environment

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2021 License: MIT Imports: 42 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AdapterAPIPort    uint16 = 6060
	ChainlinkWebPort  uint16 = 6688
	ChainlinkP2PPort  uint16 = 6690
	ExplorerAPIPort   uint16 = 8080
	PrometheusAPIPort uint16 = 9090
	MockserverAPIPort uint16 = 1080
)

Ports for common services

View Source
const (
	DefaultEVMRPCPort uint16 = 8545
	HardhatRPCPort    uint16 = 8545
	GethRPCPort       uint16 = 8546
	GanacheRPCPort    uint16 = 8547
	MinersRPCPort     uint16 = 9545
)

Ethereum ports

View Source
const (
	TerraLCDPort uint16 = 1317
	TerraFCDPort uint16 = 3060
)

Terra ports

View Source
const (
	SelectorLabelKey          = "app"
	PrivateNetworksInfoSecret = "private-keys"
)

SelectorLabelKey used to find pod labels

View Source
const (
	// HelmInstallTimeout timeout for installing a helm chart
	HelmInstallTimeout = 200 * time.Second
	// ReleasePrefix the default prefix
	ReleasePrefix = "release"
	// DefaultK8sConfigPath the default path for kube
	DefaultK8sConfigPath = ".kube/config"
)

Variables

View Source
var (
	DefaultChainlinkAuthMap = map[string][]byte{
		"apicredentials": []byte("notreal@fakeemail.ch\ntwochains"),
		"node-password":  []byte("T.tLHkcmwePT/p,]sYuntjwHKAsrhm#4eRs4LuKHwvHejWYAC2JP4M8HimwgmbaZ"),
	}
)

Functions

func GetChainlinkClients

func GetChainlinkClients(env Environment) ([]client.Chainlink, error)

GetChainlinkClients will return all instantiated Chainlink clients for a given environment

func GetExplorerClientFromEnv added in v0.0.3

func GetExplorerClientFromEnv(env Environment) (*client.ExplorerClient, error)

GetExplorerClientFromEnv returns an ExplorerClient initialized with port from service in k8s

func GetMockserverClientFromEnv added in v0.0.5

func GetMockserverClientFromEnv(env Environment) (*client.MockserverClient, error)

GetMockserverClientFromEnv returns a Mockserver client

func GetPrometheusClientFromEnv added in v0.0.5

func GetPrometheusClientFromEnv(env Environment) (*client.Prometheus, error)

GetPrometheusClientFromEnv returns a Prometheus client

func K8sConfig added in v0.0.2

func K8sConfig() (*rest.Config, error)

K8sConfig loads new default k8s config from filesystem

func NewBlockchainClient

func NewBlockchainClient(env Environment, network client.BlockchainNetwork) (client.BlockchainClient, error)

NewBlockchainClient will return an instantiated blockchain client and switch the URL depending if there's one deployed into the environment. If there's no deployed blockchain in the environment, the URL from the network config will be used

func NewBlockchainClients added in v0.0.5

func NewBlockchainClients(env Environment, network client.BlockchainNetwork) (client.BlockchainClient, error)

NewBlockchainClients will return an instantiated blockchain client that uses default client to communicate with a node, can switch clients

func NewExplorerClient added in v0.0.3

func NewExplorerClient(localUrl string) (*client.ExplorerClient, error)

NewExplorerClient creates an ExplorerClient from localUrl

func NewPrivateKeyStoreFromEnv

func NewPrivateKeyStoreFromEnv(env Environment, network *config.NetworkConfig) (config.PrivateKeyStore, error)

NewPrivateKeyStoreFromEnv returns a keystore looking either in a cluster secret or directly from the config

Types

type Environment

type Environment interface {
	ID() string

	GetAllServiceDetails(remotePort uint16) ([]*ServiceDetails, error)
	GetServiceDetails(remotePort uint16) (*ServiceDetails, error)
	GetSecretField(namespace string, secretName string, privateKey string) (string, error)

	WriteArtifacts(testLogFolder string)
	ApplyChaos(exp chaos.Experimentable) (string, error)
	StopChaos(name string) error
	StopAllChaos() error
	TearDown()

	DeploySpecs(init K8sEnvSpecInit) error
}

Environment is the interface that represents a deployed environment, whether locally or on remote machines

func NewK8sEnvironment

func NewK8sEnvironment(
	cfg *config.Config,
	networks ...client.BlockchainNetwork,
) (Environment, error)

NewK8sEnvironment connects to a k8s cluster. Your current context within your kube config will always be used.

type ExternalAdapter

type ExternalAdapter interface {
	TriggerValueChange(i int) (int, error)
	LocalURL() string
	ClusterURL() string
	SetVariable(variable int) error
}

ExternalAdapter represents a dummy external adapter within the K8sEnvironment

func GetExternalAdapter

func GetExternalAdapter(env Environment) (ExternalAdapter, error)

GetExternalAdapter will return a deployed external adapter on an environment

type HelmChart added in v0.0.2

type HelmChart struct {
	SetValuesHelmFunc SetValuesHelmFunc
	// contains filtered or unexported fields
}

HelmChart common helm chart data

func NewGethReorgHelmChart added in v0.0.2

func NewGethReorgHelmChart(networkCount int, network *config.NetworkConfig) *HelmChart

NewGethReorgHelmChart creates new helm chart for multi-node Geth network

func NewKafkaHelmChart added in v0.0.5

func NewKafkaHelmChart() *HelmChart

NewKafkaHelmChart creates new helm chart for kafka

func NewLocalTerraHelmChart added in v0.0.11

func NewLocalTerraHelmChart(networkCount int, network *config.NetworkConfig) *HelmChart

NewLocalTerraHelmChart creates new helm chart for Terra network with Lite/Full chain clients

func NewMockserverConfigHelmChart added in v0.0.5

func NewMockserverConfigHelmChart() *HelmChart

NewMockserverConfigHelmChart creates new helm chart for the mockserver configmap

func NewMockserverHelmChart added in v0.0.5

func NewMockserverHelmChart() *HelmChart

NewMockserverHelmChart creates new helm chart for the mockserver

func NewTerraRelayHelmChart added in v0.0.11

func NewTerraRelayHelmChart(idx int) *HelmChart

NewTerraRelayHelmChart creates new helm chart for Terra network relay

func (*HelmChart) Deploy added in v0.0.2

func (k *HelmChart) Deploy(_ map[string]interface{}) error

Deploy deploys the helm charts

func (*HelmChart) GetConfig added in v0.0.2

func (k *HelmChart) GetConfig() *config.Config

GetConfig gets the helms environment config

func (*HelmChart) ID added in v0.0.2

func (k *HelmChart) ID() string

ID returns the helm chart id

func (*HelmChart) ServiceDetails added in v0.0.2

func (k *HelmChart) ServiceDetails() ([]*ServiceDetails, error)

ServiceDetails gets the details of the released service

func (*HelmChart) SetEnvironment added in v0.0.2

func (k *HelmChart) SetEnvironment(environment *K8sEnvironment) error

SetEnvironment sets the environment

func (*HelmChart) SetValue added in v0.0.2

func (k *HelmChart) SetValue(key string, val interface{})

SetValue sets the specified value in the chart

func (*HelmChart) Teardown added in v0.0.2

func (k *HelmChart) Teardown() error

Teardown tears down the helm release

func (*HelmChart) Values added in v0.0.2

func (k *HelmChart) Values() map[string]interface{}

Values returns the helm charts values

func (*HelmChart) WaitUntilHealthy added in v0.0.2

func (k *HelmChart) WaitUntilHealthy() error

WaitUntilHealthy waits until the helm release is healthy

type K8sEnvResource

type K8sEnvResource interface {
	ID() string
	GetConfig() *config.Config
	SetEnvironment(environment *K8sEnvironment) error
	Deploy(values map[string]interface{}) error
	WaitUntilHealthy() error
	ServiceDetails() ([]*ServiceDetails, error)
	SetValue(key string, val interface{})
	Values() map[string]interface{}
	Teardown() error
}

K8sEnvResource is the interface for deploying a given environment resource. Creating an interface for resource deployment allows it to be extended, deploying k8s resources in different ways. For example: K8sManifest deploys a single manifest, whereas K8sManifestGroup bundles several K8sManifests to be deployed concurrently.

type K8sEnvSpecInit

type K8sEnvSpecInit func(...client.BlockchainNetwork) K8sEnvSpecs

K8sEnvSpecInit is the initiator that will return the name of the environment and the specifications to be deployed.

func NewChainlinkCluster

func NewChainlinkCluster(nodeCount int) K8sEnvSpecInit

NewChainlinkCluster is a basic environment that deploys hardhat with a chainlink cluster and an external adapter

func NewChainlinkClusterForObservabilityTesting added in v0.0.5

func NewChainlinkClusterForObservabilityTesting(nodeCount int) K8sEnvSpecInit

NewChainlinkClusterForObservabilityTesting is a basic environment that deploys a chainlink cluster with dependencies for testing observability

func NewChainlinkHeadlessCluster added in v0.0.11

func NewChainlinkHeadlessCluster(nodeCount int) K8sEnvSpecInit

NewChainlinkHeadlessCluster is a basic environment that deploys headless Chainlink cluster without direct connection to the network

func NewMixedVersionChainlinkCluster

func NewMixedVersionChainlinkCluster(nodeCount, pastVersionsCount int) K8sEnvSpecInit

NewMixedVersionChainlinkCluster mixes the currently latest chainlink version (as defined by the config file) with a number of past stable versions (defined by pastVersionsCount), ensuring that at least one of each is deployed

func NewRelays added in v0.0.11

func NewRelays(nodeCount int) K8sEnvSpecInit

NewRelays adds new External Initiators (Relays) specs

func OtpeGroup added in v0.0.5

func OtpeGroup() K8sEnvSpecInit

OtpeGroup contains manifests for otpe

func PrometheusGroup added in v0.0.5

func PrometheusGroup(rules map[string]*os.File) K8sEnvSpecInit

PrometheusGroup contains manifests for prometheus

type K8sEnvSpecs

type K8sEnvSpecs []K8sEnvResource

K8sEnvSpecs represents a series of environment resources to be deployed. The resources in the array will be deployed in the order that they are present in the array.

type K8sEnvironment

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

K8sEnvironment holds the resources for a Kubernetes deployment and environment

func (*K8sEnvironment) ApplyChaos added in v0.0.2

func (env *K8sEnvironment) ApplyChaos(exp chaos.Experimentable) (string, error)

ApplyChaos applies chaos experiment in the environment namespace

func (*K8sEnvironment) DeploySpecs added in v0.0.5

func (env *K8sEnvironment) DeploySpecs(init K8sEnvSpecInit) error

DeploySpecs deploys all specs in the provided environment init function

func (*K8sEnvironment) GetAllServiceDetails

func (env *K8sEnvironment) GetAllServiceDetails(remotePort uint16) ([]*ServiceDetails, error)

GetAllServiceDetails returns all the connectivity details for a deployed service by its remote port within k8s

func (*K8sEnvironment) GetSecretField added in v0.0.5

func (env *K8sEnvironment) GetSecretField(namespace string, secretName string, fieldName string) (string, error)

GetSecretField retrieves field data from k8s secret

func (*K8sEnvironment) GetServiceDetails

func (env *K8sEnvironment) GetServiceDetails(remotePort uint16) (*ServiceDetails, error)

GetServiceDetails returns all the connectivity details for a deployed service by its remote port within k8s

func (*K8sEnvironment) ID

func (env *K8sEnvironment) ID() string

ID returns the canonical name of the environment, which in the case of k8s is the namespace

func (*K8sEnvironment) StopAllChaos added in v0.0.2

func (env *K8sEnvironment) StopAllChaos() error

StopAllChaos stops all chaos experiments

func (*K8sEnvironment) StopChaos added in v0.0.2

func (env *K8sEnvironment) StopChaos(name string) error

StopChaos stops experiment by name

func (*K8sEnvironment) TearDown

func (env *K8sEnvironment) TearDown()

TearDown cycles through all the specifications and tears down the deployments. This typically entails cleaning up port forwarding requests and deleting the namespace that then destroys all definitions.

func (*K8sEnvironment) WriteArtifacts

func (env *K8sEnvironment) WriteArtifacts(testLogFolder string)

WriteArtifacts dumps pod logs and DB info within the environment into local log files, used near exclusively on test failure

type K8sManifest

type K8sManifest struct {

	// Manifest properties
	DeploymentFile string
	ServiceFile    string
	SecretFile     string
	ConfigMapFile  string
	Deployment     *appsV1.Deployment
	Service        *coreV1.Service
	ConfigMap      *coreV1.ConfigMap
	Secret         *coreV1.Secret
	SetValuesFunc  k8sSetValuesFunc
	Network        *config.NetworkConfig
	// contains filtered or unexported fields
}

K8sManifest represents a manifest of k8s definitions to be deployed. It implements the K8sEnvResource interface to allow the deployment of the definitions into a cluster. It consists of a k8s secret, deployment and service but can be expanded to allow more definitions if needed, or extended with another interface to expand on its functionality.

func NewAdapterManifest

func NewAdapterManifest() *K8sManifest

NewAdapterManifest is the k8s manifest that when used will deploy an external adapter to an environment

func NewChainlinkManifest

func NewChainlinkManifest() *K8sManifest

NewChainlinkManifest is the k8s manifest that when used will deploy a chainlink node to an environment

func NewExplorerManifest

func NewExplorerManifest(nodeCount int) *K8sManifest

NewExplorerManifest is the k8s manifest that when used will deploy explorer to an environment and create access keys for a nodeCount number of times

func NewGanacheManifest

func NewGanacheManifest(networkCount int, network *config.NetworkConfig) *K8sManifest

NewGanacheManifest is the k8s manifest that when used will deploy ganache to an environment

func NewGethManifest

func NewGethManifest(networkCount int, network *config.NetworkConfig) *K8sManifest

NewGethManifest is the k8s manifest that when used will deploy geth to an environment

func NewHardhatManifest

func NewHardhatManifest(networkCount int, network *config.NetworkConfig) *K8sManifest

NewHardhatManifest is the k8s manifest that when used will deploy hardhat to an environment

func NewHeadlessChainlinkManifest added in v0.0.11

func NewHeadlessChainlinkManifest() *K8sManifest

NewHeadlessChainlinkManifest is the k8s manifest for Chainlink node without network, using only EI to get network data

func NewOTPEManifest added in v0.0.5

func NewOTPEManifest() *K8sManifest

NewOTPEManifest is the k8s manifest for deploying otpe

func NewPostgresManifest added in v0.0.2

func NewPostgresManifest() *K8sManifest

NewPostgresManifest is the k8s manifest that when used will deploy a postgres db to an environment

func NewPrometheusManifest added in v0.0.5

func NewPrometheusManifest(rules map[string]*os.File) *K8sManifest

NewPrometheusManifest creates new k8s manifest for prometheus It receives a map of strings to *os.File which it uses in the following way: The string in the map is the template value that will be used the prometheus-config-map.yml file. The *os.File contains the rules yaml file, before being added to the values map of the K8sManifest. Every line of the file is appended 4 spaces, this is done so after the file is templated to the prometheus-config-map.yml file, the yml will be formatted correctly.

func (*K8sManifest) Deploy

func (m *K8sManifest) Deploy(values map[string]interface{}) error

Deploy will create the definitions for each manifest on the k8s cluster

func (*K8sManifest) ExecuteInPod added in v0.0.3

func (m *K8sManifest) ExecuteInPod(podName string, containerName string, command []string) ([]byte, []byte, error)

ExecuteInPod is similar to kubectl exec

func (*K8sManifest) GetConfig added in v0.0.2

func (m *K8sManifest) GetConfig() *config.Config

GetConfig gets the config for the manifest group

func (*K8sManifest) ID

func (m *K8sManifest) ID() string

ID returns the identifier for the manifest. The ID is important as the manifest will automatically add labels and service selectors to link deployments to their manifests.

func (*K8sManifest) ServiceDetails

func (m *K8sManifest) ServiceDetails() ([]*ServiceDetails, error)

ServiceDetails returns the connectivity details for a deployed service

func (*K8sManifest) SetEnvironment

func (m *K8sManifest) SetEnvironment(
	environment *K8sEnvironment,
) error

SetEnvironment is the K8sEnvResource implementation that sets the current cluster and config to be used on deploy

func (*K8sManifest) SetValue added in v0.0.2

func (m *K8sManifest) SetValue(key string, val interface{})

SetValue sets the value for the manifest group

func (*K8sManifest) Teardown

func (m *K8sManifest) Teardown() error

Teardown sends a message to the port forwarding channels to stop the request

func (*K8sManifest) Values

func (m *K8sManifest) Values() map[string]interface{}

Values returns all the values to be exposed in the definition templates

func (*K8sManifest) WaitUntilHealthy

func (m *K8sManifest) WaitUntilHealthy() error

WaitUntilHealthy will wait until all pods that are created from a given manifest are healthy. Once healthy, it will then forward all ports that are exposed within the service and callback to set values.

type K8sManifestGroup

type K8sManifestGroup struct {
	SetValuesFunc manifestGroupSetValuesFunc
	// contains filtered or unexported fields
}

K8sManifestGroup is an implementation of K8sEnvResource that allows a group of manifests to be deployed concurrently on the cluster. This is important for services that don't have dependencies on each other. For example: a Chainlink node doesn't depend on other Chainlink nodes on deploy and an adapter doesn't depend on Chainlink nodes on deploy, only later on within the test lifecycle which means they can be included within a single group. Whereas, Chainlink does depend on a deployed Geth, Hardhat, Ganache on deploy so they cannot be included in the group as Chainlink definition needs to know the cluster IP of the deployment for it to boot.

func (*K8sManifestGroup) Deploy

func (mg *K8sManifestGroup) Deploy(values map[string]interface{}) error

Deploy concurrently creates all of the definitions on the k8s cluster

func (*K8sManifestGroup) GetConfig added in v0.0.2

func (mg *K8sManifestGroup) GetConfig() *config.Config

GetConfig gets the config for the manifest group

func (*K8sManifestGroup) ID

func (mg *K8sManifestGroup) ID() string

ID returns the identifier of the manifest group

func (*K8sManifestGroup) ServiceDetails

func (mg *K8sManifestGroup) ServiceDetails() ([]*ServiceDetails, error)

ServiceDetails will return all the details of the services within a group

func (*K8sManifestGroup) SetEnvironment

func (mg *K8sManifestGroup) SetEnvironment(env *K8sEnvironment) error

SetEnvironment initiates the k8s cluster and config within all the nested manifests

func (*K8sManifestGroup) SetValue added in v0.0.2

func (mg *K8sManifestGroup) SetValue(key string, val interface{})

SetValue sets the value for the manifest group

func (*K8sManifestGroup) Teardown

func (mg *K8sManifestGroup) Teardown() error

Teardown will iterate through each manifest and tear it down

func (*K8sManifestGroup) Values

func (mg *K8sManifestGroup) Values() map[string]interface{}

Values will return all of the defined values to be exposed in the template definitions. Due to there possibly being multiple of the same manifest in the group, it will create keys of each manifest id, also keys with each manifest followed by its index. For example: values["adapter"].apiPort values["chainlink"].webPort values["chainlink_0"].webPort values["chainlink_1"].webPort

func (*K8sManifestGroup) WaitUntilHealthy

func (mg *K8sManifestGroup) WaitUntilHealthy() error

WaitUntilHealthy will wait until all of the manifests in the group are considered healthy. To avoid it duplicating checks for multiple of the same manifest in a group, it will first create a unique map of manifest IDs so checks aren't performed multiple times.

type PodForwardedInfo added in v0.0.2

type PodForwardedInfo struct {
	PodIP          string
	ForwardedPorts []portforward.ForwardedPort
	PodName        string
}

PodForwardedInfo data to port forward the pods

type ServiceDetails

type ServiceDetails struct {
	RemoteURL *url.URL
	LocalURL  *url.URL
}

ServiceDetails contains all of the connectivity properties about a given deployed service

type SetValuesHelmFunc added in v0.0.2

type SetValuesHelmFunc func(resource *HelmChart) error

SetValuesHelmFunc interface for setting values in a helm chart

type TemplateValuesArray added in v0.0.3

type TemplateValuesArray struct {
	Values []interface{}
	// contains filtered or unexported fields
}

TemplateValuesArray is used in the next template go func It's goal is to store an array of objects The only function it has, next, returns the first object from they array, and then removing that object from the array

Jump to

Keyboard shortcuts

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