Skip to content

Commit 684c2be

Browse files
pengzhoumlrwinieskiBarkha Choithani
committed
CLD-740: Registry Secret Removal and Allow User to Provide Own Auth Secret (#115)
* CLD-740: remove registry secret and use registry secret name instead Co-authored-by: rwinieski <[email protected]> Co-authored-by: Barkha Choithani <[email protected]>
1 parent 5ee56d6 commit 684c2be

File tree

7 files changed

+102
-34
lines changed

7 files changed

+102
-34
lines changed

charts/templates/_helpers.tpl

+19
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,25 @@ Create the name of the service account to use
7676
{{- end }}
7777
{{- end }}
7878

79+
{{/*
80+
Get the name for secret that is used for auth and managed by the Chart.
81+
*/}}
82+
{{- define "marklogic.authSecretName" -}}
83+
{{- printf "%s-admin" (include "marklogic.fullname" .) }}
84+
{{- end }}
85+
86+
{{/*
87+
Get the secret name to mount to statefulSet.
88+
Use the auth.secretName value if set, otherwise use the name from marklogic.authSecretName.
89+
*/}}
90+
{{- define "marklogic.authSecretNameToMount" -}}
91+
{{- if .Values.auth.secretName }}
92+
{{- .Values.auth.secretName }}
93+
{{- else }}
94+
{{- include "marklogic.authSecretName" . }}
95+
{{- end }}
96+
{{- end }}
97+
7998
{{/*
8099
Fully qualified domain name
81100
*/}}

charts/templates/secret-registry.yaml

-13
This file was deleted.

charts/templates/secret.yaml

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
1+
{{- if not .Values.auth.secretName -}}
2+
{{- $adminUsername := (default (printf "admin-%s" (randAlphaNum 5)) .Values.auth.adminUsername) | b64enc | quote }}
13
{{- $adminPassword := (default (randAlphaNum 10) .Values.auth.adminPassword) | b64enc | quote }}
4+
{{- $walletPassword := (default (randAlphaNum 10) .Values.auth.adminPassword) | b64enc | quote }}
25
{{- $secret := (lookup "v1" "Secret" .Release.Namespace (printf "%s-admin" (include "marklogic.fullname" .))) }}
36
{{- if $secret }}
7+
{{- $adminUsername = index $secret.data "username" }}
48
{{- $adminPassword = index $secret.data "password" }}
9+
{{- $walletPassword = index $secret.data "wallet-password" }}
510
{{- end }}
611

712
apiVersion: v1
813
kind: Secret
914
metadata:
10-
name: {{ include "marklogic.fullname" . }}-admin
15+
name: {{ include "marklogic.authSecretName" . }}
1116
namespace: {{ .Release.Namespace }}
1217
labels:
1318
{{- include "marklogic.labels" . | nindent 4 }}
1419
type: Opaque
1520
data:
1621
password: {{ $adminPassword }}
17-
username: {{ .Values.auth.adminUsername | b64enc | quote }}
18-
wallet-password: {{ .Values.auth.walletPassword | b64enc | quote }}
19-
22+
username: {{ $adminUsername }}
23+
wallet-password: {{ $walletPassword }}
24+
{{- end }}

charts/templates/statefulset.yaml

+3-4
Original file line numberDiff line numberDiff line change
@@ -299,17 +299,16 @@ spec:
299299
{{- with .Values.nodeSelector }}
300300
nodeSelector: {{- toYaml . | nindent 8}}
301301
{{- end }}
302-
{{- if .Values.imagePullSecret }}
303-
imagePullSecrets:
304-
- name: {{ include "marklogic.fullname" . }}-registry
302+
{{- if .Values.imagePullSecrets }}
303+
imagePullSecrets: {{- toYaml .Values.imagePullSecrets | nindent 8 }}
305304
{{- end }}
306305
dnsConfig:
307306
searches:
308307
- {{ include "marklogic.headlessURL" . }}
309308
volumes:
310309
- name: mladmin-secrets
311310
secret:
312-
secretName: {{ include "marklogic.fullname" . }}-admin
311+
secretName: {{ include "marklogic.authSecretNameToMount" . }}
313312
{{- if .Values.logCollection.enabled }}
314313
- name: {{ include "marklogic.fullname" . }}-fb-config-map
315314
configMap:

charts/values.yaml

+16-10
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,10 @@ initContainerImage:
3737
tag: 7.87.0
3838
pullPolicy: IfNotPresent
3939

40-
# Configure the imagePullSecret to pull the image from private repository that requires credential
41-
imagePullSecret: {}
42-
## docker hub registry: https://index.docker.io/v1/
43-
# registry: "https://index.docker.io/v1/"
44-
# username: "your username"
45-
# password: "your password"
40+
# Configure the imagePullSecrets to pull the image from private repository that requires credential
41+
imagePullSecrets: []
42+
# - name: "your-secret-name-1"
43+
# - name: "your-secret-name-2"
4644

4745
# Marklogic pods' resource requests and limits
4846
# ref: https://kubernetes.io/docs/user-guide/compute-resources/
@@ -57,11 +55,19 @@ resources: {}
5755
nameOverride: ""
5856
fullnameOverride: ""
5957

60-
# Configure Marklogic Admin Username and Password
58+
# Configure Marklogic Admin Username and Password. Create a secret and specify the name via "secretName"
59+
# with the following keys:
60+
# * username
61+
# * password
62+
# * wallet-password
63+
#
64+
# If no secret is specified and the admin credentials are not provided, a secret will be automatically
65+
# generated with random admin and wallet passwords.
6166
auth:
62-
adminUsername: "admin"
63-
adminPassword: ""
64-
walletPassword: ""
67+
secretName: ""
68+
# adminUsername: "admin"
69+
# adminPassword: ""
70+
# walletPassword: ""
6571

6672
# Optionally install converters package on MarkLogic
6773
enableConverters: false

test/e2e/install_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,8 @@ func TestHelmInstall(t *testing.T) {
9595
assert.Equal(t, 10, len(password))
9696
usernameArr := secret.Data["username"]
9797
username := string(usernameArr[:])
98-
expectedUsername := "admin"
99-
// the username from secret expected to be "admin"
100-
assert.Equal(t, expectedUsername, username)
98+
// the random generated username should have length of 11"
99+
assert.Equal(t, 11, len(username))
101100

102101
tunnel8002 := k8s.NewTunnel(kubectlOptions, k8s.ResourceTypePod, podName, 8002, 8002)
103102
defer tunnel8002.Close()

test/template/admin_sec_templ_test.go

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package template_test
2+
3+
import (
4+
"path/filepath"
5+
"strings"
6+
"testing"
7+
8+
"github.com/stretchr/testify/require"
9+
appsv1 "k8s.io/api/apps/v1"
10+
11+
"github.com/gruntwork-io/terratest/modules/helm"
12+
"github.com/gruntwork-io/terratest/modules/k8s"
13+
"github.com/gruntwork-io/terratest/modules/random"
14+
)
15+
16+
func TestChartTemplateAdminSecret(t *testing.T) {
17+
18+
// Path to the helm chart we will test
19+
helmChartPath, err := filepath.Abs("../../charts")
20+
releaseName := "marklogic-admin-sec-test"
21+
t.Log(helmChartPath, releaseName)
22+
require.NoError(t, err)
23+
24+
// Set up the namespace; confirm that the template renders the expected value for the namespace.
25+
namespaceName := "marklogic-" + strings.ToLower(random.UniqueId())
26+
t.Logf("Namespace: %s\n", namespaceName)
27+
28+
// Setup the args for helm install
29+
options := &helm.Options{
30+
SetValues: map[string]string{
31+
"image.repository": "marklogicdb/marklogic-db",
32+
"image.tag": "latest",
33+
"persistence.enabled": "false",
34+
"containerSecurityContext.enabled": "true",
35+
"secretName": "marklogic-admin-sec-test-admin",
36+
},
37+
KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName),
38+
}
39+
40+
// render the tempate
41+
output := helm.RenderTemplate(t, options, helmChartPath, releaseName, []string{"templates/statefulset.yaml"})
42+
43+
var statefulset appsv1.StatefulSet
44+
helm.UnmarshalK8SYaml(t, output, &statefulset)
45+
46+
// Verify the name and namespace matches
47+
require.Equal(t, namespaceName, statefulset.Namespace)
48+
49+
// Verify the secret name is passed for MarkLogic admin credentials
50+
expectedAdminSecName := "marklogic-admin-sec-test-admin"
51+
actualAdminSecName := statefulset.Spec.Template.Spec.Volumes[0].Secret.SecretName
52+
require.Equal(t, actualAdminSecName, expectedAdminSecName)
53+
}

0 commit comments

Comments
 (0)