Skip to content

Commit ebf4c5c

Browse files
committed
dvcr: make templates nil-safe; remove temporary root values.yaml
Signed-off-by: Yachmenev Anton <[email protected]>
1 parent 3eb9449 commit ebf4c5c

File tree

4 files changed

+25
-26
lines changed

4 files changed

+25
-26
lines changed

templates/dvcr/_helpers.tpl

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ true
44
{{- end }}
55
{{- end }}
66

7+
{{- /* Safe accessor for dvcr storage type to avoid nil pointer during linting */ -}}
8+
{{- define "dvcr.storageType" -}}
9+
{{- $mc := .Values.virtualization.internal.moduleConfig | default dict -}}
10+
{{- dig "dvcr" "storage" "type" "" $mc -}}
11+
{{- end -}}
12+
713
{{- define "dvcr.envs" -}}
814
- name: REGISTRY_HTTP_TLS_CERTIFICATE
915
value: /etc/ssl/docker/tls.crt
@@ -23,15 +29,15 @@ true
2329
name: dvcr-secrets
2430
key: salt
2531

26-
{{- if eq .Values.virtualization.internal.moduleConfig.dvcr.storage.type "PersistentVolumeClaim" }}
32+
{{- if eq (include "dvcr.storageType" .) "PersistentVolumeClaim" }}
2733
- name: REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY
2834
value: "/var/lib/registry"
29-
{{- else if eq .Values.virtualization.internal.moduleConfig.dvcr.storage.type "ObjectStorage" }}
30-
{{- if eq .Values.virtualization.internal.moduleConfig.dvcr.storage.objectStorage.type "S3" }}
35+
{{- else if eq (include "dvcr.storageType" .) "ObjectStorage" }}
36+
{{- if eq (dig "dvcr" "storage" "objectStorage" "type" "" .Values.virtualization.internal.moduleConfig) "S3" }}
3137
- name: REGISTRY_STORAGE_S3_REGION
32-
value: "{{ .Values.virtualization.internal.moduleConfig.dvcr.storage.objectStorage.s3.region }}"
38+
value: "{{ dig "dvcr" "storage" "objectStorage" "s3" "region" "" .Values.virtualization.internal.moduleConfig }}"
3339
- name: REGISTRY_STORAGE_S3_BUCKET
34-
value: "{{ .Values.virtualization.internal.moduleConfig.dvcr.storage.objectStorage.s3.bucket }}"
40+
value: "{{ dig "dvcr" "storage" "objectStorage" "s3" "bucket" "" .Values.virtualization.internal.moduleConfig }}"
3541
- name: REGISTRY_STORAGE_S3_ACCESSKEY
3642
valueFrom:
3743
secretKeyRef:
@@ -43,7 +49,7 @@ true
4349
name: dvcr-object-storage-credentials
4450
key: s3SecretKey
4551
- name: REGISTRY_STORAGE_S3_REGIONENDPOINT
46-
value: "{{ .Values.virtualization.internal.moduleConfig.dvcr.storage.objectStorage.s3.regionEndpoint }}"
52+
value: "{{ dig "dvcr" "storage" "objectStorage" "s3" "regionEndpoint" "" .Values.virtualization.internal.moduleConfig }}"
4753
{{- end }}
4854
{{- end }}
4955
{{- end }}
@@ -53,7 +59,7 @@ true
5359
- name: "dvcr-config"
5460
mountPath: "/etc/docker/registry"
5561

56-
{{- if eq .Values.virtualization.internal.moduleConfig.dvcr.storage.type "PersistentVolumeClaim" }}
62+
{{- if eq (include "dvcr.storageType" .) "PersistentVolumeClaim" }}
5763
- name: data
5864
mountPath: /var/lib/registry/
5965
{{- end }}
@@ -74,7 +80,7 @@ true
7480
configMap:
7581
name: dvcr-config
7682

77-
{{- if eq .Values.virtualization.internal.moduleConfig.dvcr.storage.type "PersistentVolumeClaim" }}
83+
{{- if eq (include "dvcr.storageType" .) "PersistentVolumeClaim" }}
7884
- name: data
7985
persistentVolumeClaim:
8086
claimName: dvcr
@@ -94,18 +100,18 @@ true
94100

95101

96102
{{- define "dvcr.helm_lib_deployment_strategy_and_replicas_for_ha" -}}
97-
{{- if and (include "helm_lib_ha_enabled" .) (eq .Values.virtualization.internal.moduleConfig.dvcr.storage.type "ObjectStorage") }}
103+
{{- if and (include "helm_lib_ha_enabled" .) (eq (include "dvcr.storageType" .) "ObjectStorage") }}
98104
replicas: 2
99105
strategy:
100106
type: RollingUpdate
101107
rollingUpdate:
102108
maxSurge: 0
103109
maxUnavailable: 1
104-
{{- else if eq .Values.virtualization.internal.moduleConfig.dvcr.storage.type "ObjectStorage" }}
110+
{{- else if eq (include "dvcr.storageType" .) "ObjectStorage" }}
105111
replicas: 1
106112
strategy:
107113
type: RollingUpdate
108-
{{- else if eq .Values.virtualization.internal.moduleConfig.dvcr.storage.type "PersistentVolumeClaim" }}
114+
{{- else if eq (include "dvcr.storageType" .) "PersistentVolumeClaim" }}
109115
replicas: 1
110116
strategy:
111117
type: Recreate
@@ -116,7 +122,7 @@ strategy:
116122
{{- $context := index . 0 -}}
117123
{{- $yes := index . 1 -}}
118124
{{- $no := index . 2 -}}
119-
{{- if and (include "helm_lib_ha_enabled" $context) (eq $context.Values.virtualization.internal.moduleConfig.dvcr.storage.type "ObjectStorage") }}
125+
{{- if and (include "helm_lib_ha_enabled" $context) (eq (include "dvcr.storageType" $context) "ObjectStorage") }}
120126
{{- $yes -}}
121127
{{- else }}
122128
{{- $no -}}

templates/dvcr/pvc.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{{- if eq (include "dvcr.isEnabled" . ) "true"}}
2-
{{- if eq .Values.virtualization.internal.moduleConfig.dvcr.storage.type "PersistentVolumeClaim" }}
3-
{{- $storageClassName := dig "storageClassName" "" .Values.virtualization.internal.moduleConfig.dvcr.storage.persistentVolumeClaim }}
2+
{{- if eq (include "dvcr.storageType" .) "PersistentVolumeClaim" }}
3+
{{- $storageClassName := dig "dvcr" "storage" "persistentVolumeClaim" "storageClassName" "" .Values.virtualization.internal.moduleConfig }}
44
kind: PersistentVolumeClaim
55
apiVersion: v1
66
metadata:
@@ -12,7 +12,7 @@ spec:
1212
- ReadWriteOnce
1313
resources:
1414
requests:
15-
storage: {{ .Values.virtualization.internal.moduleConfig.dvcr.storage.persistentVolumeClaim.size | quote }}
15+
storage: {{ dig "dvcr" "storage" "persistentVolumeClaim" "size" "" .Values.virtualization.internal.moduleConfig | quote }}
1616
{{- if ne $storageClassName "" }}
1717
storageClassName: {{ $storageClassName }}
1818
{{- end }}

templates/dvcr/secret.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type: kubernetes.io/dockerconfigjson
4040
data:
4141
{{- include "dvcr.generate_dockercfg" (list . $registry "admin" .Values.virtualization.internal.dvcr.passwordRW) | nindent 2 }}
4242

43-
{{- if eq .Values.virtualization.internal.moduleConfig.dvcr.storage.type "ObjectStorage"}}
43+
{{- if eq (include "dvcr.storageType" .) "ObjectStorage"}}
4444
---
4545
apiVersion: v1
4646
kind: Secret
@@ -50,9 +50,9 @@ metadata:
5050
{{- include "helm_lib_module_labels" (list . (dict "app" "dvcr" )) | nindent 2 }}
5151
type: Opaque
5252
data:
53-
{{- if eq .Values.virtualization.internal.moduleConfig.dvcr.storage.objectStorage.type "S3"}}
54-
s3AccessKey: {{ .Values.virtualization.internal.moduleConfig.dvcr.storage.objectStorage.s3.accessKey | quote }}
55-
s3SecretKey: {{ .Values.virtualization.internal.moduleConfig.dvcr.storage.objectStorage.s3.secretKey | quote }}
53+
{{- if eq (dig "dvcr" "storage" "objectStorage" "type" "" .Values.virtualization.internal.moduleConfig) "S3"}}
54+
s3AccessKey: {{ dig "dvcr" "storage" "objectStorage" "s3" "accessKey" "" .Values.virtualization.internal.moduleConfig | quote }}
55+
s3SecretKey: {{ dig "dvcr" "storage" "objectStorage" "s3" "secretKey" "" .Values.virtualization.internal.moduleConfig | quote }}
5656
{{- end }}
5757
{{- end }}
5858
{{- end }}

values.yaml

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)