From 590455487297012b67144d330771ecdc2bc9cea0 Mon Sep 17 00:00:00 2001 From: Darcy Date: Fri, 13 Sep 2024 11:35:07 +0800 Subject: [PATCH] Fix the issue where database-secret and admin-secret overwrite each other. (#3184) * Fix the issue where database-secret and admin-secret overwrite each other. * Improve the test cases. --- .../amoro/templates/amoro-admin-secret.yaml | 28 ---------- ...database-secret.yaml => amoro-secret.yaml} | 11 ++-- ...ecret_test.yaml => amoro-secret_test.yaml} | 54 ++++++------------- 3 files changed, 24 insertions(+), 69 deletions(-) delete mode 100644 charts/amoro/templates/amoro-admin-secret.yaml rename charts/amoro/templates/{amoro-database-secret.yaml => amoro-secret.yaml} (82%) rename charts/amoro/tests/{amoro-database-secret_test.yaml => amoro-secret_test.yaml} (58%) diff --git a/charts/amoro/templates/amoro-admin-secret.yaml b/charts/amoro/templates/amoro-admin-secret.yaml deleted file mode 100644 index 5e83e005c8..0000000000 --- a/charts/amoro/templates/amoro-admin-secret.yaml +++ /dev/null @@ -1,28 +0,0 @@ -{{/* - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/}} - -apiVersion: v1 -kind: Secret -metadata: - name: {{ include "common.names.fullname" . }} - labels: - {{- include "amoro.labels" . | nindent 4 }} -type: Opaque -data: - # use helm set dashboard username and password - AdminUsername: {{ .Values.amoroConf.ams.adminUsername | b64enc | quote }} - AdminPassword: {{ .Values.amoroConf.ams.adminPassword | b64enc | quote }} \ No newline at end of file diff --git a/charts/amoro/templates/amoro-database-secret.yaml b/charts/amoro/templates/amoro-secret.yaml similarity index 82% rename from charts/amoro/templates/amoro-database-secret.yaml rename to charts/amoro/templates/amoro-secret.yaml index 9d1065b4ea..3beff332b9 100644 --- a/charts/amoro/templates/amoro-database-secret.yaml +++ b/charts/amoro/templates/amoro-secret.yaml @@ -15,7 +15,6 @@ limitations under the License. */}} - {{- if or (eq .Values.amoroConf.database.type "mysql") (eq .Values.amoroConf.database.type "postgres") }} apiVersion: v1 kind: Secret metadata: @@ -24,8 +23,12 @@ metadata: {{- include "amoro.labels" . | nindent 4 }} type: Opaque data: - # use helm set username + # use helm set dashboard username and password + AdminUsername: {{ .Values.amoroConf.ams.adminUsername | b64enc | quote }} + AdminPassword: {{ .Values.amoroConf.ams.adminPassword | b64enc | quote }} + + {{- if or (eq .Values.amoroConf.database.type "mysql") (eq .Values.amoroConf.database.type "postgres") }} + # use helm set database username and password DatabaseUsername: {{ .Values.amoroConf.database.username | b64enc | quote }} - # use helm set password DatabasePassword: {{ .Values.amoroConf.database.password | b64enc | quote }} -{{- end }} \ No newline at end of file + {{- end }} diff --git a/charts/amoro/tests/amoro-database-secret_test.yaml b/charts/amoro/tests/amoro-secret_test.yaml similarity index 58% rename from charts/amoro/tests/amoro-database-secret_test.yaml rename to charts/amoro/tests/amoro-secret_test.yaml index 186e30c1f3..844162660d 100644 --- a/charts/amoro/tests/amoro-database-secret_test.yaml +++ b/charts/amoro/tests/amoro-secret_test.yaml @@ -15,9 +15,9 @@ # limitations under the License. -suite: Test Amoro Database Secret +suite: Test Amoro Secret templates: - - amoro-database-secret.yaml + - amoro-secret.yaml chart: appVersion: 0.1.0 version: 0.6.0 @@ -28,59 +28,39 @@ tests: database: type: derby asserts: - - hasDocuments: - count: 0 - - it: Amoro database secret should exist if database type is set to mysql + - notExists: + path: data.DatabaseUsername + - notExists: + path: data.DatabasePassword + - it: Amoro database secret should reflect username and password if database type is set to mysql set: - fullnameOverride: test amoroConf: database: type: mysql username: "abc" password: "123" asserts: - - containsDocument: - kind: Secret - apiVersion: v1 - name: test - - hasDocuments: - count: 1 - - it: Amoro database secret should exist if database type is set to postgres + - equal: + path: data.DatabaseUsername + value: "abc" + decodeBase64: true + - equal: + path: data.DatabasePassword + value: "123" + decodeBase64: true + - it: Amoro database secret should reflect username and password if database type is set to postgres set: - fullnameOverride: test amoroConf: database: type: postgres username: "abc" password: "123" - asserts: - - containsDocument: - kind: Secret - apiVersion: v1 - name: test - - hasDocuments: - count: 1 - - it: Amoro database secret should reflect username if database type is set to mysql - set: - amoroConf: - database: - type: mysql - username: "abc" - password: "123" asserts: - equal: path: data.DatabaseUsername value: "abc" decodeBase64: true - - it: Amoro database secret should reflect password if database type is set to mysql - set: - amoroConf: - database: - type: mysql - username: "abc" - password: "123" - asserts: - equal: path: data.DatabasePassword value: "123" - decodeBase64: true \ No newline at end of file + decodeBase64: true