Skip to content

Commit 035653d

Browse files
authored
Use upstream secret helper for MariaDB password (#382)
1 parent d0858e6 commit 035653d

6 files changed

+47
-57
lines changed

charts/yourls/Chart.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
apiVersion: v2
2-
version: 5.14.12
2+
version: 5.15.0
33
name: yourls
44
description: Your Own URL Shortener
55
appVersion: "1.9.2"
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
service:
2-
type: ClusterIP
3-
41
yourls:
52
password: "test-yourls"
63

74
mariadb:
85
auth:
96
rootPassword: "test-root"
107
password: "test-user"
8+
9+
service:
10+
type: ClusterIP
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
yourls:
2+
password: "test-yourls"
3+
4+
mariadb:
5+
auth:
6+
rootPassword: "test-root"
7+
password: "test-user"
8+
19
service:
210
type: ClusterIP
311

@@ -7,11 +15,3 @@ ingress:
715
extraHosts:
816
- name: "*.domain.tld"
917
path: /
10-
11-
yourls:
12-
password: "test-yourls"
13-
14-
mariadb:
15-
auth:
16-
rootPassword: "test-root"
17-
password: "test-user"
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
ingress:
2-
enabled: true
3-
tls: true
4-
5-
service:
6-
type: ClusterIP
7-
8-
metrics:
9-
enabled: true
10-
111
yourls:
122
password: "test-yourls"
133

144
mariadb:
155
auth:
166
rootPassword: "test-root"
177
password: "test-user"
8+
9+
service:
10+
type: ClusterIP
11+
12+
ingress:
13+
enabled: true
14+
tls: true
15+
16+
metrics:
17+
enabled: true

charts/yourls/templates/NOTES.txt

+17-20
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ To access your YOURLS site from outside the cluster follow the steps below:
3030

3131
1. Get the YOURLS URL and associate YOURLS hostname to your cluster external IP:
3232

33-
export CLUSTER_IP=$(minikube ip) # On Minikube. Use: `kubectl cluster-info` on others K8s clusters
34-
echo "YOURLS URL: http{{ if .Values.ingress.tls }}s{{ end }}://{{ .Values.ingress.hostname }}/"
35-
echo "$CLUSTER_IP {{ .Values.ingress.hostname }}" | sudo tee -a /etc/hosts
33+
export CLUSTER_IP=$(minikube ip) # On Minikube. Use: `kubectl cluster-info` on others K8s clusters
34+
echo "YOURLS URL: http{{ if .Values.ingress.tls }}s{{ end }}://{{ .Values.ingress.hostname }}/"
35+
echo "$CLUSTER_IP {{ .Values.ingress.hostname }}" | sudo tee -a /etc/hosts
3636

3737
{{- else }}
3838
{{- $port := .Values.service.port | toString }}
@@ -41,25 +41,25 @@ To access your YOURLS site from outside the cluster follow the steps below:
4141

4242
{{- if contains "NodePort" .Values.service.type }}
4343

44-
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "common.names.fullname" . }})
45-
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
46-
echo "YOURLS URL: http://$NODE_IP:$NODE_PORT/"
47-
echo "YOURLS Admin URL: http://$NODE_IP:$NODE_PORT/admin"
44+
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "common.names.fullname" . }})
45+
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
46+
echo "YOURLS URL: http://$NODE_IP:$NODE_PORT/"
47+
echo "YOURLS Admin URL: http://$NODE_IP:$NODE_PORT/admin"
4848

4949
{{- else if contains "LoadBalancer" .Values.service.type }}
5050

5151
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
5252
Watch the status with: 'kubectl get svc --namespace {{ .Release.Namespace }} -w {{ template "common.names.fullname" . }}'
5353

54-
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ template "common.names.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
55-
echo "YOURLS URL: http://$SERVICE_IP{{- if ne $port "80" }}:{{ .Values.service.port }}{{ end }}/"
56-
echo "YOURLS Admin URL: http://$SERVICE_IP{{- if ne $port "80" }}:{{ .Values.service.port }}{{ end }}/admin"
54+
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ template "common.names.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
55+
echo "YOURLS URL: http://$SERVICE_IP{{- if ne $port "80" }}:{{ .Values.service.port }}{{ end }}/"
56+
echo "YOURLS Admin URL: http://$SERVICE_IP{{- if ne $port "80" }}:{{ .Values.service.port }}{{ end }}/admin"
5757

5858
{{- else if contains "ClusterIP" .Values.service.type }}
5959

60-
kubectl port-forward --namespace {{ .Release.Namespace }} svc/{{ template "common.names.fullname" . }} {{ .Values.service.port }}:{{ .Values.service.port }} &
61-
echo "YOURLS URL: http://127.0.0.1{{- if ne $port "80" }}:{{ .Values.service.port }}{{ end }}/"
62-
echo "YOURLS Admin URL: http://127.0.0.1{{- if ne $port "80" }}:{{ .Values.service.port }}{{ end }}/admin"
60+
kubectl port-forward --namespace {{ .Release.Namespace }} svc/{{ template "common.names.fullname" . }} {{ .Values.service.port }}:{{ .Values.service.port }} &
61+
echo "YOURLS URL: http://127.0.0.1{{- if ne $port "80" }}:{{ .Values.service.port }}{{ end }}/"
62+
echo "YOURLS Admin URL: http://127.0.0.1{{- if ne $port "80" }}:{{ .Values.service.port }}{{ end }}/admin"
6363

6464
{{- end }}
6565
{{- end }}
@@ -68,8 +68,8 @@ To access your YOURLS site from outside the cluster follow the steps below:
6868

6969
3. Login with the following credentials below to see your app:
7070

71-
echo Username: $(kubectl get secret --namespace {{ .Release.Namespace }} {{ template "common.names.fullname" . }} -o jsonpath="{.data.username}" | base64 --decode)
72-
echo Password: $(kubectl get secret --namespace {{ .Release.Namespace }} {{ template "common.names.fullname" . }} -o jsonpath="{.data.password}" | base64 --decode)
71+
echo Username: $(kubectl get secret --namespace {{ .Release.Namespace }} {{ template "common.names.fullname" . }} -o jsonpath="{.data.username}" | base64 --decode)
72+
echo Password: $(kubectl get secret --namespace {{ .Release.Namespace }} {{ template "common.names.fullname" . }} -o jsonpath="{.data.password}" | base64 --decode)
7373

7474
{{- if .Values.metrics.enabled }}
7575

@@ -91,14 +91,11 @@ You can access Apache Prometheus metrics following the steps below:
9191
{{- include "common.warnings.rollingTag" .Values.volumePermissions.image }}
9292
{{- $passwordValidationErrors := list -}}
9393
{{- if not .Values.yourls.existingSecret -}}
94-
{{- $yourlsSecretName := include "yourls.secretName" . -}}
95-
{{- $yourlsPassword := dict "valueKey" "yourls.password" "secret" $yourlsSecretName "field" "password" "context" $ -}}
96-
{{- $yourlsPasswordValidationErrors := include "common.validations.values.single.empty" $yourlsPassword -}}
94+
{{- $yourlsPasswordValidationErrors := include "common.validations.values.single.empty" (dict "valueKey" "yourls.password" "secret" (include "yourls.secretName" .) "field" "password" "context" $) -}}
9795
{{- $passwordValidationErrors = append $passwordValidationErrors $yourlsPasswordValidationErrors -}}
9896
{{- end }}
9997
{{- if .Values.mariadb.enabled }}
100-
{{- $mariadbSecretName := include "yourls.databaseSecretName" . -}}
101-
{{- $mariadbPasswordValidationErrors := include "common.validations.values.mariadb.passwords" (dict "secret" $mariadbSecretName "subchart" true "context" $) -}}
98+
{{- $mariadbPasswordValidationErrors := include "common.validations.values.mariadb.passwords" (dict "secret" (include "yourls.databaseSecretName" .) "subchart" true "context" $) -}}
10299
{{- $passwordValidationErrors = append $passwordValidationErrors $mariadbPasswordValidationErrors -}}
103100
{{- end }}
104101
{{- include "common.errors.upgrade.passwords.empty" (dict "validationErrors" $passwordValidationErrors "context" $) -}}

charts/yourls/templates/_helpers.tpl

+8-15
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,9 @@ Return the MariaDB Secret Name
8989
*/}}
9090
{{- define "yourls.databaseSecretName" -}}
9191
{{- if .Values.mariadb.enabled }}
92-
{{- if .Values.mariadb.auth.existingSecret -}}
93-
{{- printf "%s" .Values.mariadb.auth.existingSecret -}}
94-
{{- else -}}
95-
{{- printf "%s" (include "yourls.mariadb.fullname" .) -}}
96-
{{- end -}}
97-
{{- else if .Values.externalDatabase.existingSecret -}}
98-
{{- printf "%s" .Values.externalDatabase.existingSecret -}}
92+
{{- include "mariadb.secretName" .Subcharts.mariadb -}}
9993
{{- else -}}
100-
{{- printf "%s-externaldb" (include "common.names.fullname" .) -}}
94+
{{- include "common.secrets.name" (dict "existingSecret" .Values.externalDatabase.existingSecret "defaultNameSuffix" "externaldb" "context" $) }}
10195
{{- end -}}
10296
{{- end -}}
10397

@@ -136,12 +130,11 @@ Compile all warnings into a single message.
136130
{{- define "yourls.validateValues.database" -}}
137131
{{- if and (not .Values.mariadb.enabled) (or (empty .Values.externalDatabase.host) (empty .Values.externalDatabase.port) (empty .Values.externalDatabase.database)) -}}
138132
yourls: database
139-
You disable the MariaDB installation but you did not provide the required parameters
140-
to use an external database. To use an external database, please ensure you provide
141-
(at least) the following values:
142-
143-
externalDatabase.host=DB_SERVER_HOST
144-
externalDatabase.database=DB_NAME
145-
externalDatabase.port=DB_SERVER_PORT
133+
You disable the MariaDB installation but you did not provide the required parameters
134+
to use an external database. To use an external database, please ensure you provide
135+
(at least) the following values:
136+
externalDatabase.host=DB_SERVER_HOST
137+
externalDatabase.database=DB_NAME
138+
externalDatabase.port=DB_SERVER_PORT
146139
{{- end -}}
147140
{{- end -}}

0 commit comments

Comments
 (0)