Skip to content

Commit 2b81bcd

Browse files
committed
changes based on CR
1 parent 0eb35d1 commit 2b81bcd

File tree

4 files changed

+42
-25
lines changed

4 files changed

+42
-25
lines changed

charts/templates/secret.yaml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
{{- $adminPassword := (randAlphaNum 10) | b64enc | quote }}
2-
{{- $secret := (lookup "v1" "Secret" .Release.Namespace .Release.Name ) }}
1+
{{- $adminPassword := (default (randAlphaNum 10) .Values.auth.adminPassword) | b64enc | quote }}
2+
{{- $secret := (lookup "v1" "Secret" .Release.Namespace (printf "%s-admin" (include "marklogic.fullname" .))) }}
33
{{- if $secret }}
44
{{- $adminPassword = index $secret.data "password" }}
5-
{{- end -}}
5+
{{- end }}
66

77
apiVersion: v1
88
kind: Secret
99
metadata:
10-
name: {{ include "marklogic.fullname" . }}
10+
name: {{ include "marklogic.fullname" . }}-admin
1111
namespace: {{ .Release.Namespace }}
1212
labels:
1313
{{- include "marklogic.labels" . | nindent 4 }}
14-
type: Opaque
14+
type: kubernetes.io/basic-auth
1515
data:
16-
{{- if .Values.auth.adminPassword }}
17-
marklogic-password: {{ .Values.auth.adminPassword | b64enc | quote }}
18-
{{- else }}
19-
marklogic-password: {{ $adminPassword }}
20-
{{- end }}
16+
password: {{ $adminPassword }}
17+
username: {{ .Values.auth.adminUsername | b64enc | quote }}
18+

charts/templates/statefulset.yaml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,15 @@ spec:
6767
- name: MARKLOGIC_GROUP
6868
value: {{ .Values.group.name }}
6969
- name: MARKLOGIC_ADMIN_USERNAME
70-
value: {{ .Values.auth.adminUsername | quote }}
70+
valueFrom:
71+
secretKeyRef:
72+
name: {{ include "marklogic.fullname" . }}-admin
73+
key: username
7174
- name: MARKLOGIC_ADMIN_PASSWORD
7275
valueFrom:
7376
secretKeyRef:
74-
name: {{ include "marklogic.fullname" . }}
75-
key: marklogic-password
77+
name: {{ include "marklogic.fullname" . }}-admin
78+
key: password
7679
- name: POD_NAME
7780
valueFrom:
7881
fieldRef:
@@ -93,12 +96,15 @@ spec:
9396
{{- end }}
9497
env:
9598
- name: MARKLOGIC_ADMIN_USERNAME
96-
value: {{ .Values.auth.adminUsername | quote }}
99+
valueFrom:
100+
secretKeyRef:
101+
name: {{ include "marklogic.fullname" . }}-admin
102+
key: username
97103
- name: MARKLOGIC_ADMIN_PASSWORD
98104
valueFrom:
99105
secretKeyRef:
100-
name: {{ include "marklogic.fullname" . }}
101-
key: marklogic-password
106+
name: {{ include "marklogic.fullname" . }}-admin
107+
key: password
102108
- name: MARKLOGIC_GROUP
103109
value: {{ .Values.group.name }}
104110
- name: POD_NAME

test/e2e/install_test.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,18 @@ func TestHelmInstall(t *testing.T) {
8686
},
8787
)
8888

89-
// testing generated Random Password
90-
secretName := releaseName + "-marklogic"
89+
t.Log("====Testing Generated Random Password====")
90+
secretName := releaseName + "-marklogic-admin"
9191
secret := k8s.GetSecret(t, kubectlOptions, secretName)
92-
username := "admin"
93-
passwordArr := secret.Data["marklogic-password"]
92+
passwordArr := secret.Data["password"]
9493
password := string(passwordArr[:])
9594
// the generated random password should have length of 10
9695
assert.Equal(t, 10, len(password))
96+
usernameArr := secret.Data["username"]
97+
username := string(usernameArr[:])
98+
expectedUsername := "admin"
99+
// the username from secret expected to be "admin"
100+
assert.Equal(t, expectedUsername, username)
97101

98102
tunnel8002 := k8s.NewTunnel(kubectlOptions, k8s.ResourceTypePod, podName, 8002, 8002)
99103
defer tunnel8002.Close()
@@ -109,7 +113,7 @@ func TestHelmInstall(t *testing.T) {
109113
// the generated password should be able to access the manage endpoint
110114
assert.Equal(t, 200, response.StatusCode)
111115

112-
// Verify no groups beyond enode were created/modified
116+
t.Log("====Verify no groups beyond enode were created/modified====")
113117
groupStatusEndpoint := fmt.Sprintf("http://%s/manage/v2/groups?format=json", tunnel8002.Endpoint())
114118
groupStatus := digestAuth.NewRequest(username, password, "GET", groupStatusEndpoint, "")
115119
t.Logf(`groupStatusEndpoint: %s`, groupStatusEndpoint)

test/e2e/upgrade_test.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
http_helper "github.com/gruntwork-io/terratest/modules/http-helper"
1414
"github.com/gruntwork-io/terratest/modules/k8s"
1515
"github.com/gruntwork-io/terratest/modules/random"
16+
"github.com/stretchr/testify/assert"
1617
)
1718

1819
func TestHelmUpgrade(t *testing.T) {
@@ -43,8 +44,6 @@ func TestHelmUpgrade(t *testing.T) {
4344
"replicaCount": "1",
4445
"image.repository": imageRepo,
4546
"image.tag": imageTag,
46-
"auth.adminUsername": "admin",
47-
"auth.adminPassword": "admin",
4847
"logCollection.enabled": "false",
4948
},
5049
}
@@ -58,15 +57,19 @@ func TestHelmUpgrade(t *testing.T) {
5857
releaseName := "test-upgrade"
5958
helm.Install(t, options, helmChartPath, releaseName)
6059

60+
// save the generated password from first installation
61+
secretName := releaseName + "-marklogic-admin"
62+
secret := k8s.GetSecret(t, kubectlOptions, secretName)
63+
passwordArr := secret.Data["password"]
64+
passwordAfterInstall := string(passwordArr[:])
65+
6166
newOptions := &helm.Options{
6267
KubectlOptions: kubectlOptions,
6368
SetValues: map[string]string{
6469
"persistence.enabled": "false",
6570
"replicaCount": "2",
6671
"image.repository": imageRepo,
6772
"image.tag": imageTag,
68-
"auth.adminUsername": "admin",
69-
"auth.adminPassword": "admin",
7073
"logCollection.enabled": "false",
7174
},
7275
}
@@ -96,4 +99,10 @@ func TestHelmUpgrade(t *testing.T) {
9699
return statusCode == 200
97100
},
98101
)
102+
103+
t.Log("====Test password in secret should not change after upgrade====")
104+
secret = k8s.GetSecret(t, kubectlOptions, secretName)
105+
passwordArr = secret.Data["password"]
106+
passwordAfterUpgrade := string(passwordArr[:])
107+
assert.Equal(t, passwordAfterUpgrade, passwordAfterInstall)
99108
}

0 commit comments

Comments
 (0)