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 24, 2024
1 parent d788f21 commit 00ed826
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 13 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
2 changes: 1 addition & 1 deletion pkg/config/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func ParseConfig(path, name string, setValues []string) (*VirtualClusterConfig,
retConfig := &VirtualClusterConfig{
Config: *rawConfig,
Name: name,
ControlPlaneService: name,
ControlPlaneService: fmt.Sprintf("vc-%s", name),
}

// validate config
Expand Down

0 comments on commit 00ed826

Please sign in to comment.