environment

package
v1.2.7 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2022 License: MIT Imports: 50 Imported by: 4

Documentation

Index

Constants

View Source
const (
	// HelmInstallTimeout timeout for installing a helm chart
	HelmInstallTimeout = 5 * time.Minute
	// DefaultK8sConfigPath the default path for kube
	DefaultK8sConfigPath = ".kube/config"
)
View Source
const (
	// AppEnumerationLabelKey label used to enumerate instances of the same app to ease access
	AppEnumerationLabelKey = "app"
	// InstanceEnumerationLabelKey additional label to enumerate app instances
	InstanceEnumerationLabelKey = "instance"
)

Variables

View Source
var (
	//nolint
	//go:embed charts/*/**
	ChartsFS embed.FS
)

Functions

func ChainlinkReplicas

func ChainlinkReplicas(count int, values map[string]interface{}) map[string]interface{}

ChainlinkReplicas sets the replica count of chainlink nodes to use

func ChainlinkVersion

func ChainlinkVersion(version string, values map[string]interface{}) map[string]interface{}

ChainlinkVersion sets the version of the chainlink image to use

func CommonRemoteRunnerValues added in v1.2.2

func CommonRemoteRunnerValues(testTag, slackAPI, slackChannel, slackUser string) map[string]interface{}

CommonRemoteRunnerValues builds the map with the common expected values for remote runner

func DefaultGeth added in v1.0.52

func DefaultGeth() (string, map[string]interface{})

DefaultGeth sets up a basic, low-power simulated geth instance. Really just returns empty map to use default values

func DumpConfig

func DumpConfig(cfg *Config, path string) error

DumpConfig dumps config to a yaml file

func DumpConfigJson

func DumpConfigJson(cfg *Config, path string) error

DumpConfigJson dumps config to a json file

func GetLocalK8sDeps

func GetLocalK8sDeps() (*kubernetes.Clientset, *rest.Config, error)

GetLocalK8sDeps get local k8s connection deps

func PerformanceGeth added in v1.0.52

func PerformanceGeth() (string, map[string]interface{})

PerformanceGeth sets up the simulated geth instance with more power, bigger blocks, and faster mining

func RealisticGeth added in v1.0.52

func RealisticGeth() (string, map[string]interface{})

RealisticGeth sets up the simulated geth instance to emulate the actual ethereum mainnet as close as possible

Types

type Artifacts

type Artifacts struct {
	DBName string
	// contains filtered or unexported fields
}

Artifacts is an artifacts dumping structure that copies logs and database dumps for all deployed pods

func NewArtifacts

func NewArtifacts(env *Environment) (*Artifacts, error)

NewArtifacts create new artifacts instance for provided environment

func (*Artifacts) DumpTestResult

func (a *Artifacts) DumpTestResult(testDir string, dbName string) error

DumpTestResult dumps all pods logs and db dump in a separate test dir

type ChartConnection

type ChartConnection struct {
	PodName     string         `yaml:"pod_name,omitempty" json:"pod_name" envconfig:"pod_name"`
	PodIP       string         `yaml:"pod_ip,omitempty" json:"pod_ip" envconfig:"pod_ip"`
	RemotePorts map[string]int `yaml:"remote_ports,omitempty" json:"remote_ports" envconfig:"remote_ports"`
	LocalPorts  map[string]int `yaml:"local_ports,omitempty" json:"local_ports" envconfig:"local_ports"`
}

ChartConnection info about connected pod ports

type ChartConnections

type ChartConnections map[string]*ChartConnection

ChartConnections represents a group of pods and their connection info deployed within the same chart

func (ChartConnections) Load

func (cc ChartConnections) Load(app, instance, name string) (*ChartConnection, error)

Load emulates the Load sync.Map function to use the common map key and return the value correctly typed

func (*ChartConnections) LoadByPort

func (cc *ChartConnections) LoadByPort(port int) ([]*ChartConnection, error)

LoadByPort scans all the connections and returns a list of connections if they contain a certain port number

func (*ChartConnections) LoadByPortName

func (cc *ChartConnections) LoadByPortName(portName string) ([]*ChartConnection, error)

LoadByPortName scans all the connections and returns a list of connections if they contain a certain port name

func (*ChartConnections) LocalURLByPort

func (cc *ChartConnections) LocalURLByPort(portName string, protocol Protocol) (*url.URL, error)

LocalURLByPort returns a parsed URL of a local port-forwarded service based on the port name

func (*ChartConnections) LocalURLs

func (cc *ChartConnections) LocalURLs(stringDirective string, portName string) ([]*url.URL, error)

LocalURLs scans all the connections returns remote URLs based on a port number of a service and a string directive

func (*ChartConnections) LocalURLsByPort

func (cc *ChartConnections) LocalURLsByPort(portName string, protocol Protocol) ([]*url.URL, error)

LocalURLsByPort returns parsed URLs of a local port-forwarded service based on the port name

func (ChartConnections) Range

func (cc ChartConnections) Range(f func(key string, chartConnection *ChartConnection) bool)

Range emulates the default range function in the sync.Map, without the need to cast the key & value

func (*ChartConnections) RemoteURLByPort

func (cc *ChartConnections) RemoteURLByPort(portName string, protocol Protocol) (*url.URL, error)

RemoteURLByPort returns a parsed URL of a remote service based on the port name

func (*ChartConnections) RemoteURLs

func (cc *ChartConnections) RemoteURLs(stringDirective string, portName string) ([]*url.URL, error)

RemoteURLs scans all the connections returns remote URLs based on a port number of a service and a string directive

func (*ChartConnections) RemoteURLsByPort

func (cc *ChartConnections) RemoteURLsByPort(portName string, protocol Protocol) ([]*url.URL, error)

RemoteURLsByPort returns parsed URLs of a remote service based on the port name

func (ChartConnections) Store

func (cc ChartConnections) Store(app, instance, name string, chartConnection *ChartConnection) error

Store emulates the default Store function within the sync.Map to use the common map key and value types and return an error if the key is a duplicate

type Charts

type Charts map[string]*HelmChart

Charts represents a map of charts with some helper methods

func (Charts) Connections

func (c Charts) Connections(chart string) *ChartConnections

Connections is a helper method for simply accessing chart connections, also safely allowing method chaining

func (Charts) Decode

func (c Charts) Decode(value string) error

Decode is used by envconfig to initialize the custom Charts type with populated values This function will take a JSON object representing charts, and unmarshal it into the existing object to "merge" the two

func (Charts) ExecuteInPod

func (c Charts) ExecuteInPod(chartName string, podNameSubstring string, podIndex int, containerName string, command []string) error

ExecuteInPod is similar to kubectl exec

func (Charts) Get

func (c Charts) Get(chartName string) (*HelmChart, error)

Get returns a single Helm Chart

func (Charts) OrderedKeys

func (c Charts) OrderedKeys() [][]string

OrderedKeys returns an ordered list of the map keys based on the charts Index value

type Config

type Config struct {
	Path               string                           `yaml:"-" json:"-" envconfig:"config_path"`
	QPS                float32                          `yaml:"qps" json:"qps" envconfig:"qps" default:"50"`
	Burst              int                              `yaml:"burst" json:"burst" envconfig:"burst" default:"50"`
	MarshalSafeTimeout MarshalSafeDuration              `yaml:"timeout" json:"timeout" ignored:"true" default:"3m"`
	Timeout            time.Duration                    `yaml:"-" json:"-" envconfig:"timeout" default:"3m"`
	Persistent         bool                             `yaml:"persistent" json:"persistent" envconfig:"persistent"`
	NamespacePrefix    string                           `yaml:"namespace_prefix,omitempty" json:"namespace_prefix,omitempty" envconfig:"namespace_prefix"`
	Namespace          string                           `yaml:"namespace,omitempty" json:"namespace,omitempty" envconfig:"namespace"`
	Charts             Charts                           `yaml:"charts,omitempty" json:"charts,omitempty" envconfig:"charts"`
	Experiments        map[string]*chaos.ExperimentInfo `yaml:"experiments,omitempty" json:"experiments,omitempty" envconfig:"experiments"`
}

Config represents the full configuration of an environment, it can either be defined programmatically at runtime, or defined in files to be used in a CLI or any other application

func NewChainlinkCCIPReorgConfig added in v1.0.67

func NewChainlinkCCIPReorgConfig(chainlinkValues map[string]interface{}, networkIDs []int) *Config

NewChainlinkCCIPReorgConfig returns a Chainlink environment for the purpose of CCIP testing

func NewChainlinkConfig

func NewChainlinkConfig(
	chainlinkValues map[string]interface{},
	optionalNamespacePrefix string,
	networks ...SimulatedNetwork,
) *Config

NewChainlinkConfig returns a vanilla Chainlink environment used for generic functional testing. Geth networks can be passed in to launch differently configured simulated geth instances.

func NewChainlinkReorgConfig

func NewChainlinkReorgConfig(chainlinkValues map[string]interface{}) *Config

NewChainlinkReorgConfig returns a Chainlink environment designed for simulating re-orgs within testing

func NewPerformanceChainlinkConfig added in v1.2.0

func NewPerformanceChainlinkConfig(
	chainlinkValues map[string]interface{},
	optionalNamespacePrefix string,
	networks ...SimulatedNetwork,
) *Config

NewPerformanceChainlinkConfig launches an environment with upgraded resources Mockserver launches with 1 CPU and 1 GB of RAM Chainlink DB launches with 1 CPU and 2GB of RAM Chainlink node launches with 2 CPU and 4GB RAM

func NewTerraChainlinkConfig

func NewTerraChainlinkConfig(chainlinkValues map[string]interface{}) *Config

NewTerraChainlinkConfig returns a Chainlink environment designed for testing with a Terra relay

func (*Config) Decode added in v1.0.77

func (m *Config) Decode(path string) error

Decode marshals the config from a provided yaml file

func (*Config) ToJSON added in v1.0.77

func (m *Config) ToJSON() ([]byte, error)

ToJSON marshals the config to JSON

type Environment

type Environment struct {
	*Config
	Artifacts *Artifacts
	Chaos     *chaos.Controller
	// contains filtered or unexported fields
}

Environment build and deployed from several helm Charts

func DeployEnvironment

func DeployEnvironment(config *Config) (*Environment, error)

DeployEnvironment returns a deployed environment from a given config that can be pre-defined within the library, or passed in as part of lib usage

func DeployOrLoadEnvironment

func DeployOrLoadEnvironment(config *Config) (*Environment, error)

DeployOrLoadEnvironment returns a deployed environment from a given preset that can be ones pre-defined within the library, or passed in as part of lib usage

func DeployOrLoadEnvironmentFromConfigFile

func DeployOrLoadEnvironmentFromConfigFile(configFilePath string) (*Environment, error)

DeployOrLoadEnvironmentFromConfigFile returns an environment based on a preset file, mostly for use as a presets CLI

func DeployRemoteRunnerEnvironment added in v1.0.77

func DeployRemoteRunnerEnvironment(
	config *Config,
	frameworkConfigPath,
	networksConfigPath,
	testExecutablePath string,
	runnerHelmValues map[string]interface{},
) (*Environment, error)

DeployRemoteRunnerEnvironment is used for deploying environment with a remote runner inside a pod suitable for a long-running tests

func DeployRemoteRunnerToEnv added in v1.2.3

func DeployRemoteRunnerToEnv(
	env *Environment,
	frameworkConfigPath,
	networksConfigPath,
	testExecutablePath string,
	runnerHelmValues map[string]interface{},
) (*Environment, error)

DeployRemoteRunnerToEnv Adds the remote runner to the charts and deploys it useful when you have your env deployed already and just need to add it on

func LoadEnvironment

func LoadEnvironment(config *Config) (*Environment, error)

LoadEnvironment loads an already deployed environment from config

func NewEnvironment

func NewEnvironment(config *Config) (*Environment, error)

NewEnvironment creates new environment from charts

func (*Environment) AddChart

func (k *Environment) AddChart(chart *HelmChart) error

AddChart adds chart to deploy

func (*Environment) AddLabel

func (k *Environment) AddLabel(selector string, label string) error

AddLabel adds a new label to a group of pods defined by selector

func (*Environment) ApplyChaosExperiment

func (k *Environment) ApplyChaosExperiment(exp chaos.Experimentable) (string, error)

ApplyChaosExperiment applies experiment to an ephemeral env

func (*Environment) ApplyChaosExperimentFromTemplate

func (k *Environment) ApplyChaosExperimentFromTemplate(tmplPath string) error

ApplyChaosExperimentFromTemplate applies experiment to a standalone env

func (*Environment) ClearAllChaosExperiments

func (k *Environment) ClearAllChaosExperiments() error

ClearAllChaosExperiments clears all chaos experiments

func (*Environment) ClearAllChaosStandaloneExperiments

func (k *Environment) ClearAllChaosStandaloneExperiments(expInfos map[string]*chaos.ExperimentInfo) error

ClearAllChaosStandaloneExperiments remove all chaos experiments from a standalone env

func (*Environment) ClearConfig

func (k *Environment) ClearConfig() error

ClearConfig resets the config so only the preset config remains

func (*Environment) ClearConfigLocalPorts

func (k *Environment) ClearConfigLocalPorts() error

ClearConfigLocalPorts removes the local ports set within config

func (*Environment) Connect

func (k *Environment) Connect(chartName string) error

Connect to a single chart

func (*Environment) ConnectAll

func (k *Environment) ConnectAll() error

ConnectAll connects to all containerPorts for all charts, dump config in JSON if Persistent flag is present

func (*Environment) DeferTeardown

func (k *Environment) DeferTeardown()

DeferTeardown wraps teardown and logs on error, to be used in deferred function calls

func (*Environment) Deploy

func (k *Environment) Deploy(chartName string) error

Deploy a single chart

func (*Environment) DeployAll

func (k *Environment) DeployAll() error

DeployAll deploys all deploy sequence at once

func (*Environment) Disconnect

func (k *Environment) Disconnect()

Disconnect closes any current open port forwarder rules

func (*Environment) GetSecretField

func (k *Environment) GetSecretField(namespace string, secretName string, fieldName string) (string, error)

GetSecretField retrieves field data from k8s secret

func (*Environment) Init

func (k *Environment) Init(namespacePrefix string) error

Init inits namespace for an env and configure helm for k8s and that namespace

func (*Environment) StopChaosExperiment

func (k *Environment) StopChaosExperiment(id string) error

StopChaosExperiment stops experiment in a ephemeral env

func (*Environment) StopChaosStandaloneExperiment

func (k *Environment) StopChaosStandaloneExperiment(expInfo *chaos.ExperimentInfo) error

StopChaosStandaloneExperiment stops experiment in a standalone env

func (*Environment) SyncConfig

func (k *Environment) SyncConfig() error

SyncConfig dumps config in Persistent mode

func (*Environment) SyncConfigJson

func (k *Environment) SyncConfigJson() error

SyncConfigJson dumps a json config in Persistent mode

func (*Environment) Teardown

func (k *Environment) Teardown() error

Teardown tears down the helm releases

func (*Environment) Upgrade

func (k *Environment) Upgrade(chartName string) error

Upgrade a single chart

type HelmChart

type HelmChart struct {
	ReleaseName      string                 `yaml:"release_name,omitempty" json:"release_name,omitempty" envconfig:"release_name"`
	Path             string                 `yaml:"path,omitempty" json:"path,omitempty" envconfig:"path"`
	URL              string                 `yaml:"url,omitempty" json:"url,omitempty" envconfig:"url"`
	Values           map[string]interface{} `yaml:"values,omitempty" json:"values,omitempty" envconfig:"values"`
	Index            int                    `yaml:"index,omitempty" json:"index,omitempty" envconfig:"index"`
	AutoConnect      bool                   `yaml:"auto_connect" json:"auto_connect" envconfig:"auto_connect"`
	ChartConnections ChartConnections       `yaml:"chart_connections,omitempty" json:"chart_connections,omitempty" envconfig:"chart_connections"`
	BeforeHook       Hook                   `yaml:"-" json:"-" envconfig:"-"`
	AfterHook        Hook                   `yaml:"-" json:"-" envconfig:"-"`
	// contains filtered or unexported fields
}

HelmChart represents a single Helm chart to be installed into a cluster

func NewChainlinkChart

func NewChainlinkChart(index int, values map[string]interface{}) *HelmChart

NewChainlinkChart returns a default Chainlink Helm chart based on a set of override values

func (*HelmChart) Connect

func (hc *HelmChart) Connect() error

Connect connects to all exposed containerPorts, forwards them to local

func (*HelmChart) CopyToPod

func (hc *HelmChart) CopyToPod(src, destination, containername string) (*bytes.Buffer, *bytes.Buffer, *bytes.Buffer, error)

CopyToPod copies src to a particular container. Destination should be in the form of a proper K8s destination path NAMESPACE/POD_NAME:folder/FILE_NAME

func (*HelmChart) Deploy

func (hc *HelmChart) Deploy() error

Deploy deploys a chart and update config settings

func (*HelmChart) ExecuteInPod

func (hc *HelmChart) ExecuteInPod(podName string, containerName string, command []string) ([]byte, []byte, error)

ExecuteInPod is similar to kubectl exec

func (*HelmChart) GetPodsByNameSubstring

func (hc *HelmChart) GetPodsByNameSubstring(nameSubstring string) ([]v1.Pod, error)

GetPodsByNameSubstring retrieves all running pods whose names contain the provided substring

func (*HelmChart) Init

func (hc *HelmChart) Init(env *Environment) error

Init sets up the connection to helm for the chart to be managed

func (*HelmChart) Uninstall added in v1.0.61

func (hc *HelmChart) Uninstall() error

Uninstall uninstalls the helm chart

func (*HelmChart) Upgrade

func (hc *HelmChart) Upgrade() error

Upgrade an already deployed Helm chart with new values

type Hook

type Hook func(environment *Environment) error

Hook is an environment hook to be ran either before or after a deployment

type MarshalSafeDuration

type MarshalSafeDuration time.Duration

MarshalSafeDuration enables proper json marshalling and unmarshaling for config values See: https://stackoverflow.com/questions/48050945/how-to-unmarshal-json-into-durations

func (MarshalSafeDuration) AsTimeDuration

func (d MarshalSafeDuration) AsTimeDuration() time.Duration

AsTimeDuration returns as a standard time.Duration

func (MarshalSafeDuration) MarshalJSON

func (d MarshalSafeDuration) MarshalJSON() ([]byte, error)

MarshalJSON marshals durations into proper json

func (*MarshalSafeDuration) UnmarshalJSON

func (d *MarshalSafeDuration) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals durations into proper json

type Protocol

type Protocol int

Protocol represents a URL scheme to use when fetching connection details

const (
	// WS : Web Socket Protocol
	WS Protocol = iota
	// WSS : Web Socket Secure Protocol
	WSS
	// HTTP : Hypertext Transfer Protocol
	HTTP
	// HTTPS : Hypertext Transfer Protocol Secure
	HTTPS
)

type SimulatedNetwork added in v1.0.52

type SimulatedNetwork func() (string, map[string]interface{})

SimulatedNetwork is a function that enables launching a simulated network with a returned chart name and corresponding values

Jump to

Keyboard shortcuts

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