From e092b33ffdf701916671db89ff4847251656bb35 Mon Sep 17 00:00:00 2001 From: ArkBriar Date: Thu, 7 Mar 2024 18:17:57 +0800 Subject: [PATCH] fix & test: enrich test cases and fix bug found (#33) Signed-off-by: arkbriar --- charts/risingwave/templates/service.yaml | 11 +- .../templates/standalone/standalone-sts.yaml | 2 +- .../risingwave/tests/azblob_secret_test.yaml | 5 + charts/risingwave/tests/configmap_test.yaml | 73 +++++++++ charts/risingwave/tests/etcd_secret_test.yaml | 5 + charts/risingwave/tests/gcs_secret_test.yaml | 5 + .../risingwave/tests/minio_secret_test.yaml | 5 + charts/risingwave/tests/obs_secret_test.yaml | 5 + charts/risingwave/tests/oss_secret_test.yaml | 5 + charts/risingwave/tests/s3_secret_test.yaml | 5 + charts/risingwave/tests/secret_test.yaml | 78 +++++++++ charts/risingwave/tests/service_test.yaml | 148 ++++++++++++++++++ 12 files changed, 343 insertions(+), 4 deletions(-) create mode 100644 charts/risingwave/tests/configmap_test.yaml create mode 100644 charts/risingwave/tests/secret_test.yaml create mode 100644 charts/risingwave/tests/service_test.yaml diff --git a/charts/risingwave/templates/service.yaml b/charts/risingwave/templates/service.yaml index f085318..35dce8f 100644 --- a/charts/risingwave/templates/service.yaml +++ b/charts/risingwave/templates/service.yaml @@ -17,7 +17,7 @@ metadata: {{- if or $annotations .Values.service.annotations }} annotations: {{- if $annotations }} - {{ nindent 4 $annotations }} + {{- nindent 4 $annotations }} {{- end }} {{- if .Values.service.annotations }} {{- toYaml .Values.service.annotations | nindent 4 }} @@ -25,18 +25,23 @@ metadata: {{- end }} spec: type: {{ .Values.service.type }} + {{- if .Values.service.externalIPs }} externalIPs: {{- range .Values.service.externalIPs }} - {{ . }} {{- end }} + {{- end }} {{- if .Values.service.loadBalancerSourceRanges }} loadBalancerSourceRanges: - {{ toYaml .Values.service.loadBalancerSourceRanges | indent 2 }} + {{- range .Values.service.loadBalancerSourceRanges }} + - {{ . }} + {{- end }} {{- end }} externalTrafficPolicy: {{ .Values.service.externalTrafficPolicy }} sessionAffinity: {{ .Values.service.sessionAffinity }} {{- if .Values.service.sessionAffinityConfig }} - sessionAffinityConfig: {{- toYaml .Values.service.sessionAffinityConfig | indent 4 }} + sessionAffinityConfig: + {{- toYaml .Values.service.sessionAffinityConfig | nindent 4 }} {{- end }} selector: {{- include "risingwave.selectorLabels" . | nindent 4 }} diff --git a/charts/risingwave/templates/standalone/standalone-sts.yaml b/charts/risingwave/templates/standalone/standalone-sts.yaml index e6f68b3..9fbc27b 100644 --- a/charts/risingwave/templates/standalone/standalone-sts.yaml +++ b/charts/risingwave/templates/standalone/standalone-sts.yaml @@ -186,7 +186,7 @@ spec: {{- end }} {{- if .Values.metaStore.etcd.authentication.enabled }} - secretRef: - name: {{- include "risingwave.etcdCredentialsSecretName" . }} + name: {{ include "risingwave.etcdCredentialsSecretName" . }} {{- end }} env: # Disable auto region loading. Refer to the original source for more information. diff --git a/charts/risingwave/tests/azblob_secret_test.yaml b/charts/risingwave/tests/azblob_secret_test.yaml index 315f851..e7d3f49 100644 --- a/charts/risingwave/tests/azblob_secret_test.yaml +++ b/charts/risingwave/tests/azblob_secret_test.yaml @@ -88,6 +88,11 @@ tests: - isSubset: path: metadata.labels content: + helm.sh/chart: risingwave-0.0.1 + app.kubernetes.io/name: risingwave + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/version: 1.0.0 + app.kubernetes.io/instance: RELEASE-NAME LABEL: LABEL_V - exists: path: metadata.annotations diff --git a/charts/risingwave/tests/configmap_test.yaml b/charts/risingwave/tests/configmap_test.yaml new file mode 100644 index 0000000..9b227c0 --- /dev/null +++ b/charts/risingwave/tests/configmap_test.yaml @@ -0,0 +1,73 @@ +suite: Test config map +templates: +- templates/configmap.yaml +chart: + appVersion: 1.0.0 + version: 0.0.1 +tests: +- it: file should not render when using existing config map + set: + existingConfigMap: "CONFIG_MAP" + asserts: + - hasDocuments: + count: 0 +- it: file should contain the config map + set: + configuration: | + [example] + a = b + asserts: + - containsDocument: + apiVersion: v1 + kind: ConfigMap + - equal: + path: metadata.name + value: RELEASE-NAME-risingwave-configuration + - equal: + path: data + value: + risingwave.toml: | + [example] + a = b +- it: config map should contain the labels and annotations + set: + configuration: | + [example] + a = b + asserts: + - isSubset: + path: metadata.labels + content: + helm.sh/chart: risingwave-0.0.1 + app.kubernetes.io/name: risingwave + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/version: 1.0.0 + app.kubernetes.io/instance: RELEASE-NAME + - notExists: + path: metadata.annotations +- it: config map should reflect the common labels and annotations + set: + commonLabels: + LABEL: LABEL_V + commonAnnotations: + ANNOTATION: ANNOTATION_V + + configuration: | + [example] + a = b + asserts: + - isSubset: + path: metadata.labels + content: + helm.sh/chart: risingwave-0.0.1 + app.kubernetes.io/name: risingwave + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/version: 1.0.0 + app.kubernetes.io/instance: RELEASE-NAME + LABEL: LABEL_V + - exists: + path: metadata.annotations + - isSubset: + path: metadata.annotations + content: + ANNOTATION: ANNOTATION_V \ No newline at end of file diff --git a/charts/risingwave/tests/etcd_secret_test.yaml b/charts/risingwave/tests/etcd_secret_test.yaml index fec494f..09006c2 100644 --- a/charts/risingwave/tests/etcd_secret_test.yaml +++ b/charts/risingwave/tests/etcd_secret_test.yaml @@ -74,6 +74,11 @@ tests: - isSubset: path: metadata.labels content: + helm.sh/chart: risingwave-0.0.1 + app.kubernetes.io/name: risingwave + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/version: 1.0.0 + app.kubernetes.io/instance: RELEASE-NAME LABEL: LABEL_V - exists: path: metadata.annotations diff --git a/charts/risingwave/tests/gcs_secret_test.yaml b/charts/risingwave/tests/gcs_secret_test.yaml index 29fd02c..62f86a5 100644 --- a/charts/risingwave/tests/gcs_secret_test.yaml +++ b/charts/risingwave/tests/gcs_secret_test.yaml @@ -86,6 +86,11 @@ tests: - isSubset: path: metadata.labels content: + helm.sh/chart: risingwave-0.0.1 + app.kubernetes.io/name: risingwave + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/version: 1.0.0 + app.kubernetes.io/instance: RELEASE-NAME LABEL: LABEL_V - exists: path: metadata.annotations diff --git a/charts/risingwave/tests/minio_secret_test.yaml b/charts/risingwave/tests/minio_secret_test.yaml index a5b1740..4e65b0d 100644 --- a/charts/risingwave/tests/minio_secret_test.yaml +++ b/charts/risingwave/tests/minio_secret_test.yaml @@ -80,6 +80,11 @@ tests: - isSubset: path: metadata.labels content: + helm.sh/chart: risingwave-0.0.1 + app.kubernetes.io/name: risingwave + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/version: 1.0.0 + app.kubernetes.io/instance: RELEASE-NAME LABEL: LABEL_V - exists: path: metadata.annotations diff --git a/charts/risingwave/tests/obs_secret_test.yaml b/charts/risingwave/tests/obs_secret_test.yaml index 3481202..d91b0f2 100644 --- a/charts/risingwave/tests/obs_secret_test.yaml +++ b/charts/risingwave/tests/obs_secret_test.yaml @@ -88,6 +88,11 @@ tests: - isSubset: path: metadata.labels content: + helm.sh/chart: risingwave-0.0.1 + app.kubernetes.io/name: risingwave + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/version: 1.0.0 + app.kubernetes.io/instance: RELEASE-NAME LABEL: LABEL_V - exists: path: metadata.annotations diff --git a/charts/risingwave/tests/oss_secret_test.yaml b/charts/risingwave/tests/oss_secret_test.yaml index a6d04c8..2e6c481 100644 --- a/charts/risingwave/tests/oss_secret_test.yaml +++ b/charts/risingwave/tests/oss_secret_test.yaml @@ -88,6 +88,11 @@ tests: - isSubset: path: metadata.labels content: + helm.sh/chart: risingwave-0.0.1 + app.kubernetes.io/name: risingwave + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/version: 1.0.0 + app.kubernetes.io/instance: RELEASE-NAME LABEL: LABEL_V - exists: path: metadata.annotations diff --git a/charts/risingwave/tests/s3_secret_test.yaml b/charts/risingwave/tests/s3_secret_test.yaml index 68cfabd..0efd1ec 100644 --- a/charts/risingwave/tests/s3_secret_test.yaml +++ b/charts/risingwave/tests/s3_secret_test.yaml @@ -88,6 +88,11 @@ tests: - isSubset: path: metadata.labels content: + helm.sh/chart: risingwave-0.0.1 + app.kubernetes.io/name: risingwave + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/version: 1.0.0 + app.kubernetes.io/instance: RELEASE-NAME LABEL: LABEL_V - exists: path: metadata.annotations diff --git a/charts/risingwave/tests/secret_test.yaml b/charts/risingwave/tests/secret_test.yaml new file mode 100644 index 0000000..28d1277 --- /dev/null +++ b/charts/risingwave/tests/secret_test.yaml @@ -0,0 +1,78 @@ +suite: Test secret (authentication) +templates: +- templates/secret.yaml +chart: + appVersion: 1.0.0 + version: 0.0.1 +tests: +- it: file should always render + asserts: + - hasDocuments: + count: 1 + - containsDocument: + apiVersion: v1 + kind: Secret + - equal: + path: metadata.name + value: RELEASE-NAME-risingwave +- it: secret should contains labels and annotations + asserts: + - isSubset: + path: metadata.labels + content: + helm.sh/chart: risingwave-0.0.1 + app.kubernetes.io/name: risingwave + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/version: 1.0.0 + app.kubernetes.io/instance: RELEASE-NAME + - notExists: + path: metadata.annotations +- it: secret should reflect common labels and annotations + set: + commonLabels: + LABEL: LABEL_V + commonAnnotations: + ANNOTATION: ANNOTATION_V + asserts: + - isSubset: + path: metadata.labels + content: + helm.sh/chart: risingwave-0.0.1 + app.kubernetes.io/name: risingwave + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/version: 1.0.0 + app.kubernetes.io/instance: RELEASE-NAME + LABEL: LABEL_V + - exists: + path: metadata.annotations + - isSubset: + path: metadata.annotations + content: + ANNOTATION: ANNOTATION_V +- it: secret contains root user and random password by default + asserts: + - equal: + path: stringData.root-user + value: root + - equal: + path: stringData.root-password + value: "" + - notExists: + path: stringData.real-root-password +- it: secret must reflect root user and generate a random password for real root + set: + auth: + rootUser: ROOT_USER + rootPassword: ROOT_PASSWORD + asserts: + - equal: + path: stringData.root-user + value: ROOT_USER + - equal: + path: stringData.root-password + value: ROOT_PASSWORD + - exists: + path: stringData.real-root-password + - notEqual: + path: stringData.real-root-password + value: "" diff --git a/charts/risingwave/tests/service_test.yaml b/charts/risingwave/tests/service_test.yaml new file mode 100644 index 0000000..7a2bbee --- /dev/null +++ b/charts/risingwave/tests/service_test.yaml @@ -0,0 +1,148 @@ +suite: Test service +templates: +- templates/service.yaml +chart: + appVersion: 1.0.0 + version: 0.0.1 +tests: +- it: service should always render + asserts: + - hasDocuments: + count: 1 + - containsDocument: + apiVersion: v1 + kind: Service + - equal: + path: metadata.name + value: RELEASE-NAME-risingwave +- it: service should contains labels and annotations + asserts: + - isSubset: + path: metadata.labels + content: + helm.sh/chart: risingwave-0.0.1 + app.kubernetes.io/name: risingwave + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/version: 1.0.0 + app.kubernetes.io/instance: RELEASE-NAME + - notExists: + path: metadata.annotations +- it: service should reflect common labels and annotations + set: + commonLabels: + LABEL: LABEL_V + commonAnnotations: + ANNOTATION: ANNOTATION_V + asserts: + - isSubset: + path: metadata.labels + content: + helm.sh/chart: risingwave-0.0.1 + app.kubernetes.io/name: risingwave + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/version: 1.0.0 + app.kubernetes.io/instance: RELEASE-NAME + LABEL: LABEL_V + - exists: + path: metadata.annotations + - isSubset: + path: metadata.annotations + content: + ANNOTATION: ANNOTATION_V +- it: service should work by default + asserts: + - equal: + path: spec + value: + type: ClusterIP + externalTrafficPolicy: null + sessionAffinity: None + selector: + app.kubernetes.io/name: risingwave + app.kubernetes.io/instance: RELEASE-NAME + risingwave.risingwavelabs.com/component: frontend + ports: + - name: svc + port: 4567 + targetPort: svc +- it: service should reflect the options + set: + service: + type: LoadBalancer + port: 1234 + nodePort: 2345 + loadBalancerSourceRanges: + - 10.10.10.0/24 + externalIPs: + - 1.1.1.1 + externalTrafficPolicy: Local + sessionAffinity: ClientIP + sessionAffinityConfig: + clientIP: + timeoutSeconds: 300 + annotations: + ANNOTATION: ANNOTATION_V + labels: + LABEL: LABEL_V + asserts: + - equal: + path: spec + value: + type: LoadBalancer + externalTrafficPolicy: Local + sessionAffinity: ClientIP + sessionAffinityConfig: + clientIP: + timeoutSeconds: 300 + loadBalancerSourceRanges: + - 10.10.10.0/24 + externalIPs: + - 1.1.1.1 + selector: + app.kubernetes.io/name: risingwave + app.kubernetes.io/instance: RELEASE-NAME + risingwave.risingwavelabs.com/component: frontend + ports: + - name: svc + port: 1234 + targetPort: svc + nodePort: 2345 + - isSubset: + path: metadata.labels + content: + helm.sh/chart: risingwave-0.0.1 + app.kubernetes.io/name: risingwave + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/version: 1.0.0 + app.kubernetes.io/instance: RELEASE-NAME + LABEL: LABEL_V + - exists: + path: metadata.annotations + - isSubset: + path: metadata.annotations + content: + ANNOTATION: ANNOTATION_V +- it: service should select different pod and port for standalone mode + set: + standalone: + enabled: true + asserts: + - isSubset: + path: spec.selector + content: + risingwave.risingwavelabs.com/component: standalone + - equal: + path: spec.ports[0].targetPort + value: f-svc +- it: service should select different pod and port for compact mode + set: + compactMode: + enabled: true + asserts: + - isSubset: + path: spec.selector + content: + risingwave.risingwavelabs.com/component: compute + - equal: + path: spec.ports[0].targetPort + value: f-svc \ No newline at end of file