From 4a50475157a47150fe2c96259f7248f38ed2942c Mon Sep 17 00:00:00 2001 From: Lenin Mehedy Date: Mon, 9 Oct 2023 07:05:18 +1100 Subject: [PATCH 1/2] feat: allow deploying chart with custom release name Signed-off-by: Lenin Mehedy --- charts/hedera-network/config-files/envoy.yaml | 2 +- .../hedera-network/config-files/haproxy.cfg | 4 +- .../templates/configmaps/envoy-cm.yaml | 4 +- .../templates/configmaps/haproxy-cm.yaml | 6 +-- .../configmaps/otel-collector-cm.yaml | 2 +- .../templates/configmaps/test-cm.yaml | 2 +- .../gateway-api/envoy-grpc-web-routes.yaml | 6 +-- .../gateway-api/haproxy-grpc-routes.yaml | 6 +-- .../gateway-api/network-node-grpc-routes.yaml | 6 +-- .../templates/network-node-statefulset.yaml | 5 +- charts/hedera-network/templates/pdb.yaml | 2 +- .../templates/proxy/envoy-deployment.yaml | 4 +- .../templates/proxy/haproxy-deployment.yaml | 6 +-- .../templates/rbac/pod-monitor.yaml | 6 +-- .../secrets/backup-uploder-secrets.yaml | 2 +- .../secrets/otel-collector-secrets.yaml | 2 +- .../secrets/uploder-mirror-secrets.yaml | 2 +- .../templates/services/envoy-svc.yaml | 2 +- .../templates/services/haproxy-svc.yaml | 2 +- .../templates/services/network-node-svc.yaml | 2 +- .../templates/sidecars/_backup-uploader.tpl | 3 +- .../templates/sidecars/_sidecars.tpl | 3 +- .../telemetry/prometheus-svc-monitor.yaml | 2 +- .../templates/tests/test-deployment.yaml | 8 ++-- charts/hedera-network/tests/README.md | 2 +- charts/hedera-network/tests/env.sh | 2 + charts/hedera-network/tests/env.template | 1 + charts/hedera-network/tests/helper.sh | 2 +- .../tests/test_gateway_api_deployment.bats | 4 +- dev/Makefile | 4 +- dev/scripts/env.sh | 15 +++++- dev/scripts/main.sh | 47 ++++++++++--------- dev/scripts/template.env | 2 +- 33 files changed, 97 insertions(+), 71 deletions(-) diff --git a/charts/hedera-network/config-files/envoy.yaml b/charts/hedera-network/config-files/envoy.yaml index fd0d4bb0e..945b7a74e 100644 --- a/charts/hedera-network/config-files/envoy.yaml +++ b/charts/hedera-network/config-files/envoy.yaml @@ -81,7 +81,7 @@ static_resources: - endpoint: address: socket_address: - address: network-{{ .nodeConfig.name }}-svc + address: {{ .Release.Name }}-network-{{ .nodeConfig.name }}-svc port_value: 50211 - name: envoy-admin connect_timeout: 0.25s diff --git a/charts/hedera-network/config-files/haproxy.cfg b/charts/hedera-network/config-files/haproxy.cfg index 428d98eb2..86fdc4163 100644 --- a/charts/hedera-network/config-files/haproxy.cfg +++ b/charts/hedera-network/config-files/haproxy.cfg @@ -37,7 +37,7 @@ backend be_servers # Health Checks: Observe all Layer 4 TCP connections for problems. # Health Checks: 5 connections must fail before on-error parameter is invoked and marks server down. # Health Checks: Revive the server with regular health checks by polling the server every 10 seconds. - server server1 network-{{ .nodeConfig.name }}-svc:50211 check inter 10s downinter 10s observe layer4 error-limit 5 on-error mark-down + server server1 {{ .Release.Name }}-network-{{ .nodeConfig.name }}-svc:50211 check inter 10s downinter 10s observe layer4 error-limit 5 on-error mark-down backend be_servers_tls mode tcp option ssl-hello-chk @@ -45,7 +45,7 @@ backend be_servers_tls # Health Checks: Observe all Layer 4 TCP connections for problems. # Health Checks: 5 connections must fail before on-error parameter is invoked and marks server down. # Health Checks: Revive the server with regular health checks by polling the server every 10 seconds. - server server1 network-{{ .nodeConfig.name }}-svc:50212 check inter 10s downinter 10s observe layer4 error-limit 5 on-error mark-down + server server1 {{ .Release.Name }}-network-{{ .nodeConfig.name }}-svc:50212 check inter 10s downinter 10s observe layer4 error-limit 5 on-error mark-down listen stats mode http bind 0.0.0.0:9090 diff --git a/charts/hedera-network/templates/configmaps/envoy-cm.yaml b/charts/hedera-network/templates/configmaps/envoy-cm.yaml index e584f4579..f710b9d3b 100644 --- a/charts/hedera-network/templates/configmaps/envoy-cm.yaml +++ b/charts/hedera-network/templates/configmaps/envoy-cm.yaml @@ -4,10 +4,10 @@ apiVersion: v1 kind: ConfigMap metadata: - name: envoy-proxy-cm-{{ $node.name }} + name: {{ $.Release.Name }}-envoy-proxy-cm-{{ $node.name }} namespace: {{ default $.Release.Namespace $.Values.global.namespaceOverride }} data: envoy.yaml: | - {{- tpl ($.Files.Get "config-files/envoy.yaml") (dict "nodeConfig" $node "Template" $.Template) | nindent 4 }} + {{- tpl ($.Files.Get "config-files/envoy.yaml") (dict "nodeConfig" $node "Template" $.Template "Release" $.Release ) | nindent 4 }} --- {{ end }} diff --git a/charts/hedera-network/templates/configmaps/haproxy-cm.yaml b/charts/hedera-network/templates/configmaps/haproxy-cm.yaml index 3b63a756d..dadfcf6c6 100644 --- a/charts/hedera-network/templates/configmaps/haproxy-cm.yaml +++ b/charts/hedera-network/templates/configmaps/haproxy-cm.yaml @@ -4,17 +4,17 @@ apiVersion: v1 kind: ConfigMap metadata: - name: haproxy-cm-{{ $node.name }} + name: {{ $.Release.Name }}-haproxy-cm-{{ $node.name }} namespace: {{ default $.Release.Namespace $.Values.global.namespaceOverride }} data: haproxy.cfg: | - {{- tpl ($.Files.Get "config-files/haproxy.cfg") (dict "nodeConfig" $node "Template" $.Template) | nindent 4 }} + {{- tpl ($.Files.Get "config-files/haproxy.cfg") (dict "nodeConfig" $node "Template" $.Template "Release" $.Release ) | nindent 4 }} --- {{ end }} apiVersion: v1 kind: ConfigMap metadata: - name: haproxy-ofac-cm + name: {{ $.Release.Name }}-haproxy-ofac-cm data: ofacBlock.acl: | {{- .Files.Get "config-files/ofacBlock.acl" | nindent 4 }} diff --git a/charts/hedera-network/templates/configmaps/otel-collector-cm.yaml b/charts/hedera-network/templates/configmaps/otel-collector-cm.yaml index 726c9bc81..8dc217e5a 100644 --- a/charts/hedera-network/templates/configmaps/otel-collector-cm.yaml +++ b/charts/hedera-network/templates/configmaps/otel-collector-cm.yaml @@ -1,7 +1,7 @@ apiVersion: v1 kind: ConfigMap metadata: - name: otel-collector-cm + name: {{ $.Release.Name }}-otel-collector-cm namespace: {{ default $.Release.Namespace $.Values.global.namespaceOverride }} data: config.yaml: | diff --git a/charts/hedera-network/templates/configmaps/test-cm.yaml b/charts/hedera-network/templates/configmaps/test-cm.yaml index 3c004543b..e539e2d6c 100644 --- a/charts/hedera-network/templates/configmaps/test-cm.yaml +++ b/charts/hedera-network/templates/configmaps/test-cm.yaml @@ -1,7 +1,7 @@ apiVersion: v1 kind: ConfigMap metadata: - name: test-cm + name: {{ $.Release.Name }}-test-cm namespace: {{ default $.Release.Namespace $.Values.global.namespaceOverride }} data: {{- $total_nodes := len $.Values.hedera.nodes -}} diff --git a/charts/hedera-network/templates/gateway-api/envoy-grpc-web-routes.yaml b/charts/hedera-network/templates/gateway-api/envoy-grpc-web-routes.yaml index 7485037f8..d7015921e 100644 --- a/charts/hedera-network/templates/gateway-api/envoy-grpc-web-routes.yaml +++ b/charts/hedera-network/templates/gateway-api/envoy-grpc-web-routes.yaml @@ -6,19 +6,19 @@ apiVersion: gateway.networking.k8s.io/v1beta1 kind: HTTPRoute metadata: - name: envoy-grpc-web-route-{{ $node.name }} + name: {{ $.Release.Name }}-envoy-grpc-web-route-{{ $node.name }} namespace: {{ default $.Release.Namespace $.Values.global.namespaceOverride }} labels: fullstack.hedera.com/type: http-route spec: parentRefs: - - name: fst + - name: {{ $.Values.gatewayApi.gateway.name }} sectionName: grpc-web-{{ $node.name }} hostnames: - {{ tpl $.Values.gatewayApi.route.hostname (dict "node" $node "Template" $.Template) }} rules: - backendRefs: - - name: envoy-proxy-{{ $node.name }}-svc + - name: {{ $.Release.Name }}-envoy-proxy-{{ $node.name }}-svc port: 8080 {{- end }} {{- end }} diff --git a/charts/hedera-network/templates/gateway-api/haproxy-grpc-routes.yaml b/charts/hedera-network/templates/gateway-api/haproxy-grpc-routes.yaml index ae775bbf5..53d869ac9 100644 --- a/charts/hedera-network/templates/gateway-api/haproxy-grpc-routes.yaml +++ b/charts/hedera-network/templates/gateway-api/haproxy-grpc-routes.yaml @@ -6,18 +6,18 @@ apiVersion: gateway.networking.k8s.io/v1alpha2 kind: TCPRoute metadata: - name: haproxy-grpc-route-{{ $node.name }} + name: {{ $.Release.Name }}-haproxy-grpc-route-{{ $node.name }} namespace: {{ default $.Release.Namespace $.Values.global.namespaceOverride }} labels: fullstack.hedera.com/type: tcp-route fullstack.hedera.com/nodeName: {{ $node.name }} spec: parentRefs: - - name: fst + - name: {{ $.Values.gatewayApi.gateway.name }} sectionName: grpc-{{ $node.name }} rules: - backendRefs: - - name: haproxy-{{ $node.name }}-svc + - name: {{ $.Release.Name }}-haproxy-{{ $node.name }}-svc port: 50211 {{- end }} {{- end }} diff --git a/charts/hedera-network/templates/gateway-api/network-node-grpc-routes.yaml b/charts/hedera-network/templates/gateway-api/network-node-grpc-routes.yaml index 214997dc2..15fd5e311 100644 --- a/charts/hedera-network/templates/gateway-api/network-node-grpc-routes.yaml +++ b/charts/hedera-network/templates/gateway-api/network-node-grpc-routes.yaml @@ -6,18 +6,18 @@ apiVersion: gateway.networking.k8s.io/v1alpha2 kind: TCPRoute metadata: - name: node-grpc-route-{{ $node.name }} + name: {{ $.Release.Name }}-node-grpc-route-{{ $node.name }} namespace: {{ default $.Release.Namespace $.Values.global.namespaceOverride }} labels: fullstack.hedera.com/type: tcp-route fullstack.hedera.com/nodeName: {{ $node.name }} spec: parentRefs: - - name: fst + - name: {{ $.Values.gatewayApi.gateway.name }} sectionName: grpc-{{ $node.name }} rules: - backendRefs: - - name: network-{{ $node.name }}-svc + - name: {{ $.Release.Name }}-network-{{ $node.name }}-svc port: 50211 {{- end }} {{- end }} diff --git a/charts/hedera-network/templates/network-node-statefulset.yaml b/charts/hedera-network/templates/network-node-statefulset.yaml index 8ff53dd35..ee3ad0c59 100644 --- a/charts/hedera-network/templates/network-node-statefulset.yaml +++ b/charts/hedera-network/templates/network-node-statefulset.yaml @@ -13,7 +13,7 @@ apiVersion: apps/v1 kind: StatefulSet metadata: - name: network-{{ $node.name }} + name: {{ $.Release.Name }}-network-{{ $node.name }} namespace: {{ default $.Release.Namespace $.Values.global.namespaceOverride }} labels: app: network-{{ $node.name }} @@ -59,7 +59,7 @@ spec: {{- if default $defaults.sidecars.otelCollector.enable $otelCollector.enable | eq "true" }} - name: otel-collector-volume configMap: - name: otel-collector-cm + name: {{ $.Release.Name }}-otel-collector-cm {{- end }} initContainers: # Init Container @@ -101,5 +101,6 @@ spec: "node" $node "defaults" $defaults "minioserver" (index $.Values "minio-server") + "release" $.Release ) | nindent 6 }} {{ end }} diff --git a/charts/hedera-network/templates/pdb.yaml b/charts/hedera-network/templates/pdb.yaml index 643b1f170..f69b54a86 100644 --- a/charts/hedera-network/templates/pdb.yaml +++ b/charts/hedera-network/templates/pdb.yaml @@ -4,7 +4,7 @@ apiVersion: policy/v1 kind: PodDisruptionBudget metadata: - name: network-node-pdb-{{ $node.name }} + name: {{ $.Release.Name }}-node-pdb-{{ $node.name }} namespace: {{ default $.Release.Namespace $.Values.global.namespaceOverride }} labels: fullstack.hedera.com/type: pod-disruption-budget diff --git a/charts/hedera-network/templates/proxy/envoy-deployment.yaml b/charts/hedera-network/templates/proxy/envoy-deployment.yaml index ce89b6471..ffba1639e 100644 --- a/charts/hedera-network/templates/proxy/envoy-deployment.yaml +++ b/charts/hedera-network/templates/proxy/envoy-deployment.yaml @@ -6,7 +6,7 @@ apiVersion: apps/v1 kind: Deployment metadata: - name: envoy-proxy-{{ $node.name }} + name: {{ $.Release.Name }}-envoy-proxy-{{ $node.name }} namespace: {{ default $.Release.Namespace $.Values.global.namespaceOverride }} spec: replicas: 1 @@ -38,7 +38,7 @@ spec: volumes: - name: config-volume configMap: - name: envoy-proxy-cm-{{ $node.name }} + name: {{ $.Release.Name }}-envoy-proxy-cm-{{ $node.name }} containers: - name: {{ default $defaults.nameOverride $envoyProxy.nameOverride }} image: {{ include "fullstack.container.image" (dict "image" $envoyProxy.image "Chart" $.Chart "defaults" $defaults ) }} diff --git a/charts/hedera-network/templates/proxy/haproxy-deployment.yaml b/charts/hedera-network/templates/proxy/haproxy-deployment.yaml index 198b7a273..8c01cbc52 100644 --- a/charts/hedera-network/templates/proxy/haproxy-deployment.yaml +++ b/charts/hedera-network/templates/proxy/haproxy-deployment.yaml @@ -6,7 +6,7 @@ apiVersion: apps/v1 kind: Deployment metadata: - name: haproxy-{{ $node.name }} + name: {{ $.Release.Name }}-haproxy-{{ $node.name }} namespace: {{ default $.Release.Namespace $.Values.global.namespaceOverride }} spec: replicas: 1 @@ -38,10 +38,10 @@ spec: volumes: - name: haproxy-config-volume configMap: - name: haproxy-cm-{{ $node.name }} + name: {{ $.Release.Name }}-haproxy-cm-{{ $node.name }} - name: haproxy-ofac-volume configMap: - name: haproxy-ofac-cm + name: {{ $.Release.Name }}-haproxy-ofac-cm containers: - name: {{ default $defaults.nameOverride $haproxy.nameOverride }} image: {{ include "fullstack.container.image" (dict "image" $haproxy.image "Chart" $.Chart "defaults" $defaults ) }} diff --git a/charts/hedera-network/templates/rbac/pod-monitor.yaml b/charts/hedera-network/templates/rbac/pod-monitor.yaml index d6a2ec5e7..3d710cd4f 100644 --- a/charts/hedera-network/templates/rbac/pod-monitor.yaml +++ b/charts/hedera-network/templates/rbac/pod-monitor.yaml @@ -2,17 +2,17 @@ apiVersion: v1 kind: ServiceAccount metadata: - name: pod-monitor + name: {{ $.Release.Name }}-pod-monitor namespace: {{ default $.Release.Namespace $.Values.global.namespaceOverride }} --- apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding metadata: - name: pod-monitor-role-binding + name: {{ $.Release.Name }}-pod-monitor-role-binding namespace: {{ default $.Release.Namespace $.Values.global.namespaceOverride }} subjects: - kind: ServiceAccount - name: pod-monitor + name: {{ $.Release.Name}}-pod-monitor namespace: {{ default $.Release.Namespace $.Values.global.namespaceOverride }} roleRef: kind: ClusterRole diff --git a/charts/hedera-network/templates/secrets/backup-uploder-secrets.yaml b/charts/hedera-network/templates/secrets/backup-uploder-secrets.yaml index 04f14dae7..84144edba 100644 --- a/charts/hedera-network/templates/secrets/backup-uploder-secrets.yaml +++ b/charts/hedera-network/templates/secrets/backup-uploder-secrets.yaml @@ -1,7 +1,7 @@ apiVersion: v1 kind: Secret metadata: - name: backup-uploader-secrets + name: {{ $.Release.Name }}-backup-uploader-secrets namespace: {{ default $.Release.Namespace $.Values.global.namespaceOverride }} type: Opaque data: diff --git a/charts/hedera-network/templates/secrets/otel-collector-secrets.yaml b/charts/hedera-network/templates/secrets/otel-collector-secrets.yaml index 13e65c2f2..20d152bf4 100644 --- a/charts/hedera-network/templates/secrets/otel-collector-secrets.yaml +++ b/charts/hedera-network/templates/secrets/otel-collector-secrets.yaml @@ -1,7 +1,7 @@ apiVersion: v1 kind: Secret metadata: - name: otel-collector-secrets + name: {{ $.Release.Name }}-otel-collector-secrets namespace: {{ default $.Release.Namespace $.Values.global.namespaceOverride }} type: Opaque data: diff --git a/charts/hedera-network/templates/secrets/uploder-mirror-secrets.yaml b/charts/hedera-network/templates/secrets/uploder-mirror-secrets.yaml index cc6c11371..a08b0ca30 100644 --- a/charts/hedera-network/templates/secrets/uploder-mirror-secrets.yaml +++ b/charts/hedera-network/templates/secrets/uploder-mirror-secrets.yaml @@ -6,7 +6,7 @@ apiVersion: v1 kind: Secret metadata: - name: minio-secrets + name: {{ $.Release.Name }}-minio-secrets namespace: {{ default $.Release.Namespace $.Values.global.namespaceOverride }} type: Opaque data: diff --git a/charts/hedera-network/templates/services/envoy-svc.yaml b/charts/hedera-network/templates/services/envoy-svc.yaml index 082103dda..c75dba0da 100644 --- a/charts/hedera-network/templates/services/envoy-svc.yaml +++ b/charts/hedera-network/templates/services/envoy-svc.yaml @@ -6,7 +6,7 @@ apiVersion: v1 kind: Service metadata: - name: envoy-proxy-{{ $node.name }}-svc + name: {{ $.Release.Name }}-envoy-proxy-{{ $node.name }}-svc namespace: {{ default $.Release.Namespace $.Values.global.namespaceOverride }} labels: fullstack.hedera.com/type: envoy-proxy-svc diff --git a/charts/hedera-network/templates/services/haproxy-svc.yaml b/charts/hedera-network/templates/services/haproxy-svc.yaml index 248083a6b..f7595bd5d 100644 --- a/charts/hedera-network/templates/services/haproxy-svc.yaml +++ b/charts/hedera-network/templates/services/haproxy-svc.yaml @@ -6,7 +6,7 @@ apiVersion: v1 kind: Service metadata: - name: haproxy-{{ $node.name }}-svc + name: {{ $.Release.Name }}-haproxy-{{ $node.name }}-svc namespace: {{ default $.Release.Namespace $.Values.global.namespaceOverride }} labels: fullstack.hedera.com/type: haproxy-svc diff --git a/charts/hedera-network/templates/services/network-node-svc.yaml b/charts/hedera-network/templates/services/network-node-svc.yaml index 4fa908d2f..f26c2f604 100644 --- a/charts/hedera-network/templates/services/network-node-svc.yaml +++ b/charts/hedera-network/templates/services/network-node-svc.yaml @@ -3,7 +3,7 @@ apiVersion: v1 kind: Service metadata: - name: network-{{ $nodeConfig.name }}-svc + name: {{ $.Release.Name }}-network-{{ $nodeConfig.name }}-svc namespace: {{ default $.Release.Namespace $.Values.global.namespaceOverride }} labels: fullstack.hedera.com/type: network-node-svc diff --git a/charts/hedera-network/templates/sidecars/_backup-uploader.tpl b/charts/hedera-network/templates/sidecars/_backup-uploader.tpl index 362dde348..d1850a460 100644 --- a/charts/hedera-network/templates/sidecars/_backup-uploader.tpl +++ b/charts/hedera-network/templates/sidecars/_backup-uploader.tpl @@ -2,6 +2,7 @@ {{- $backupUploader := .backupUploader | required "context must include 'backupUploader'!" -}} {{- $defaults := .defaults | required "context must include 'defaults'!" }} {{- $chart := .chart | required "context must include 'chart'!" -}} +{{- $release := .release | required "context must include 'release'!" -}} - name: {{ default "backup-uploader" $backupUploader.nameOverride }} image: {{ include "fullstack.container.image" (dict "image" $backupUploader.image "Chart" $chart "defaults" $defaults) }} imagePullPolicy: {{ include "fullstack.images.pullPolicy" (dict "image" $backupUploader.image "defaults" $defaults) }} @@ -16,7 +17,7 @@ value: {{ default $defaults.config.backupBucket ($backupUploader.config).backupBucket | quote }} envFrom: - secretRef: - name: backup-uploader-secrets + name: {{ $release.Name }}-backup-uploader-secrets {{- with $backupUploader.resources }} resources: {{- toYaml . | nindent 4 }} diff --git a/charts/hedera-network/templates/sidecars/_sidecars.tpl b/charts/hedera-network/templates/sidecars/_sidecars.tpl index 4117723c3..67cea624f 100644 --- a/charts/hedera-network/templates/sidecars/_sidecars.tpl +++ b/charts/hedera-network/templates/sidecars/_sidecars.tpl @@ -7,6 +7,7 @@ {{- $otelCollector := .otelCollector | required "context must include 'otelCollector'!" -}} {{- $cloud := .cloud | required "context must include 'cloud'!" -}} {{- $chart := .chart | required "context must include 'chart'!" -}} +{{- $release := .release | required "context must include 'Release'!" -}} {{- $nodeId := .node.accountId -}} {{- $minioserver := .minioserver -}} {{- if default $defaults.sidecars.recordStreamUploader.enable $recordStream.enable | eq "true" }} @@ -26,7 +27,7 @@ {{- end }} {{- if default $defaults.sidecars.backupUploader.enable $backupUploader.enable | eq "true" }} # Sidecar: Backup Uploader - {{- $data := dict "backupUploader" $backupUploader "cloud" $cloud "chart" $chart "defaults" $defaults.sidecars.backupUploader -}} + {{- $data := dict "backupUploader" $backupUploader "cloud" $cloud "chart" $chart "defaults" $defaults.sidecars.backupUploader "release" $release -}} {{ include "fullstack.sidecars.backupUploader " $data | nindent 0 }} {{- end }} {{- if default $defaults.sidecars.otelCollector.enable $otelCollector.enable | eq "true" }} diff --git a/charts/hedera-network/templates/telemetry/prometheus-svc-monitor.yaml b/charts/hedera-network/templates/telemetry/prometheus-svc-monitor.yaml index f990545ea..c89d4676c 100644 --- a/charts/hedera-network/templates/telemetry/prometheus-svc-monitor.yaml +++ b/charts/hedera-network/templates/telemetry/prometheus-svc-monitor.yaml @@ -2,7 +2,7 @@ apiVersion: monitoring.coreos.com/v1 kind: ServiceMonitor metadata: - name: network-node-monitor + name: {{ $.Release.Name }}-network-node-monitor namespace: {{ default $.Release.Namespace $.Values.global.namespaceOverride }} labels: fullstack.hedera.com/type: network-node-svc-monitor diff --git a/charts/hedera-network/templates/tests/test-deployment.yaml b/charts/hedera-network/templates/tests/test-deployment.yaml index 0eab70989..9a76ba0d2 100644 --- a/charts/hedera-network/templates/tests/test-deployment.yaml +++ b/charts/hedera-network/templates/tests/test-deployment.yaml @@ -1,13 +1,13 @@ apiVersion: v1 kind: Pod metadata: - name: "network-test" + name: {{ $.Release.Name }}-network-test annotations: "helm.sh/hook": test # add hook-failed once bug is fixed that prevents it from getting logs "helm.sh/hook-delete-policy": before-hook-creation spec: - serviceAccountName: pod-monitor + serviceAccountName: {{ $.Release.Name}}-pod-monitor {{- if $.Values.deployment.nodeSelector }} nodeSelector: {{- $.Values.deployment.nodeSelector | toYaml | nindent 8 }} @@ -27,7 +27,7 @@ spec: volumes: - name: test-volume configMap: - name: test-cm + name: {{ $.Release.Name}}-test-cm defaultMode: 0777 # we need the test files to be executable containers: {{- $tester := $.Values.tester }} @@ -54,6 +54,8 @@ spec: valueFrom: fieldRef: fieldPath: metadata.namespace + - name: RELEASE_NAME + value: {{ $.Release.Name }} command: - "/bin/bash" - "-c" diff --git a/charts/hedera-network/tests/README.md b/charts/hedera-network/tests/README.md index 7da4919d4..deee1333d 100644 --- a/charts/hedera-network/tests/README.md +++ b/charts/hedera-network/tests/README.md @@ -17,7 +17,7 @@ you have the network deployed already. ``` - once the `network-test` container is running, use another terminal to shell into it using command below ``` - kubectl exec -it network-test -- bash + kubectl exec -it "${RELEASE_NAME}-network-test" -- bash # where RELEASE_NAME is helm chart release name ``` - Then you can run the test inside the container to debug ``` diff --git a/charts/hedera-network/tests/env.sh b/charts/hedera-network/tests/env.sh index 050672dce..b5c1cf39a 100755 --- a/charts/hedera-network/tests/env.sh +++ b/charts/hedera-network/tests/env.sh @@ -21,6 +21,7 @@ TESTS_DIR="${TESTS_DIR:-${CUR_DIR}}" TOTAL_NODES="${TOTAL_NODES:-3}" USER="${USER:-changeme}" NAMESPACE="${NAMESPACE:-fst-${USER}}" +RELEASE_NAME="${RELEASE_NAME:-fst}" LOG_DIR="${LOG_DIR:-${CUR_DIR}/logs}" LOG_FILE="${LOG_FILE:-helm-test.log}" OUTPUT_LOG="${OUTPUT_LOG:-false}" @@ -28,6 +29,7 @@ OUTPUT_LOG="${OUTPUT_LOG:-false}" echo "--------------------------Env Setup: fullstack-testing Helm Test------------------------------------------------" echo "NAMESPACE: ${NAMESPACE}" +echo "RELEASE_NAME: ${RELEASE_NAME}" echo "ENV_FILE: ${ENV_FILE}" echo "BATS_HOME: ${BATS_HOME}" echo "TESTS_DIR: ${TESTS_DIR}" diff --git a/charts/hedera-network/tests/env.template b/charts/hedera-network/tests/env.template index 5ed4d1fb1..5cdfb56a0 100644 --- a/charts/hedera-network/tests/env.template +++ b/charts/hedera-network/tests/env.template @@ -1,5 +1,6 @@ USER="${USER:-changeme}" NAMESPACE="${NAMESPACE:-fst-${USER}}" +RELEASE_NAME="${RELEASE_NAME:-fst}" TOTAL_NODES=3 diff --git a/charts/hedera-network/tests/helper.sh b/charts/hedera-network/tests/helper.sh index b86255dfa..6b6b336b6 100644 --- a/charts/hedera-network/tests/helper.sh +++ b/charts/hedera-network/tests/helper.sh @@ -83,7 +83,7 @@ function check_test_status() { function get_config_val() { local config_path=$1 log_debug "Get config command: helm get values fst -a -n ${NAMESPACE} | yq '${config_path}'" - ret=$(helm get values fst -a -n "${NAMESPACE}" | yq "${config_path}" ) + ret=$(helm get values ${RELEASE_NAME} -a -n "${NAMESPACE}" | yq "${config_path}" ) echo "${ret}" log_debug "${config_path} => ${ret}" } diff --git a/charts/hedera-network/tests/test_gateway_api_deployment.bats b/charts/hedera-network/tests/test_gateway_api_deployment.bats index 3db9fe4cb..b57450f1e 100644 --- a/charts/hedera-network/tests/test_gateway_api_deployment.bats +++ b/charts/hedera-network/tests/test_gateway_api_deployment.bats @@ -22,7 +22,7 @@ setup() { local node_name=$(get_pod_label "${pod}" "fullstack.hedera.com/node-name") [[ -z "${node_name}" ]] && test_status="${FAIL}" && break - local route_name="envoy-grpc-web-route-${node_name}" + local route_name="${RELEASE_NAME}-envoy-grpc-web-route-${node_name}" local is_enabled=$(is_enabled_for_node "${node_name}" ".envoyProxy.enable") if [ "${is_enabled}" = "TRUE" ]; then log_debug "EnvoyProxy enabled for node '${node_name}'" @@ -61,7 +61,7 @@ setup() { local node_name=$(get_pod_label "${pod}" "fullstack.hedera.com/node-name") [[ -z "${node_name}" ]] && test_status="${FAIL}" && break - local route_name="haproxy-grpc-route-${node_name}" + local route_name="${RELEASE_NAME}-haproxy-grpc-route-${node_name}" local is_enabled=$(is_enabled_for_node "${node_name}" ".haproxy.enable") if [ "${is_enabled}" = "TRUE" ]; then log_debug "HAProxy enabled for node '${node_name}'" diff --git a/dev/Makefile b/dev/Makefile index 0509b8cc8..f37e21137 100644 --- a/dev/Makefile +++ b/dev/Makefile @@ -221,13 +221,13 @@ undeploy-minio-operator: ######################################### Helm Chart Test ################################# .PHONY: helm-test helm-test: - source "${SCRIPTS_DIR}/main.sh" && run_helm_chart_tests "network-test" || exit 1 + source "${SCRIPTS_DIR}/main.sh" && run_helm_chart_tests || exit 1 .PHONY: destroy-test-container destroy-test-container: echo "" && \ echo ">> Deleting test container..." && \ - kubectl delete pod network-test -n "${NAMESPACE}" || true + kubectl delete pod "${RELEASE_NAME}-network-test" -n "${NAMESPACE}" || true ######################################### CI ################################# .PHONY: local-kubectl-bats diff --git a/dev/scripts/env.sh b/dev/scripts/env.sh index ba7b11325..e41026331 100644 --- a/dev/scripts/env.sh +++ b/dev/scripts/env.sh @@ -9,6 +9,19 @@ readonly TMP_DIR="${SCRIPT_DIR}/../temp" readonly SETUP_CHART_DIR="${SCRIPT_DIR}/../../charts/fullstack-cluster-setup" readonly CHART_DIR="${SCRIPT_DIR}/../../charts/hedera-network" +USER="${USER:-changeme}" +CLUSTER_NAME="${CLUSTER_NAME:-fst}" +NAMESPACE="${NAMESPACE:-fst-${USER}}" +RELEASE_NAME="${RELEASE_NAME:-fst}" +NMT_VERSION=v2.0.0-alpha.0 +PLATFORM_VERSION=v0.39.1 + +POD_MONITOR_ROLE="${POD_MONITOR_ROLE:-pod-monitor-role}" +GATEWAY_CLASS_NAME="${GATEWAY_CLASS_NAME:-fst-gateway-class}" + +#NODE_NAMES=(node0 node1 node2 node3) +NODE_NAMES=(node0) + POD_MONITOR_ROLE="${POD_MONITOR_ROLE:-pod-monitor-role}" GATEWAY_CLASS_NAME="${GATEWAY_CLASS_NAME:-fst-gateway-class}" @@ -91,7 +104,7 @@ setup echo "--------------------------Env Setup: fullstack-testing ------------------------------------------------" echo "CLUSTER_NAME: ${CLUSTER_NAME}" -echo "RELEASE_NAME: ${HELM_RELEASE_NAME}" +echo "RELEASE_NAME: ${RELEASE_NAME}" echo "USER: ${USER}" echo "NAMESPACE: ${NAMESPACE}" echo "SCRIPT_DIR: ${SCRIPT_DIR}" diff --git a/dev/scripts/main.sh b/dev/scripts/main.sh index 08047150a..f7ed5e0f2 100644 --- a/dev/scripts/main.sh +++ b/dev/scripts/main.sh @@ -92,7 +92,7 @@ function install_chart() { echo "SCRIPT_NAME: ${node_setup_script}" echo "Additional values: ${CHART_VALUES_FILES}" echo "-----------------------------------------------------------------------------------------------------" - local count=$(helm list -q -n "${NAMESPACE}" | grep -c "${HELM_RELEASE_NAME}") + local count=$(helm list -q -n "${NAMESPACE}" | grep -c "${RELEASE_NAME}") if [[ $count -eq 0 ]]; then if [ "${node_setup_script}" = "nmt-install.sh" ]; then nmt_install @@ -100,72 +100,77 @@ function install_chart() { direct_install fi else - echo "${HELM_RELEASE_NAME} is already installed" + echo "${RELEASE_NAME} is already installed" fi log_time "install_chart" } function uninstall_chart() { - [[ -z "${HELM_RELEASE_NAME}" ]] && echo "ERROR: [uninstall_chart] Helm release name is required" && return 1 + [[ -z "${RELEASE_NAME}" ]] && echo "ERROR: [uninstall_chart] Helm release name is required" && return 1 echo "" - local count=$(helm list -q -n "${NAMESPACE}" | grep -c "${HELM_RELEASE_NAME}") + local count=$(helm list -q -n "${NAMESPACE}" | grep -c "${RELEASE_NAME}") if [[ $count -ne 0 ]]; then - echo "Uninstalling helm chart ${HELM_RELEASE_NAME} in namespace ${NAMESPACE}... " + echo "Uninstalling helm chart ${RELEASE_NAME} in namespace ${NAMESPACE}... " echo "-----------------------------------------------------------------------------------------------------" - helm uninstall -n "${NAMESPACE}" "${HELM_RELEASE_NAME}" + helm uninstall -n "${NAMESPACE}" "${RELEASE_NAME}" sleep 10 - echo "Uninstalled helm chart ${HELM_RELEASE_NAME} in namespace ${NAMESPACE}" + echo "Uninstalled helm chart ${RELEASE_NAME} in namespace ${NAMESPACE}" else - echo "Helm chart '${HELM_RELEASE_NAME}' not found in namespace ${NAMESPACE}. Nothing to uninstall. " + echo "Helm chart '${RELEASE_NAME}' not found in namespace ${NAMESPACE}. Nothing to uninstall. " fi # it is needed for GKE deployment local has_secret - has_secret=$(kubectl get secret | grep -c "sh.helm.release.v1.${HELM_RELEASE_NAME}.*") + has_secret=$(kubectl get secret | grep -c "sh.helm.release.v1.${RELEASE_NAME}.*") if [[ $has_secret ]]; then - kubectl delete secret "sh.helm.release.v1.${HELM_RELEASE_NAME}.v1" || true + kubectl delete secret "sh.helm.release.v1.${RELEASE_NAME}.v1" || true + fi + + local has_postgres_pvc + has_postgres_pvc=$(kubectl get pvc --no-headers -l app.kubernetes.io/component=postgresql,app.kubernetes.io/name=postgres,app.kubernetes.io/instance="${RELEASE_NAME}" | wc -l) + if [[ $has_postgres_pvc ]]; then + kubectl delete pvc -l app.kubernetes.io/component=postgresql,app.kubernetes.io/name=postgres,app.kubernetes.io/instance="${RELEASE_NAME}" fi log_time "uninstall_chart" } function nmt_install() { - [[ -z "${HELM_RELEASE_NAME}" ]] && echo "ERROR: [nmt_install] Helm release name is required" && return 1 + [[ -z "${RELEASE_NAME}" ]] && echo "ERROR: [nmt_install] Helm release name is required" && return 1 [[ -z "${NAMESPACE}" ]] && echo "ERROR: [nmt_install] Namespace name is required" && return 1 if [[ -z "${CHART_VALUES_FILES}" ]]; then - helm install "${HELM_RELEASE_NAME}" -n "${NAMESPACE}" "${CHART_DIR}" --set defaults.root.image.repository=hashgraph/full-stack-testing/ubi8-init-dind + helm install "${RELEASE_NAME}" -n "${NAMESPACE}" "${CHART_DIR}" --set defaults.root.image.repository=hashgraph/full-stack-testing/ubi8-init-dind else - helm install "${HELM_RELEASE_NAME}" -n "${NAMESPACE}" "${CHART_DIR}" -f "${CHART_DIR}/values.yaml" --values "${CHART_VALUES_FILES}" --set defaults.root.image.repository=hashgraph/full-stack-testing/ubi8-init-dind + helm install "${RELEASE_NAME}" -n "${NAMESPACE}" "${CHART_DIR}" -f "${CHART_DIR}/values.yaml" --values "${CHART_VALUES_FILES}" --set defaults.root.image.repository=hashgraph/full-stack-testing/ubi8-init-dind fi } function direct_install() { - [[ -z "${HELM_RELEASE_NAME}" ]] && echo "ERROR: [direct_install] Helm release name is required" && return 1 + [[ -z "${RELEASE_NAME}" ]] && echo "ERROR: [direct_install] Helm release name is required" && return 1 [[ -z "${NAMESPACE}" ]] && echo "ERROR: [direct_install] Namespace name is required" && return 1 if [[ -z "${CHART_VALUES_FILES}" ]]; then - helm install "${HELM_RELEASE_NAME}" -n "${NAMESPACE}" "${CHART_DIR}" + helm install "${RELEASE_NAME}" -n "${NAMESPACE}" "${CHART_DIR}" else - helm install "${HELM_RELEASE_NAME}" -n "${NAMESPACE}" "${CHART_DIR}" -f "${CHART_DIR}/values.yaml" --values "${CHART_VALUES_FILES}" + helm install "${RELEASE_NAME}" -n "${NAMESPACE}" "${CHART_DIR}" -f "${CHART_DIR}/values.yaml" --values "${CHART_VALUES_FILES}" fi } function run_helm_chart_tests() { - [[ -z "${HELM_RELEASE_NAME}" ]] && echo "ERROR: [run_helm_chart_tests] Helm release name is required" && return 1 + [[ -z "${RELEASE_NAME}" ]] && echo "ERROR: [run_helm_chart_tests] Helm release name is required" && return 1 setup_kubectl_context - local test_name=$1 # pod name in the tests/test-deployment.yaml file - [[ -z "${test_name}" ]] && echo "ERROR: test name is required" && return 1 + local test_name="${RELEASE_NAME}-network-test" # pod name in the tests/test-deployment.yaml file echo "" - echo "Running helm chart tests (takes ~5m, timeout 15m)... " + echo "Running helm chart tests $test_name (takes ~5m, timeout 15m)... " echo "-----------------------------------------------------------------------------------------------------" - helm test "${HELM_RELEASE_NAME}" --filter name="${test_name}" --timeout 15m + helm test "${RELEASE_NAME}" --filter name="${test_name}" --timeout 15m local test_status=$(kubectl get pod "${test_name}" -o jsonpath='{.status.phase}' | xargs) echo "Helm test status: ${test_status}" diff --git a/dev/scripts/template.env b/dev/scripts/template.env index bbeb1109e..2918787ed 100644 --- a/dev/scripts/template.env +++ b/dev/scripts/template.env @@ -1,7 +1,7 @@ USER="${USER:-changeme}" CLUSTER_NAME="${CLUSTER_NAME:-fst}" NAMESPACE="${NAMESPACE:-fst-${USER}}" -HELM_RELEASE_NAME="${RELEASE_NAME:-fst}" +RELEASE_NAME="${RELEASE_NAME:-fst}" NMT_VERSION=v2.0.0-alpha.0 PLATFORM_VERSION=v0.39.1 From d9009b802e742134b23c04dfbbd3154bd30f55cc Mon Sep 17 00:00:00 2001 From: Lenin Mehedy Date: Mon, 9 Oct 2023 09:46:43 +1100 Subject: [PATCH 2/2] fix: use RELEASE_NAME in node setup and start scripts Signed-off-by: Lenin Mehedy --- dev/scripts/direct-install.sh | 6 +++--- dev/scripts/helper.sh | 15 ++++++++------- dev/scripts/nmt-install.sh | 6 +++--- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/dev/scripts/direct-install.sh b/dev/scripts/direct-install.sh index c4841619d..71d2f0829 100644 --- a/dev/scripts/direct-install.sh +++ b/dev/scripts/direct-install.sh @@ -49,7 +49,7 @@ function setup_node_all() { local node_name for node_name in "${NODE_NAMES[@]}"; do - local pod="network-${node_name}-0" # pod name + local pod="${RELEASE_NAME}-network-${node_name}-0" # pod name create_hapi_directories "${pod}" || return "${EX_ERR}" copy_platform "${pod}" || return "${EX_ERR}" @@ -85,7 +85,7 @@ function start_node_all() { local node_name for node_name in "${NODE_NAMES[@]}"; do - local pod="network-${node_name}-0" # pod name + local pod="${RELEASE_NAME}-network-${node_name}-0" # pod name start_service "${pod}" || return "${EX_ERR}" log_time "start_node" done @@ -106,7 +106,7 @@ function stop_node_all() { local node_name for node_name in "${NODE_NAMES[@]}"; do - local pod="network-${node_name}-0" # pod name + local pod="${RELEASE_NAME}-network-${node_name}-0" # pod name stop_service "${pod}" || return "${EX_ERR}" log_time "stop_node" done diff --git a/dev/scripts/helper.sh b/dev/scripts/helper.sh index 14fde29f5..880b61f9a 100755 --- a/dev/scripts/helper.sh +++ b/dev/scripts/helper.sh @@ -20,6 +20,7 @@ readonly HGCAPP_DIR="/opt/hgcapp" readonly NMT_DIR="${HGCAPP_DIR}/node-mgmt-tools" readonly HAPI_PATH="${HGCAPP_DIR}/services-hedera/HapiApp2.0" readonly HEDERA_HOME_DIR="/home/hedera" +readonly RELEASE_NAME="${RELEASE_NAME:-fst}" readonly NMT_VERSION="${NMT_VERSION:-v2.0.0-alpha.0}" readonly NMT_RELEASE_URL="https://api.github.com/repos/swirlds/swirlds-docker/releases/tags/${NMT_VERSION}" @@ -304,13 +305,13 @@ function prep_address_book() { # prepare address book lines local addresses=() for node_name in "${NODE_NAMES[@]}"; do - local pod="network-${node_name}-0" # pod name + local pod="${RELEASE_NAME}-network-${node_name}-0" # pod name local max_attempts=$MAX_ATTEMPTS local attempts=0 local status=$(kubectl get pod "${pod}" -o 'jsonpath={..status.conditions[?(@.type=="Ready")].status}') while [[ "${attempts}" -lt "${max_attempts}" && "${status}" != "True" ]]; do - kubectl get pod network-node0-0 -o 'jsonpath={..status.conditions[?(@.type=="Ready")]}' + kubectl get pod "${pod}" -o 'jsonpath={..status.conditions[?(@.type=="Ready")]}' echo "" echo "Waiting for the pod to be ready - ${pod}: Attempt# ${attempts}/${max_attempts} ..." @@ -327,8 +328,8 @@ function prep_address_book() { return "${EX_ERR}" fi - echo "${KCTL} get svc network-${node_name}-svc -o jsonpath='{.spec.clusterIP}' | xargs" - local SVC_IP=$("${KCTL}" get svc "network-${node_name}-svc" -o jsonpath='{.spec.clusterIP}' | xargs) + echo "${KCTL} get svc ${RELEASE_NAME}-network-${node_name}-svc -o jsonpath='{.spec.clusterIP}' | xargs" + local SVC_IP=$("${KCTL}" get svc "${RELEASE_NAME}-network-${node_name}-svc" -o jsonpath='{.spec.clusterIP}' | xargs) if [ -z "${SVC_IP}" ]; then echo "Could not detect service IP for ${pod}" return "${EX_ERR}" @@ -674,7 +675,7 @@ function verify_node_all() { local node_name for node_name in "${NODE_NAMES[@]}"; do - local pod="network-${node_name}-0" # pod name + local pod="${RELEASE_NAME}-network-${node_name}-0" # pod name verify_network_state "${pod}" "${MAX_ATTEMPTS}" || return "${EX_ERR}" log_time "verify_network_state" done @@ -694,7 +695,7 @@ function replace_keys_all() { local node_name for node_name in "${NODE_NAMES[@]}"; do - local pod="network-${node_name}-0" # pod name + local pod="${RELEASE_NAME}-network-${node_name}-0" # pod name copy_hedera_keys "${pod}" || return "${EX_ERR}" copy_node_keys "${node_name}" "${pod}" || return "${EX_ERR}" log_time "replace_keys" @@ -714,7 +715,7 @@ function reset_node_all() { local node_name for node_name in "${NODE_NAMES[@]}"; do - local pod="network-${node_name}-0" # pod name + local pod="${RELEASE_NAME}-network-${node_name}-0" # pod name reset_node "${pod}" || return "${EX_ERR}" log_time "reset_node" done diff --git a/dev/scripts/nmt-install.sh b/dev/scripts/nmt-install.sh index ff886fa83..75848466a 100644 --- a/dev/scripts/nmt-install.sh +++ b/dev/scripts/nmt-install.sh @@ -23,7 +23,7 @@ function setup_node_all() { local node_name for node_name in "${NODE_NAMES[@]}"; do - local pod="network-${node_name}-0" # pod name + local pod="${RELEASE_NAME}-network-${node_name}-0" # pod name reset_node "${pod}" copy_nmt "${pod}" || return "${EX_ERR}" copy_platform "${pod}" || return "${EX_ERR}" @@ -55,7 +55,7 @@ function start_node_all() { local node_name for node_name in "${NODE_NAMES[@]}"; do - local pod="network-${node_name}-0" # pod name + local pod="${RELEASE_NAME}-network-${node_name}-0" # pod name nmt_start "${pod}" || return "${EX_ERR}" log_time "start_node" done @@ -76,7 +76,7 @@ function stop_node_all() { local node_name for node_name in "${NODE_NAMES[@]}"; do - local pod="network-${node_name}-0" # pod name + local pod="${RELEASE_NAME}-network-${node_name}-0" # pod name nmt_stop "${pod}" || return "${EX_ERR}" log_time "stop_node" done