From 6cb804dfc7d99ab00dc56c48865606c3e1245c13 Mon Sep 17 00:00:00 2001 From: gheorghestrimtu Date: Wed, 8 Sep 2021 16:20:13 +0300 Subject: [PATCH 1/3] separate explorer --- environment/environment_templates.go | 83 +++++++++++++------ environment/k8s_environment.go | 7 +- .../chainlink/chainlink-deployment.yml | 2 + suite/contracts/contracts_alerts_test.go | 2 +- 4 files changed, 67 insertions(+), 27 deletions(-) diff --git a/environment/environment_templates.go b/environment/environment_templates.go index 440f112bc..1a2ccc032 100644 --- a/environment/environment_templates.go +++ b/environment/environment_templates.go @@ -224,7 +224,25 @@ func NewChainlinkCluster(nodeCount int) K8sEnvSpecInit { chainlinkGroup.manifests = append(chainlinkGroup.manifests, cManifest) } - return addDependencyGroup(nodeCount, "basic-chainlink", chainlinkGroup) + dependencyGroup := getBasicDependencyGroup() + addPostgresDbsToDependencyGroup(dependencyGroup, nodeCount) + return addNetworkManifestToDependencyGroup("basic-chainlink", dependencyGroup, chainlinkGroup) +} + +func NewChainlinkClusterForAlertsTesting(nodeCount int) K8sEnvSpecInit { + chainlinkGroup := &K8sManifestGroup{ + id: "chainlinkCluster", + manifests: []K8sEnvResource{}, + } + for i := 0; i < nodeCount; i++ { + cManifest := NewChainlinkManifest() + cManifest.id = fmt.Sprintf("%s-%d", cManifest.id, i) + chainlinkGroup.manifests = append(chainlinkGroup.manifests, cManifest) + } + dependencyGroup := getBasicDependencyGroup() + addPostgresDbsToDependencyGroup(dependencyGroup, nodeCount) + addServicesForTestingAlertsToDependencyGroup(dependencyGroup, nodeCount) + return addNetworkManifestToDependencyGroup("basic-chainlink", dependencyGroup, chainlinkGroup) } // NewMixedVersionChainlinkCluster mixes the currently latest chainlink version (as defined by the config file) with @@ -261,7 +279,11 @@ func NewMixedVersionChainlinkCluster(nodeCount, pastVersionsCount int) K8sEnvSpe chainlinkGroup.manifests = append(chainlinkGroup.manifests, cManifest) } - return addDependencyGroup(nodeCount, "mixed-version-chainlink", chainlinkGroup) + dependencyGroup := getBasicDependencyGroup() + addPostgresDbsToDependencyGroup(dependencyGroup, nodeCount) + return addNetworkManifestToDependencyGroup("mixed-version-chainlink", dependencyGroup, chainlinkGroup) + + //return addDependencyGroup(nodeCount, "mixed-version-chainlink", chainlinkGroup) } // NewGethReorgHelmChart creates new helm chart for multi-node Geth network @@ -306,9 +328,8 @@ func getMixedVersions(versionCount int) ([]string, error) { return mixedVersions, nil } -// addDependencyGroup add everything that has no dependencies but other pods have -// dependencies on in the first group -func addDependencyGroup(nodeCount int, envName string, chainlinkGroup *K8sManifestGroup) K8sEnvSpecInit { +// getBasicDependencyGroup returns a manifest group containing the basic setup for a chainlink deployment +func getBasicDependencyGroup() *K8sManifestGroup { group := &K8sManifestGroup{ id: "DependencyGroup", manifests: []K8sEnvResource{NewAdapterManifest()}, @@ -327,40 +348,52 @@ func addDependencyGroup(nodeCount int, envName string, chainlinkGroup *K8sManife return nil }, } - for i := 0; i < nodeCount; i++ { - pManifest := NewPostgresManifest() - pManifest.id = fmt.Sprintf("%s-%d", pManifest.id, i) - group.manifests = append(group.manifests, pManifest) - } + return group +} +// addNetworkManifestToDependencyGroup adds the correct network to the dependency group and returns +// an array of all groups, this should be called as the last function when creating deploys +func addNetworkManifestToDependencyGroup(envName string, dependencyGroup *K8sManifestGroup, chainlinkGroup *K8sManifestGroup) K8sEnvSpecInit { return func(config *config.NetworkConfig) (string, K8sEnvSpecs) { switch config.Name { case "Ethereum Geth reorg": - group.manifests = append( - group.manifests, + dependencyGroup.manifests = append( + dependencyGroup.manifests, NewGethReorgHelmChart(), ) case "Ethereum Geth dev": - group.manifests = append( - group.manifests, - NewGethManifest(), - NewExplorerManifest(nodeCount)) + dependencyGroup.manifests = append( + dependencyGroup.manifests, + NewGethManifest()) case "Ethereum Hardhat": - group.manifests = append( - group.manifests, + dependencyGroup.manifests = append( + dependencyGroup.manifests, NewHardhatManifest()) case "Ethereum Ganache": - group.manifests = append( - group.manifests, + dependencyGroup.manifests = append( + dependencyGroup.manifests, NewGanacheManifest()) default: // no simulated chain - group.manifests = append( - group.manifests, - NewExplorerManifest(nodeCount)) + dependencyGroup.manifests = append( + dependencyGroup.manifests) } if len(chainlinkGroup.manifests) > 0 { - return envName, K8sEnvSpecs{group, chainlinkGroup} + return envName, K8sEnvSpecs{dependencyGroup, chainlinkGroup} } - return envName, K8sEnvSpecs{group} + return envName, K8sEnvSpecs{dependencyGroup} + } +} + +// addPostgresDbsToDependencyGroup adds a postgresCount number of postgres dbs to the dependency group +func addPostgresDbsToDependencyGroup(dependencyGroup *K8sManifestGroup, postgresCount int) { + for i := 0; i < postgresCount; i++ { + pManifest := NewPostgresManifest() + pManifest.id = fmt.Sprintf("%s-%d", pManifest.id, i) + dependencyGroup.manifests = append(dependencyGroup.manifests, pManifest) } } + +// addServicesForTestingAlertsToDependencyGroup adds services necessary for testing alerts to the dependency group +func addServicesForTestingAlertsToDependencyGroup(dependencyGroup *K8sManifestGroup, nodeCount int) { + dependencyGroup.manifests = append(dependencyGroup.manifests, NewExplorerManifest(nodeCount)) +} diff --git a/environment/k8s_environment.go b/environment/k8s_environment.go index b03b45bdb..9082c5866 100644 --- a/environment/k8s_environment.go +++ b/environment/k8s_environment.go @@ -853,13 +853,18 @@ func next(array *TemplateValuesArray) (interface{}, error) { return val, nil } +func present(name string, data map[string]interface{}) bool { + _, ok := data[name] + return ok +} + func (m *K8sManifest) parse(path string, obj interface{}, data interface{}) error { fileBytes, err := ioutil.ReadFile(path) if err != nil { return fmt.Errorf("failed to read k8s file: %v", err) } - var funcs = template.FuncMap{"next": next} + var funcs = template.FuncMap{"next": next, "present": present} tpl, err := template.New(path).Funcs(funcs).Parse(string(fileBytes)) if err != nil { diff --git a/environment/templates/chainlink/chainlink-deployment.yml b/environment/templates/chainlink/chainlink-deployment.yml index 60355eb61..52be7490f 100644 --- a/environment/templates/chainlink/chainlink-deployment.yml +++ b/environment/templates/chainlink/chainlink-deployment.yml @@ -83,6 +83,7 @@ spec: value: "200000" - name: KEEPER_REGISTRY_PERFORM_GAS_OVERHEAD value: "150000" + {{ if (present "explorer" .Values.DependencyGroup) }} - name: EXPLORER_URL value: {{ .Values.DependencyGroup.explorer.clusterURL }} {{ with $x := next .Values.DependencyGroup.explorer.keys }} @@ -91,6 +92,7 @@ spec: - name: EXPLORER_SECRET value: {{ $x.Secret }} {{ end }} + {{ end }} volumeMounts: - name: node-secrets-volume readonly: false diff --git a/suite/contracts/contracts_alerts_test.go b/suite/contracts/contracts_alerts_test.go index fb0c47115..8141f0557 100644 --- a/suite/contracts/contracts_alerts_test.go +++ b/suite/contracts/contracts_alerts_test.go @@ -22,7 +22,7 @@ var _ = Describe("Alerts suite", func() { BeforeEach(func() { By("Deploying the environment", func() { suiteSetup, err = actions.DefaultLocalSetup( - environment.NewChainlinkCluster(3), + environment.NewChainlinkClusterForAlertsTesting(3), client.NewNetworkFromConfig, tools.ProjectRoot, ) From f4cf25bb4aa63ededc4859b89bce423120149cbf Mon Sep 17 00:00:00 2001 From: gheorghestrimtu Date: Wed, 8 Sep 2021 16:22:07 +0300 Subject: [PATCH 2/3] clean up --- environment/environment_templates.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/environment/environment_templates.go b/environment/environment_templates.go index 1a2ccc032..40a3bd1e9 100644 --- a/environment/environment_templates.go +++ b/environment/environment_templates.go @@ -282,8 +282,6 @@ func NewMixedVersionChainlinkCluster(nodeCount, pastVersionsCount int) K8sEnvSpe dependencyGroup := getBasicDependencyGroup() addPostgresDbsToDependencyGroup(dependencyGroup, nodeCount) return addNetworkManifestToDependencyGroup("mixed-version-chainlink", dependencyGroup, chainlinkGroup) - - //return addDependencyGroup(nodeCount, "mixed-version-chainlink", chainlinkGroup) } // NewGethReorgHelmChart creates new helm chart for multi-node Geth network From 70882ee0dfa65b05d2c379291b98a29167bb2c72 Mon Sep 17 00:00:00 2001 From: gheorghestrimtu Date: Wed, 8 Sep 2021 16:26:06 +0300 Subject: [PATCH 3/3] lint --- environment/environment_templates.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/environment/environment_templates.go b/environment/environment_templates.go index 40a3bd1e9..7330fef47 100644 --- a/environment/environment_templates.go +++ b/environment/environment_templates.go @@ -357,8 +357,7 @@ func addNetworkManifestToDependencyGroup(envName string, dependencyGroup *K8sMan case "Ethereum Geth reorg": dependencyGroup.manifests = append( dependencyGroup.manifests, - NewGethReorgHelmChart(), - ) + NewGethReorgHelmChart()) case "Ethereum Geth dev": dependencyGroup.manifests = append( dependencyGroup.manifests, @@ -372,8 +371,6 @@ func addNetworkManifestToDependencyGroup(envName string, dependencyGroup *K8sMan dependencyGroup.manifests, NewGanacheManifest()) default: // no simulated chain - dependencyGroup.manifests = append( - dependencyGroup.manifests) } if len(chainlinkGroup.manifests) > 0 { return envName, K8sEnvSpecs{dependencyGroup, chainlinkGroup}