From 34b425568ae9b3fbca0a3bfb0bf88653cb896ae9 Mon Sep 17 00:00:00 2001 From: kidneyweak Date: Tue, 16 Jan 2024 16:35:11 +0800 Subject: [PATCH] temp: cluster apply network --- .../instance/infra/InfraRunner.interface.ts | 1 + .../kubernetes/charts/goquorum-node/values.yaml | 2 +- src/quorum/instance/infra/kubernetes/runner.ts | 17 ++++++----------- src/quorum/instance/kubernetesCluster.ts | 7 +++++++ src/quorum/service/cluster.ts | 5 +++-- 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/quorum/instance/infra/InfraRunner.interface.ts b/src/quorum/instance/infra/InfraRunner.interface.ts index 58318aa..7cf8957 100644 --- a/src/quorum/instance/infra/InfraRunner.interface.ts +++ b/src/quorum/instance/infra/InfraRunner.interface.ts @@ -32,6 +32,7 @@ export interface InfraRunner { export interface KubernetesInfraRunner { createDeploymentAndService(payload: K8SRunCommandType): Promise createTemplate(payload: K8SRunCommandType): Promise + wait(job: string, namespace: string): Promise deleteDeploymentAndService(payload: K8SRunCommandType): Promise } diff --git a/src/quorum/instance/infra/kubernetes/charts/goquorum-node/values.yaml b/src/quorum/instance/infra/kubernetes/charts/goquorum-node/values.yaml index 2af0697..3680c23 100644 --- a/src/quorum/instance/infra/kubernetes/charts/goquorum-node/values.yaml +++ b/src/quorum/instance/infra/kubernetes/charts/goquorum-node/values.yaml @@ -114,7 +114,7 @@ node: image: goquorum: repository: quorumengineering/quorum - tag: 22.7.1 + tag: 23.4.0 tessera: repository: quorumengineering/tessera tag: 22.1.7 diff --git a/src/quorum/instance/infra/kubernetes/runner.ts b/src/quorum/instance/infra/kubernetes/runner.ts index 2625a97..c565829 100644 --- a/src/quorum/instance/infra/kubernetes/runner.ts +++ b/src/quorum/instance/infra/kubernetes/runner.ts @@ -1,8 +1,6 @@ -import YAML from 'js-yaml' import { logger } from '../../../../util/logger' import { spawn } from 'child_process' import config from '../../../config' -import fs from 'fs-extra' import { DockerResultType, KubernetesInfraRunner } from '../InfraRunner.interface' import { K8SRunCommandType } from '../../../model/type/kubernetes.type' @@ -30,6 +28,12 @@ export class Runner implements KubernetesInfraRunner { return { stdout: '' } } + public wait = async (job: string, namespace: string): Promise => { + await console.log('wait') + await this.runKubectl(['wait', '--for=condition=complete', job, '-n', namespace, '--timeout=600s']) + return { stdout: '' } + } + public deleteDeploymentAndService = async (payload: K8SRunCommandType): Promise => { await console.log('deleteDeploymentAndService') await this.runHelm( @@ -57,15 +61,6 @@ export class Runner implements KubernetesInfraRunner { return { stdout: '' } } - private getYaml (path: string): Promise { - return new Promise((resolve, reject) => { - fs.readFile(path, 'utf8', (err, data) => { - if (err) reject(err) - resolve(YAML.load(data)) - }) - }) - } - private async checkAndCreateNamespace (namespace: string): Promise { try { console.log(`kubectl get namespaces ${namespace}`) diff --git a/src/quorum/instance/kubernetesCluster.ts b/src/quorum/instance/kubernetesCluster.ts index 8d434e0..234980b 100644 --- a/src/quorum/instance/kubernetesCluster.ts +++ b/src/quorum/instance/kubernetesCluster.ts @@ -18,4 +18,11 @@ export default class KubernetesInstance extends AbstractInstance { return await this.kubernetesInfra.createTemplate(payload) } } + + public async wait (job: string, namespace: string) { + logger.debug('Kubernetes instance wait') + if (this.kubernetesInfra !== undefined) { + return await this.kubernetesInfra.wait(job, namespace) + } + } } diff --git a/src/quorum/service/cluster.ts b/src/quorum/service/cluster.ts index 6ae307b..d2214ae 100644 --- a/src/quorum/service/cluster.ts +++ b/src/quorum/service/cluster.ts @@ -24,6 +24,7 @@ export default class Cluster extends AbstractService { values: this.bdkFile.getGenesisChartPath(), }) + await k8s.wait('job.batch/goquorum-genesis-init', 'quorum') // create network const validatorYaml = new ValidatorConfigYaml() validatorYaml.setCluster() @@ -44,7 +45,7 @@ export default class Cluster extends AbstractService { for (let i = 0; i < validatorNumber; i += 1) { await k8s.install({ helmChart: this.bdkFile.getGoQuorumNodeChartPath(), - name: `validator${i}`, + name: `validator-${i + 1}`, namespace: 'quorum', values: this.bdkFile.getValidatorChartPath(i), }) @@ -52,7 +53,7 @@ export default class Cluster extends AbstractService { for (let i = 0; i < memberNumber; i += 1) { await k8s.install({ helmChart: this.bdkFile.getGoQuorumNodeChartPath(), - name: `member${i}`, + name: `member-${i + 1}`, namespace: 'quorum', values: this.bdkFile.getMemberChartPath(i), })