internal

package
v1.6.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 4, 2020 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// URIHealthz represents URI for health check
	URIHealthz = "/healthz"
	URIVersion = "/version"

	//SamsahaiCtrlName           = "samsahai-ctrl"
	SamsahaiAuthHeader  = "x-samsahai-auth"
	SamsahaiDefaultPort = "8080"

	StagingCtrlName    = "s2h-staging-ctrl"
	StagingDefaultPort = 8090

	// Viper keys
	VKDebug                           = "debug"
	VKServerHTTPPort                  = "port"
	VKMetricHTTPPort                  = "metric-port"
	VKPodNamespace                    = "pod-namespace"
	VKS2HConfigPath                   = "s2h-config-path"
	VKClusterDomain                   = "cluster-domain"
	VKS2HTeamName                     = "s2h-team-name"
	VKS2HAuthToken                    = "s2h-auth-token"
	VKS2HServerURL                    = "s2h-server-url"
	VKS2HServiceName                  = "s2h-service-name"
	VKS2HServiceScheme                = "s2h-service-scheme"
	VKS2HImage                        = "s2h-image"
	VKS2HExternalURL                  = "s2h-external-url"
	VKTeamcityURL                     = "teamcity-url"
	VKTeamcityUsername                = "teamcity-username"
	VKTeamcityPassword                = "teamcity-password"
	VKSlackToken                      = "slack-token"
	VKMSTeamsTenantID                 = "ms-teams-tenant-id"
	VKMSTeamsClientID                 = "ms-teams-client-id"
	VKMSTeamsClientSecret             = "ms-teams-client-secret"
	VKMSTeamsUsername                 = "ms-teams-username"
	VKMSTeamsPassword                 = "ms-teams-password"
	VKActivePromotionConcurrences     = "active-promotion-concurrences"
	VKActivePromotionTimeout          = "active-promotion-timeout"
	VKActivePromotionDemotionTimeout  = "active-demotion-timeout"
	VKActivePromotionRollbackTimeout  = "active-promotion-rollback-timeout"
	VKActivePromotionTearDownDuration = "active-promotion-teardown-duration"
	VKActivePromotionMaxHistories     = "active-promotion-max-histories"
	VKActivePromotionOnTeamCreation   = "active-promotion-on-team-creation"
	VKQueueMaxHistoryDays             = "queue-max-history-days"
)
View Source
const AbbreviationName = "s2h"
View Source
const AppName = "samsahai"
View Source
const AppPrefix = AbbreviationName + "-"
View Source
const (
	MaxReleaseNameLength = 53
)

Variables

View Source
var GitCommit string

GitCommit defines commit hash of git during built

View Source
var Version string

Version defines the version of application

Functions

func GenReleaseName

func GenReleaseName(namespace, compName string) string

GenReleaseName returns the release name for deploying components

func GenStagingNamespace

func GenStagingNamespace(teamName string) string

GenStagingNamespace returns the name of staging namespace by team name

func GetDefaultLabels

func GetDefaultLabels(teamName string) map[string]string

GetDefaultLabels returns default labels for kubernetes resources

func GetTeamLabelKey

func GetTeamLabelKey() string

GetTeamLabelKey returns team label key

Types

type ActivePromotionConfig

type ActivePromotionConfig struct {
	// Concurrences defines number of active promotion concurrences
	Concurrences int `json:"concurrences" yaml:"concurrences"`

	// Timeout defines timeout duration of active promotion process
	Timeout metav1.Duration `json:"timeout" yaml:"timeout"`

	// DemotionTimeout defines timeout duration of active demotion process
	DemotionTimeout metav1.Duration `json:"demotionTimeout" yaml:"demotionTimeout"`

	// RollbackTimeout defines timeout duration of rollback process
	RollbackTimeout metav1.Duration `json:"rollbackTimeout" yaml:"rollbackTimeout"`

	// TearDownDuration defines tear down duration of previous active environment
	TearDownDuration metav1.Duration `json:"teardownDuration" yaml:"teardownDuration"`

	// MaxHistories defines max stored histories of active promotion
	MaxHistories int `json:"maxHistories" yaml:"maxHistories"`

	// PromoteOnTeamCreation defines whether auto-promote active environment or not when team creation?
	PromoteOnTeamCreation bool `json:"promoteOnTeamCreation" yaml:"promoteOnTeamCreation"`
}

ActivePromotionConfig represents configuration of active promotion

type ActivePromotionController

type ActivePromotionController interface {
}

type ActivePromotionOption

type ActivePromotionOption func(*ActivePromotionReporter)

ActivePromotionOption allows specifying various configuration

func WithCredential

func WithCredential(creds s2hv1beta1.Credential) ActivePromotionOption

TODO: should override tc credential per team WithCredential specifies credential to override when create active promotion reporter object

type ActivePromotionReporter

type ActivePromotionReporter struct {
	TeamName               string                `json:"teamName,omitempty"`
	CurrentActiveNamespace string                `json:"currentActiveNamespace,omitempty"`
	Credential             s2hv1beta1.Credential `json:"credential,omitempty"`
	Envs                   map[string]string
	s2hv1beta1.ActivePromotionStatus
	SamsahaiConfig
}

ActivePromotionReporter manages active promotion report

func NewActivePromotionReporter

func NewActivePromotionReporter(status *s2hv1beta1.ActivePromotionStatus, s2hConfig SamsahaiConfig, teamName, currentNs string, opts ...ActivePromotionOption) *ActivePromotionReporter

NewActivePromotionReporter creates active promotion reporter object

type ComponentUpgradeOption

type ComponentUpgradeOption func(*ComponentUpgradeReporter)

ComponentUpgradeOption allows specifying various configuration

func WithQueueHistoryName

func WithQueueHistoryName(qHist string) ComponentUpgradeOption

WithQueueHistoryName specifies queuehistory name to override when creating component upgrade reporter object QueueHistoryName will be the latest failure of component upgrade if reverification is success, QueueHistoryName will be the history of queue before running reverification

func WithTestRunner

func WithTestRunner(tr s2hv1beta1.TestRunner) ComponentUpgradeOption

WithTestRunner specifies test runner to override when creating component upgrade reporter object

type ComponentUpgradeReporter

type ComponentUpgradeReporter struct {
	IssueTypeStr IssueType             `json:"issueTypeStr,omitempty"`
	StatusStr    StatusType            `json:"statusStr,omitempty"`
	StatusInt    int32                 `json:"statusInt,omitempty"`
	TestRunner   s2hv1beta1.TestRunner `json:"testRunner,omitempty"`
	Credential   s2hv1beta1.Credential `json:"credential,omitempty"`
	Envs         map[string]string

	*rpc.ComponentUpgrade
	SamsahaiConfig
}

ComponentUpgradeReporter manages component upgrade report

func NewComponentUpgradeReporter

func NewComponentUpgradeReporter(comp *rpc.ComponentUpgrade, s2hConfig SamsahaiConfig, opts ...ComponentUpgradeOption) *ComponentUpgradeReporter

NewComponentUpgradeReporter creates component upgrade reporter from rpc object

type ConfigController added in v1.1.0

type ConfigController interface {
	// Get returns configuration from memory
	Get(configName string) (*s2hv1beta1.Config, error)

	// GetComponents returns all components from `Configuration` that has valid `Source`
	GetComponents(configName string) (map[string]*s2hv1beta1.Component, error)

	// GetParentComponents returns components that doesn't have parent (nil Parent)
	GetParentComponents(configName string) (map[string]*s2hv1beta1.Component, error)

	// GetBundles returns a group of components for each bundle
	GetBundles(configName string) (s2hv1beta1.ConfigBundles, error)

	// GetPriorityQueues returns a list of priority queues which defined in Config
	GetPriorityQueues(configName string) ([]string, error)

	// Update updates Config CRD
	Update(config *s2hv1beta1.Config) error

	// Delete deletes Config CRD
	Delete(configName string) error
}

type ConfigurationJSON

type ConfigurationJSON struct {
	GitRevision   string                 `json:"gitRevision"`
	Configuration *s2hv1beta1.ConfigSpec `json:"config"`
}

type Connection

type Connection struct {
	Name          string `json:"name"`
	URL           string `json:"url"`
	IP            string `json:"ip"`
	Port          string `json:"port"`
	ServicePort   string `json:"servicePort"`
	Type          string `json:"type"`
	ContainerPort string `json:"containerPort"`
}

type DeployEngine

type DeployEngine interface {
	// GetName returns name of deploy engine
	GetName() string

	// GetValues returns yaml values of release deployment
	GetValues() (map[string][]byte, error)

	// Create creates environment
	Create(refName string, comp *v1beta1.Component, parentComp *v1beta1.Component, values map[string]interface{}, deployTimeout *time.Duration) error

	// Rollback rollback helm release
	Rollback(refName string, revision int) error

	// GetHistories returns histories of release
	GetHistories(refName string) ([]*release.Release, error)

	// Delete deletes environment
	Delete(refName string) error

	// ForceDelete deletes environment when timeout
	ForceDelete(refName string) error

	// GetLabelSelector returns map of label for select the components that created by the engine
	GetLabelSelectors(refName string) map[string]string

	// GetReleases returns all deployed releases
	GetReleases() ([]*release.Release, error)

	// IsMocked uses for skip some functions due to mock deploy
	//
	// Skipped function: WaitForComponentsCleaned
	IsMocked() bool
}

type DesiredComponentChecker

type DesiredComponentChecker interface {
	// GetName returns name of checker
	GetName() string

	// GetVersion returns version from defined pattern
	GetVersion(repository string, name string, pattern string) (string, error)

	//EnsureVersion ensures the defined version is exist on repository
	EnsureVersion(repository string, name string, version string) error
}

DesiredComponentChecker represents standard interface for checking component version

type DesiredComponentController

type DesiredComponentController interface {
}

type EventType

type EventType string

EventType represents an event type of reporter

const (
	ComponentUpgradeType EventType = "ComponentUpgrade"
	ActivePromotionType  EventType = "ActivePromotion"
	ImageMissingType     EventType = "ImageMissing"
)

type GitInfo

type GitInfo struct {
	Name         string
	FullName     string
	BranchName   string
	HeadRevision string
}

GitInfo represents git repo, branch info. for process the update

type HTTPHeader

type HTTPHeader string

type ImageMissingReporter added in v1.4.1

type ImageMissingReporter struct {
	TeamName      string `json:"teamName,omitempty"`
	ComponentName string `json:"componentName,omitempty"`
	Envs          map[string]string

	*rpc.Image
	SamsahaiConfig
}

ImageMissingReporter manages image missing report

func NewImageMissingReporter added in v1.4.1

func NewImageMissingReporter(image *rpc.Image, s2hConfig SamsahaiConfig, teamName, compName string) *ImageMissingReporter

NewImageMissingReporter creates image missing reporter object

type IssueType

type IssueType string

IssueType represents an issue type of component upgrade failure

const (
	IssueUnknown              IssueType = "Unknown issue"
	IssueDesiredVersionFailed IssueType = "Desired component failed"
	IssueImageMissing         IssueType = "Image missing"
	IssueEnvironment          IssueType = "Environment issue - Verification failed"
)

type MSTeamsCredential added in v1.3.0

type MSTeamsCredential struct {
	TenantID     string
	ClientID     string
	ClientSecret string
	Username     string
	Password     string
}

type Plugin

type Plugin interface {
	DesiredComponentChecker

	// GetComponentName returns component name when incoming webhook matched with plugin name.
	// Useful for converting incoming component name to matched with the internal one.
	GetComponentName(name string) string
}

type PostNamespaceCreation

type PostNamespaceCreation struct {
	// Namespace defines a creating namespace
	Namespace string          `json:"namespace"`
	Team      s2hv1beta1.Team `json:"team"`
	SamsahaiConfig
}

PostNamespaceCreation represents a struct for running post namespace creation

type QueueController

type QueueController interface {
	// Add adds Queue with priority list
	Add(q *v1beta1.Queue, priorityQueues []string) error

	// AddTop adds Queue to the top
	AddTop(q *v1beta1.Queue) error

	// First returns first component in Queue or current running Queue
	First() (*v1beta1.Queue, error)

	// Remove removes Queue
	Remove(q *v1beta1.Queue) error

	// Size returns no of queues
	Size() int

	// SetLastOrder sets queue order to the last
	SetLastOrder(q *v1beta1.Queue) error

	// SetReverifyQueueAtFirst sets queue to reverify type
	SetReverifyQueueAtFirst(q *v1beta1.Queue) error

	// SetRetryQueue sets Queue to retry one time
	SetRetryQueue(q *v1beta1.Queue, noOfRetry int, nextAt time.Time) error

	// RemoveAllQueues removes all queues
	RemoveAllQueues() error
}

QueueController manages updating component queue through CRD

type Reporter

type Reporter interface {
	// GetName returns type of reporter
	GetName() string

	// SendComponentUpgrade sends details of component upgrade
	SendComponentUpgrade(configCtrl ConfigController, comp *ComponentUpgradeReporter) error

	// SendActivePromotionStatus sends active promotion status
	SendActivePromotionStatus(configCtrl ConfigController, atpRpt *ActivePromotionReporter) error

	// SendImageMissing sends image missing
	SendImageMissing(configCtrl ConfigController, imageMissingRpt *ImageMissingReporter) error
}

Reporter is the interface of reporter

type SamsahaiConfig

type SamsahaiConfig struct {
	// ConfigDirPath defines a directory path of Samsahai configuration
	ConfigDirPath string `json:"-" yaml:"-"`

	// PluginsDir defines a plugins directory path
	PluginsDir string `json:"pluginsDir" yaml:"pluginsDir"`

	// SamsahaiImage defines a Samsahai image name and tag
	SamsahaiImage string `json:"s2hImage" yaml:"s2hImage"`

	// SamsahaiExternalURL defines a Samsahai external url
	SamsahaiExternalURL string `json:"s2hExternalURL" yaml:"s2hExternalURL"`

	// TeamcityURL defines a Teamcity url
	TeamcityURL string `json:"teamcityURL" yaml:"teamcityURL"`

	// ClusterDomain defines a cluster domain name
	ClusterDomain string `json:"clusterDomain" yaml:"clusterDomain"`

	// ActivePromotion defines an active promotion configuration
	ActivePromotion ActivePromotionConfig `json:"activePromotion,omitempty" yaml:"activePromotion,omitempty"`

	// PostNamespaceCreation defines commands executing after creating s2h namespace
	PostNamespaceCreation *struct {
		s2hv1beta1.CommandAndArgs
	} `json:"postNamespaceCreation,omitempty" yaml:"postNamespaceCreation,omitempty"`

	// StagingEnvs defines environment variables of staging controller
	StagingEnvs map[string]string `json:"stagingEnvs,omitempty" yaml:"stagingEnvs,omitempty"`

	SamsahaiURL        string             `json:"-" yaml:"-"`
	SamsahaiCredential SamsahaiCredential `json:"-" yaml:"-"`
}

SamsahaiConfig represents configuration of Samsahai itself

type SamsahaiController

type SamsahaiController interface {
	s2hrpc.RPC

	http.Handler

	PathPrefix() string

	// Start runs internal worker
	Start(stop <-chan struct{})

	// QueueLen returns no. of internal queue
	QueueLen() int

	// GetTeam returns Team CRD
	GetTeam(teamName string, teamComp *s2hv1beta1.Team) error

	// GetConfigController returns samsahai configuration from config crd
	GetConfigController() ConfigController

	// GetPlugins returns samsahai plugins
	GetPlugins() map[string]Plugin

	// LoadTeamSecret loads team secret from main namespace
	LoadTeamSecret(teamComp *s2hv1beta1.Team) error

	// CreateStagingEnvironment creates staging environment
	CreateStagingEnvironment(teamName, namespaceName string) error

	// CreatePreActiveEnvironment creates pre-active environment
	CreatePreActiveEnvironment(teamName, namespace string) error

	// PromoteActiveEnvironment switches environment from pre-active to active and stores current active components
	PromoteActiveEnvironment(teamComp *s2hv1beta1.Team, namespace, promotedBy string, comps map[string]s2hv1beta1.StableComponent) error

	// DestroyActiveEnvironment destroys active environment when active demotion is failure.
	DestroyActiveEnvironment(teamName, namespace string) error

	// DestroyPreActiveEnvironment destroys pre-active environment when active promotion is failure.
	DestroyPreActiveEnvironment(teamName, namespace string) error

	// DestroyPreviousActiveEnvironment destroys previous active environment when active promotion is success.
	DestroyPreviousActiveEnvironment(teamName, namespace string) error

	// SetPreviousActiveNamespace updates previous active namespace to team status
	SetPreviousActiveNamespace(teamComp *s2hv1beta1.Team, namespace string) error

	// SetPreActiveNamespace updates pre-active namespace to team status
	SetPreActiveNamespace(teamComp *s2hv1beta1.Team, namespace string) error

	// SetActiveNamespace updates active namespace to team status
	SetActiveNamespace(teamComp *s2hv1beta1.Team, namespace string) error

	// NotifyComponentChanged adds Component to queue for checking new version
	NotifyComponentChanged(name, repository, teamName string)

	// NotifyActivePromotion sends active promotion status report
	NotifyActivePromotion(atpRpt *ActivePromotionReporter)

	// GetConnections returns Services in NodePort type and Ingresses that exist in the namespace
	GetConnections(namespace string) (map[string][]Connection, error)

	// GetTeams returns list of teams in Samsahai
	GetTeams() (*s2hv1beta1.TeamList, error)

	// GetQueueHistories returns QueueHistoryList of the namespace
	GetQueueHistories(namespace string) (*s2hv1beta1.QueueHistoryList, error)

	// GetQueueHistory returns Queue by name and namespace
	GetQueueHistory(name, namespace string) (*s2hv1beta1.QueueHistory, error)

	// GetQueues returns QueueList of the namespace
	GetQueues(namespace string) (*s2hv1beta1.QueueList, error)

	// GetStableValues returns Stable Values of parent component in team
	GetStableValues(team *s2hv1beta1.Team, comp *s2hv1beta1.Component) (s2hv1beta1.ComponentValues, error)

	// GetActivePromotions returns ActivePromotionList by labels
	GetActivePromotions() (*s2hv1beta1.ActivePromotionList, error)

	// GetActivePromotion returns ActivePromotion by name
	GetActivePromotion(name string) (v *s2hv1beta1.ActivePromotion, err error)

	// GetActivePromotionHistories returns ActivePromotionList by labels
	GetActivePromotionHistories(selectors map[string]string) (*s2hv1beta1.ActivePromotionHistoryList, error)

	// GetActivePromotionHistory returns ActivePromotion by name
	GetActivePromotionHistory(name string) (*s2hv1beta1.ActivePromotionHistory, error)
}

SamsahaiController

type SamsahaiCredential

type SamsahaiCredential struct {
	InternalAuthToken string
	SlackToken        string
	MSTeams           MSTeamsCredential
	TeamcityUsername  string
	TeamcityPassword  string
}

type SortableVersion

type SortableVersion []string

func (SortableVersion) Len

func (v SortableVersion) Len() int

func (SortableVersion) Less

func (v SortableVersion) Less(i, j int) bool

func (SortableVersion) Swap

func (v SortableVersion) Swap(i, j int)

type StableComponentController

type StableComponentController interface {
}

type StagingConfig

type StagingConfig struct {
	// MaxHistoryDays defines maximum days of QueueHistory stored
	MaxHistoryDays int `json:"maxHistoryDays" yaml:"maxHistoryDays"`
}

StagingConfig represents configuration of Staging

type StagingController

type StagingController interface {
	// should implement RPC
	stagingrpc.RPC

	// should be able to serve http
	http.Handler

	// Start runs internal worker
	Start(stop <-chan struct{})

	// IsBusy returns true if controller still processing queue
	IsBusy() bool

	// LoadTestRunner loads single test runner to controller
	LoadTestRunner(runner StagingTestRunner)

	// LoadDeployEngine loads single deploy engine to controller
	LoadDeployEngine(engine DeployEngine)
}

type StagingTestRunner

type StagingTestRunner interface {
	// GetName returns type of test runner
	GetName() string

	// Trigger makes http request to run the test build
	Trigger(testConfig *v1beta1.ConfigTestRunner, currentQueue *v1beta1.Queue) error

	// GetResult makes http request to get result of test build [FAILURE/SUCCESS/UNKNOWN]
	// It returns bool results of is build success and is build finished
	GetResult(testConfig *v1beta1.ConfigTestRunner, currentQueue *v1beta1.Queue) (bool, bool, error)
}

type StatusType

type StatusType string

StatusType represents an active promotion type

const (
	StatusSuccess StatusType = "Success"
	StatusFailure StatusType = "Failure"
)

Directories

Path Synopsis
reporter
third_party
cmd
protostruct
Package protostruct supports operations on the protocol buffer Struct message.
Package protostruct supports operations on the protocol buffer Struct message.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL