Skip to content

Commit

Permalink
Make it possible to create vcluster with numbers only name
Browse files Browse the repository at this point in the history
  • Loading branch information
johannesfrey committed Sep 23, 2024
1 parent d788f21 commit 68b91b1
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 12 deletions.
4 changes: 4 additions & 0 deletions chart/templates/_helper.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@
{{ .repository }}:{{ .tag }}
{{- end -}}
{{- end -}}

{{- define "vcluster.name" -}}
{{- printf "vc-%s" .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
2 changes: 1 addition & 1 deletion chart/templates/headless-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
apiVersion: v1
kind: Service
metadata:
name: {{ .Release.Name }}-headless
name: {{ template "vcluster.name" . }}-headless
namespace: {{ .Release.Namespace }}
labels:
app: vcluster
Expand Down
4 changes: 2 additions & 2 deletions chart/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
apiVersion: v1
kind: Service
metadata:
name: {{ .Release.Name }}
name: {{ template "vcluster.name" . }}
namespace: {{ .Release.Namespace }}
labels:
app: vcluster
Expand Down Expand Up @@ -41,6 +41,6 @@ spec:
{{- if and (not .Values.controlPlane.service.spec.selector) (not .Values.experimental.isolatedControlPlane.headless) }}
selector:
app: vcluster
release: {{ .Release.Name }}
release: {{ template "vcluster.name" . }}
{{- end }}
{{- end }}
10 changes: 5 additions & 5 deletions chart/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
apiVersion: apps/v1
kind: {{ include "vcluster.kind" . }}
metadata:
name: {{ .Release.Name }}
name: {{ .Release.Name | quote }}
namespace: {{ .Release.Namespace }}
labels:
app: vcluster
Expand All @@ -21,13 +21,13 @@ spec:
selector:
matchLabels:
app: vcluster
release: {{ .Release.Name }}
release: {{ .Release.Name | quote }}
{{- if eq (include "vcluster.kind" .) "StatefulSet" }}
{{- if ge (int .Capabilities.KubeVersion.Minor) 27 }}
persistentVolumeClaimRetentionPolicy:
whenDeleted: {{ .Values.controlPlane.statefulSet.persistence.volumeClaim.retentionPolicy }}
{{- end }}
serviceName: {{ .Release.Name }}-headless
serviceName: {{ template "vcluster.name" . }}-headless
podManagementPolicy: {{ .Values.controlPlane.statefulSet.scheduling.podManagementPolicy }}
{{ include "vcluster.persistence" . | indent 2 }}
{{- else }}
Expand All @@ -51,7 +51,7 @@ spec:
{{- end }}
labels:
app: vcluster
release: {{ .Release.Name }}
release: {{ .Release.Name | quote }}
{{- if .Values.controlPlane.statefulSet.pods.labels }}
{{ toYaml .Values.controlPlane.statefulSet.pods.labels | indent 8 }}
{{- end }}
Expand Down Expand Up @@ -87,7 +87,7 @@ spec:
dnsPolicy: {{ .Values.controlPlane.statefulSet.dnsPolicy }}
{{- end }}
{{- if .Values.controlPlane.statefulSet.dnsConfig }}
dnsConfig:
dnsConfig:
{{ toYaml .Values.controlPlane.statefulSet.dnsConfig | indent 8 }}
{{- end }}
{{- if .Values.controlPlane.advanced.serviceAccount.name }}
Expand Down
2 changes: 1 addition & 1 deletion chart/tests/headless-service_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ tests:
count: 1
- equal:
path: metadata.name
value: my-release-headless
value: vc-my-release-headless
- equal:
path: metadata.namespace
value: my-namespace
Expand Down
2 changes: 1 addition & 1 deletion chart/tests/service_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ tests:
count: 1
- equal:
path: metadata.name
value: my-release
value: vc-my-release
- equal:
path: metadata.namespace
value: my-namespace
Expand Down
4 changes: 2 additions & 2 deletions chart/tests/statefulset_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ tests:
value: StatefulSet
- equal:
path: spec.serviceName
value: my-release-headless
value: vc-my-release-headless
- contains:
path: spec.volumeClaimTemplates
content:
Expand All @@ -452,7 +452,7 @@ tests:
value: StatefulSet
- equal:
path: spec.serviceName
value: my-release-headless
value: vc-my-release-headless
- lengthEqual:
path: spec.volumeClaimTemplates
count: 1
Expand Down

0 comments on commit 68b91b1

Please sign in to comment.