gravity

package
v0.0.0-...-21311fb Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2023 License: Apache-2.0 Imports: 51 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ClusterStateActive is healthy and not running any operations.
	ClusterStateActive = "active"
	// ClusterStateDegraded is unhealthy.
	ClusterStateDegraded = "degraded"
)

ClusterState* consts come from https://github.com/gravitational/gravity/blob/7.0.0/lib/ops/constants.go#L64-L93

View Source
const (
	Parallel   = true
	Sequential = false
)
View Source
const (
	// TestStatusScheduled means test was scheduled
	TestStatusScheduled = "SCHEDULED"
	// TestStatusRunning means test is running now
	TestStatusRunning = "RUNNING"
	// TestStatusPassed means test successfully passed end to end
	TestStatusPassed = "PASSED"
	// TestStatusFailed means test failed due to test logic not passing
	TestStatusFailed = "FAILED"
	// TestStatusCancelled means test execution was interrupted due to test suite cancellation
	TestStatusCancelled = "CANCELED"
	// TestStatusPanicked means test function had an unexpected panic
	TestStatusPanicked = "PANICKED"
)

Variables

View Source
var DefaultTimeouts = OpTimeouts{
	Install:          time.Minute * 15,
	Upgrade:          time.Minute * 30,
	Uninstall:        time.Minute * 5,
	UninstallApp:     time.Minute * 5,
	NodeStatus:       time.Minute * 1,
	ClusterStatus:    time.Minute * 5,
	Leave:            time.Minute * 15,
	CollectLogs:      time.Minute * 7,
	WaitForInstaller: time.Minute * 30,
	AutoScaling:      time.Minute * 10,
	TimeSync:         time.Minute * 5,
	ResolveInPlanet:  time.Minute * 1,
	GetPods:          time.Minute * 1,
}

Functions

func KubectlDeletePod

func KubectlDeletePod(ctx context.Context, g Gravity, namespace, pod string) error

func ParseDDOutput

func ParseDDOutput(output string) (speedBytesPerSec uint64, err error)

from https://github.com/gravitational/gravity/blob/master/lib/utils/parse.go

ParseDDOutput parses the output of "dd" command and returns the reported speed in bytes per second.

Example output:

$ dd if=/dev/zero of=/tmp/testfile bs=1G count=1 1+0 records in 1+0 records out 1073741824 bytes (1.1 GB) copied, 4.52455 s, 237 MB/s

func RelocateClusterMaster

func RelocateClusterMaster(ctx context.Context, g Gravity) error

RelocateClusterMaster will check which node currently runs gravity-site master and will try to evict it from that node so that it'll get picked up by some other

func ResolveInPlanet

func ResolveInPlanet(ctx context.Context, g Gravity, name string) (string, error)

ResolveInPlanet will launch DNS resolution inside Planet container

func SetProvisionerPolicy

func SetProvisionerPolicy(p ProvisionerPolicy)

Types

type Application

type Application struct {
	// Name is the name of the cluster application
	Name string `json:"name"`
}

Application defines the cluster application

type Cluster

type Cluster struct {
	// Nodes is the list of gravity nodes in the cluster
	Nodes []Gravity
	// Destroy is the resource destruction handler
	Destroy DestroyFn
}

Cluster describes the result of provisioning cluster infrastructure.

type ClusterNodesByRole

type ClusterNodesByRole struct {
	// ApiMaster is Kubernetes apiserver master
	ApiMaster Gravity
	// ClusterMaster is current gravity-site application master
	ClusterMaster Gravity
	// ClusterBackup are backup nodes for gravity-site application
	ClusterBackup []Gravity
	// Regular nodes are those which are part of the cluster but have no role assigned
	Regular []Gravity
	// Other lists all nodes but the API server node
	Other []Gravity
}

ClusterNodesByRole defines which roles every node plays in a cluster

type ClusterSpecV2

type ClusterSpecV2 struct {
	// Status is a cluster status, initialized for existing clusters only
	Status string `json:"status,omitempty" yaml:"status,omitempty"`
}

ClusterSpecV2 is cluster V2 specification from gravitational/gravity project it is a minimal copy of only needed fields

type ClusterStatus

type ClusterStatus struct {
	// Application defines the cluster application
	Application Application `json:"application"`
	// Cluster is the name of the cluster
	Cluster string `json:"domain"`
	// State is the cluster state
	State string `json:"state"`
	// SystemStatus is the cluster status
	SystemStatus SystemStatus `json:"system_status"`
	// Token is secure token which prevents rogue nodes from joining the cluster during installation
	Token Token `json:"token"`
	// Nodes describes the nodes in the cluster
	Nodes []NodeStatus `json:"nodes"`
}

ClusterStatus describes the status of a Gravity cluster

type ClusterV2

type ClusterV2 struct {
	// Spec contains cluster specification
	Spec ClusterSpecV2 `json:"spec" yaml:"spec"`
}

ClusterV2 spec is a minimal copy of the Cluster definition from the gravitational/gravity project Unneeded fields have been removed, and only required fields are included in the local copy https://github.com/gravitational/gravity/blob/20cfcef8d50ab403f0a9452376ccd52e145ae90c/lib/storage/cluster.go#L65

type DestroyFn

type DestroyFn func() error

DestroyFn function which will destroy previously created remote resources

type Graceful

type Graceful bool

type Gravity

type Gravity interface {
	json.Marshaler
	fmt.Stringer
	// SetInstaller transfers and prepares installer package given with installerUrl.
	// The install directory will be overridden to the specified sub-directory
	// in user's home
	SetInstaller(ctx context.Context, installerUrl, subdir string) error
	// TransferFile transfers the file specified with url into the given sub-directory
	// subdir in user's home.
	// The install directory will be overridden to the specified sub-directory
	// in user's home
	TransferFile(ctx context.Context, url, subdir string) error
	// ExecScript transfers and executes script with predefined parameters
	ExecScript(ctx context.Context, scriptUrl string, args []string) error
	// Install operates on initial master node
	Install(ctx context.Context, param InstallParam) error
	// Status retrieves status
	Status(ctx context.Context) (*GravityStatus, error)
	// OfflineUpdate tries to upgrade application version
	OfflineUpdate(ctx context.Context, installerUrl string) error
	// Join asks to join existing cluster (or installation in progress)
	Join(ctx context.Context, param JoinCmd) error
	// Leave requests current node leave a cluster
	Leave(ctx context.Context, graceful Graceful) error
	// Remove requests cluster to evict a given node
	Remove(ctx context.Context, node string, graceful Graceful) error
	// Uninstall will wipe gravity installation from node
	Uninstall(ctx context.Context) error
	// UninstallApp uninstalls cluster application
	UninstallApp(ctx context.Context) error
	// PowerOff will power off the node
	PowerOff(ctx context.Context, graceful Graceful) error
	// Reboot will reboot this node and wait until it will become available again
	Reboot(ctx context.Context, graceful Graceful) error
	// CollectLogs will pull essential logs from node and store it in state dir under node-logs/prefix
	CollectLogs(ctx context.Context, prefix string, args ...string) (localPath string, err error)
	// Upload uploads packages in current installer dir to cluster
	Upload(ctx context.Context) error
	// Upgrade takes currently active installer (see SetInstaller) and tries to perform upgrade
	Upgrade(ctx context.Context) error
	// RunInPlanet runs specific command inside Planet container and returns its result
	RunInPlanet(ctx context.Context, cmd string, args ...string) (string, error)
	// Node returns underlying VM instance
	Node() infra.Node
	// Offline returns true if node was previously powered off
	Offline() bool
	// Client returns SSH client to VM instance
	Client() *ssh.Client
	// Will log using extended info such as current tag, node info, etc
	Logger() logrus.FieldLogger
}

Gravity is interface to remote gravity CLI

type GravityStatus

type GravityStatus struct {
	// Cluster describes the cluster status
	Cluster ClusterStatus `json:"cluster"`
}

GravityStatus describes the status of the Gravity cluster

type InstallParam

type InstallParam struct {
	// Token is initial token to use during cluster setup
	Token string `json:"-"`
	// Role is node role as defined in app.yaml
	Role string `json:"role" validate:"required"`
	// Cluster is Optional name of the cluster. Autogenerated if not set.
	Cluster string `json:"cluster"`
	// Flavor is Application flavor. See Application Manifest for details.
	Flavor string `json:"flavor" validate:"required"`
	// EnableRemoteSupport (Optional) whether to register this installation with remote ops-center
	EnableRemoteSupport bool `json:"remote_support"`
	// CloudProvider defines tighter integration with cloud vendor, i.e. use AWS networking on Amazon
	CloudProvider string `json:"cloud_provider,omitempty"`
	// GCENodeTag specifies the node tag on GCE.
	// Node tag replaces the cluster name if the cluster name does not comply with the GCE naming convention
	GCENodeTag string `json:"gce_node_tag,omitempty"`
	// StateDir is the directory where all gravity data will be stored on the node
	StateDir string `json:"state_dir" validate:"required"`
	// OSFlavor is operating system and optional version separated by ':'
	OSFlavor OS `json:"os" validate:"required"`
	// DockerStorageDriver is one of supported storage drivers
	DockerStorageDriver StorageDriver `json:"storage_driver"`
	// InstallerURL overrides installer URL from the global config
	InstallerURL string `json:"installer_url,omitempty"`
	// OpsAdvertiseAddr is optional Ops Center advertise address to pass to the install command
	OpsAdvertiseAddr string `json:"ops_advertise_addr,omitempty"`
	// ServiceUID is an optional parameter for install's --service-uid flag: https://gravitational.com/gravity/docs/ver/7.x/pack/#service-user
	ServiceUID *uint `json:"service_uid,omitempty"`
	// ServiceGID is an optional parameter for install's --service-gid flag
	ServiceGID *uint `json:"service_gid,omitempty"`
}

InstallParam represents install parameters passed to first node

type JoinCmd

type JoinCmd struct {
	// InstallDir is set automatically
	InstallDir string
	// PeerAddr is other node (i.e. master)
	PeerAddr string
	// Token is the join token
	Token string
	// Role is the role of the joining node
	Role string
	// StateDir is where all gravity data will be stored on the joining node
	StateDir string
}

JoinCmd represents various parameters for Join

type NodeStatus

type NodeStatus struct {
	// Addr is the advertised address of this cluster node
	Addr string `json:"advertise_ip"`
}

NodeStatus describes the status of a cluster node

type Nodes

type Nodes []Gravity

Nodes is a list of gravity nodes

func (Nodes) String

func (r Nodes) String() string

String returns a textual representation of this list of nodes

type OS

type OS struct {
	Vendor, Version string
}

OS represents OS vendor/version

func (OS) String

func (os OS) String() string

String returns a textual representation of this OS instance

func (*OS) UnmarshalText

func (os *OS) UnmarshalText(b []byte) error

UnmarshalText interprets b as an OS vendor with a version. I.e. given:

"vendor:version", it populates this OS instance accordingly

type OpTimeouts

type OpTimeouts struct {
	Install          time.Duration
	Upgrade          time.Duration
	NodeStatus       time.Duration
	ClusterStatus    time.Duration
	Uninstall        time.Duration
	UninstallApp     time.Duration
	Leave            time.Duration
	CollectLogs      time.Duration
	WaitForInstaller time.Duration
	AutoScaling      time.Duration
	TimeSync         time.Duration
	ResolveInPlanet  time.Duration
	GetPods          time.Duration
}

OpTimeouts defines per-node, per-operation timeouts which would be used to determine whether test must be failed provisioner has its own timeout / restart logic which is dependent on cloud provider and terraform

type Pod

type Pod struct {
	Name   string
	Ready  bool
	NodeIP string
}

func KubectlGetPods

func KubectlGetPods(ctx context.Context, g Gravity, namespace, label string) ([]Pod, error)

type ProvisionerConfig

type ProvisionerConfig struct {
	// DeployTo defines cloud to deploy to
	CloudProvider string `yaml:"cloud" validate:"required,eq=aws|eq=azure|eq=gce|eq=ops"`
	// AWS defines AWS connection parameters
	AWS *aws.Config `yaml:"aws"`
	// Azure defines Azure connection parameters
	Azure *azure.Config `yaml:"azure"`
	// GCE defines Google Compute Engine connection parameters
	GCE *gce.Config `yaml:"gce"`
	// Ops defines Ops Center connection parameters
	Ops *ops.Config `yaml:"ops"`

	// ScriptPath is the path to the terraform script or directory for provisioning
	ScriptPath string `yaml:"script_path" validate:"required"`
	// TerraformPluginDir is the path to the terraform plugin directory
	TerraformPluginDir string `yaml:"tf_plugin_dir"`
	// InstallerURL specifies the location of the installer tarball.
	// Can either be a local path or S3 URL
	InstallerURL string `yaml:"installer_url" validate:"required"`
	// GravityURL specifies the location of the up-to-date gravity binary.
	// Can either be a local path or S3 URL
	GravityURL string `yaml:"gravity_url" validate:"required"`
	// StateDir defines base directory where to keep state (i.e. terraform configs/vars)
	StateDir string `yaml:"state_dir" validate:"required"`

	// NodeCount defines amount of nodes to be provisioned
	NodeCount uint `validate:"gte=1"`
	// contains filtered or unexported fields
}

ProvisionerConfig defines parameters required to provision hosts CloudProvider, AWS, Azure, ScriptPath and InstallerURL

func LoadConfig

func LoadConfig(t *testing.T, configBytes []byte) (cfg ProvisionerConfig)

LoadConfig loads essential parameters from YAML

func (ProvisionerConfig) DestroyOpsFn

func (c ProvisionerConfig) DestroyOpsFn(tc *TestContext, clusterName string) func() error

DestroyOpsFn will destroy the cluster by making a request to the ops center to de-provision the cluster

func (ProvisionerConfig) Tag

func (config ProvisionerConfig) Tag() string

Tag returns the configured tag. Tag is a unique robotest cluster identifier

func (ProvisionerConfig) WithNodes

func (config ProvisionerConfig) WithNodes(nodes uint) ProvisionerConfig

WithNodes returns copy of config with specific number of nodes

func (ProvisionerConfig) WithOS

func (config ProvisionerConfig) WithOS(os OS) ProvisionerConfig

WithOS returns copy of config with specific OS

func (ProvisionerConfig) WithStorageDriver

func (config ProvisionerConfig) WithStorageDriver(storageDriver StorageDriver) ProvisionerConfig

WithStorageDriver returns copy of config with specific storage driver

func (ProvisionerConfig) WithTag

func (config ProvisionerConfig) WithTag(tag string) ProvisionerConfig

WithTag returns copy of config applying extended tag to it

type ProvisionerPolicy

type ProvisionerPolicy struct {
	// DestroyOnSuccess instructs to remove any cloud resources after test completed OK
	DestroyOnSuccess bool
	// DestroyOnFailure instructs to cleanup any cloud resources after test completed with failure or context was timed out or interrupted
	DestroyOnFailure bool
	// AlwaysCollectLogs requests to fetch logs also from VMs where tests completed OK
	AlwaysCollectLogs bool
	// ResourceListFile keeps record of allocated and not cleaned up resources
	ResourceListFile string
}

type StorageDriver

type StorageDriver string

StorageDriver specifies a Docker storage driver by name

func (StorageDriver) Driver

func (drv StorageDriver) Driver() string

Driver validates and returns driver name

func (*StorageDriver) UnmarshalText

func (drv *StorageDriver) UnmarshalText(name []byte) error

UnmarshalText interprets b as a Docker storage driver name

type SystemStatus

type SystemStatus int

SystemStatus comes from https://github.com/gravitational/satellite/blob/7.1.0/agent/proto/agentpb/agent.pb.go#L28-L32

const (
	// SystemStatus_Unknown is rarely/never returned in practice but is defined here for parity with satellite.
	SystemStatus_Unknown SystemStatus = 0
	// SystemStatus_Running is satellite's healthy status.
	SystemStatus_Running SystemStatus = 1
	// SystemStatus_Degraded is satellite's unhealthy status.
	SystemStatus_Degraded SystemStatus = 2
)

func (SystemStatus) String

func (ss SystemStatus) String() string

func (*SystemStatus) UnmarshalJSON

func (s *SystemStatus) UnmarshalJSON(data []byte) error

UnmarshalJSON fulfills the Unmarshaler interface, allowing SystemStatus to perform custom JSON unmarshalling.

Gravity 5.2.x+ marshals SystemStatus as an integer and Gravity 5.0.36- marshals it as a string. For more info, see:

https://github.com/gravitational/robotest/issues/247

For Gravity's definitions and mappings of see:

https://github.com/gravitational/satellite/blob/5.0.2/agent/proto/agentpb/agent.proto#L36-L40
https://github.com/gravitational/satellite/blob/5.0.2/agent/proto/agentpb/agent.pb.go#L48-L63

TODO: When Gravity 5.0.x support is no longer needed, this function can be removed and SystemStatus can be swapped to type int:

SystemStatus int `json:"system_status"`

type TestContext

type TestContext struct {
	// contains filtered or unexported fields
}

TestContext aggregates common parameters for better test suite readability

func (*TestContext) AutoScale

func (c *TestContext) AutoScale(target int) ([]Gravity, error)

AutoScale will update the autoscaling group to the target number of nodes, and return a new list of nodes to be used for testing

func (*TestContext) CheckTimeSync

func (c *TestContext) CheckTimeSync(nodes []Gravity) error

CheckTime walks around all nodes and checks whether their time is within acceptable limits

func (*TestContext) CollectLogs

func (c *TestContext) CollectLogs(prefix string, nodes []Gravity) error

CollectLogs requests logs from all nodes. prefix `postmortem` is reserved for cleanup procedure

func (*TestContext) Context

func (c *TestContext) Context() context.Context

Context provides a context for a current test run

func (*TestContext) Error

func (c *TestContext) Error() error

Error returns reason this test failed

func (*TestContext) ExecScript

func (c *TestContext) ExecScript(nodes []Gravity, scriptUrl string, args []string, timeout time.Duration) error

ExecScript will run and execute a script on all nodes

func (*TestContext) Expand

func (c *TestContext) Expand(currentCluster, nodesToJoin []Gravity, p InstallParam) error

Expand joins one or more node to a cluster

func (*TestContext) FailNow

func (c *TestContext) FailNow()

FailNow requests this test suite to abort

func (*TestContext) Failed

func (c *TestContext) Failed() bool

Failed checks if this test failed

func (*TestContext) FromPreviousInstall

func (c *TestContext) FromPreviousInstall(nodes []Gravity, subdir string)

Simple hook to allow re-entrance to already initialized host

func (*TestContext) JoinNode

func (c *TestContext) JoinNode(peer, nodeToJoin Gravity, p InstallParam) error

JoinNode has one node join a peer already in a cluster

func (*TestContext) Logger

func (c *TestContext) Logger() logrus.FieldLogger

Logger returns preconfigured logger for this test

func (*TestContext) Maybe

func (c *TestContext) Maybe(msg string, err error)

Maybe logs the specified message and error if non-nil. Does not fail the test

func (*TestContext) NodesByRole

func (c *TestContext) NodesByRole(nodes []Gravity) (roles *ClusterNodesByRole, err error)

NodesByRole will conveniently organize nodes according to their roles in cluster

func (*TestContext) OK

func (c *TestContext) OK(msg string, err error)

OK logs the specified message and error. If the error is non-nil, the test is marked failed and aborted

func (*TestContext) OfflineInstall

func (c *TestContext) OfflineInstall(nodes []Gravity, param InstallParam) error

OfflineInstall sets up cluster using nodes provided

func (*TestContext) Provision

func (c *TestContext) Provision(cfg ProvisionerConfig) (cluster Cluster, err error)

Provision will attempt to provision the requested cluster

func (*TestContext) RemoveNode

func (c *TestContext) RemoveNode(master, nodeToRemove Gravity) error

RemoveNode evicts a singe node from the cluster

func (*TestContext) Require

func (c *TestContext) Require(msg string, condition bool, args ...interface{})

Require verifies condition is true, fails test otherwise

func (*TestContext) Run

func (cx *TestContext) Run(fn TestFunc, cfg ProvisionerConfig, param interface{})

Run allows a running test to spawn a subtest

func (*TestContext) SetInstaller

func (c *TestContext) SetInstaller(nodes []Gravity, installerUrl string, tag string) error

ProvisionInstaller deploys a specific installer

func (*TestContext) SetTimeouts

func (c *TestContext) SetTimeouts(tm OpTimeouts)

WithTimeouts returns context

func (*TestContext) Shrink

func (c *TestContext) Shrink(nodesToKeep, nodesToRemove []Gravity) error

Shrink evicts one or more nodes from the cluster

func (*TestContext) Sleep

func (c *TestContext) Sleep(msg string, d time.Duration)

Sleep will just sleep with log message

func (*TestContext) Status

func (c *TestContext) Status(nodes []Gravity) (statuses []GravityStatus, err error)

Status queries `gravity status` once from each node in nodes.

func (*TestContext) Uninstall

func (c *TestContext) Uninstall(nodes []Gravity) error

Uninstall makes nodes leave cluster and uninstall gravity it is not asserting internally

func (*TestContext) UninstallApp

func (c *TestContext) UninstallApp(nodes []Gravity) error

UninstallApp uninstalls cluster application

func (*TestContext) Upgrade

func (c *TestContext) Upgrade(nodes []Gravity, installerURL, gravityURL, subdir string) error

Upgrade performs an upgrade procedure on all nodes

func (*TestContext) WaitForActiveStatus

func (c *TestContext) WaitForActiveStatus(nodes []Gravity) error

WaitForActiveStatus blocks until all nodes report state = Active and notDegraded or an internal timeout expires.

func (*TestContext) WaitForStatus

func (c *TestContext) WaitForStatus(nodes []Gravity, expected statusValidator) error

WaitForStatus blocks until all nodes satisfy the expected statusValidator or an internal timeout expires.

func (*TestContext) WithFields

func (c *TestContext) WithFields(fields logrus.Fields) *TestContext

WithFields assigns additional logging fields to this context

type TestFunc

type TestFunc func(c *TestContext, config ProvisionerConfig)

type TestStatus

type TestStatus struct {
	UID, SuiteUID string
	Name          string
	Status        string
	LogUrl        string
	Param         interface{}
}

TestStatus represents high level test status on completion

type TestSuite

type TestSuite interface {
	// Cancel requests teardown for all subordinate tests
	Cancel(reason string, args ...interface{})
	// Schedule adds tests to the plan
	Schedule(fn TestFunc, baseConfig ProvisionerConfig, param interface{})
	// Run executes scheduled (and derived) tests and returns their status
	Run() []TestStatus
	// Logger provides preconfigured logger
	Logger() logrus.FieldLogger
	// Close disposes background resources
	Close()
}

func NewSuite

func NewSuite(ctx context.Context, t *testing.T, googleProjectID string, fields logrus.Fields, failFast bool, retryAttempts, preemptedRetryAttempts int) TestSuite

NewRun creates new group run environment

type Token

type Token struct {
	// Token is the join token value
	Token string `json:"token"`
}

Token describes the cluster join token

Jump to

Keyboard shortcuts

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