Skip to content

Commit ecf9e9a

Browse files
committed
feat: helm chart
1 parent b30fb44 commit ecf9e9a

16 files changed

Lines changed: 1452 additions & 0 deletions

chart/Chart.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
apiVersion: v2
2+
name: docker-cache-server
3+
version: 0.0.1
4+
appVersion: v0.0.2
5+
kubeVersion: ">=1.18.0"

chart/templates/_affinities.tpl

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
{{/* vim: set filetype=mustache: */}}
2+
3+
{{/*
4+
Return a soft nodeAffinity definition
5+
{{ include "common.affinities.nodes.soft" (dict "key" "FOO" "values" (list "BAR" "BAZ")) -}}
6+
*/}}
7+
{{- define "common.affinities.nodes.soft" -}}
8+
preferredDuringSchedulingIgnoredDuringExecution:
9+
- preference:
10+
matchExpressions:
11+
- key: {{ .key }}
12+
operator: In
13+
values:
14+
{{- range .values }}
15+
- {{ . | quote }}
16+
{{- end }}
17+
weight: 1
18+
{{- end -}}
19+
20+
{{/*
21+
Return a hard nodeAffinity definition
22+
{{ include "common.affinities.nodes.hard" (dict "key" "FOO" "values" (list "BAR" "BAZ")) -}}
23+
*/}}
24+
{{- define "common.affinities.nodes.hard" -}}
25+
requiredDuringSchedulingIgnoredDuringExecution:
26+
nodeSelectorTerms:
27+
- matchExpressions:
28+
- key: {{ .key }}
29+
operator: In
30+
values:
31+
{{- range .values }}
32+
- {{ . | quote }}
33+
{{- end }}
34+
{{- end -}}
35+
36+
{{/*
37+
Return a nodeAffinity definition
38+
{{ include "common.affinities.nodes" (dict "type" "soft" "key" "FOO" "values" (list "BAR" "BAZ")) -}}
39+
*/}}
40+
{{- define "common.affinities.nodes" -}}
41+
{{- if eq .type "soft" }}
42+
{{- include "common.affinities.nodes.soft" . -}}
43+
{{- else if eq .type "hard" }}
44+
{{- include "common.affinities.nodes.hard" . -}}
45+
{{- end -}}
46+
{{- end -}}
47+
48+
{{/*
49+
Return a soft podAffinity/podAntiAffinity definition
50+
{{ include "common.affinities.pods.soft" (dict "component" "FOO" "extraMatchLabels" .Values.extraMatchLabels "context" $) -}}
51+
*/}}
52+
{{- define "common.affinities.pods.soft" -}}
53+
{{- $component := default "" .component -}}
54+
{{- $extraMatchLabels := default (dict) .extraMatchLabels -}}
55+
preferredDuringSchedulingIgnoredDuringExecution:
56+
- podAffinityTerm:
57+
labelSelector:
58+
matchLabels: {{- (include "common.labels.matchLabels" .context) | nindent 10 }}
59+
{{- if not (empty $component) }}
60+
{{ printf "docker-cache-server.kubernetes.io/component: %s" $component }}
61+
{{- end }}
62+
{{- range $key, $value := $extraMatchLabels }}
63+
{{ $key }}: {{ $value | quote }}
64+
{{- end }}
65+
namespaces:
66+
- {{ include "common.names.namespace" .context | quote }}
67+
topologyKey: kubernetes.io/hostname
68+
weight: 1
69+
{{- end -}}
70+
71+
{{/*
72+
Return a hard podAffinity/podAntiAffinity definition
73+
{{ include "common.affinities.pods.hard" (dict "component" "FOO" "extraMatchLabels" .Values.extraMatchLabels "context" $) -}}
74+
*/}}
75+
{{- define "common.affinities.pods.hard" -}}
76+
{{- $component := default "" .component -}}
77+
{{- $extraMatchLabels := default (dict) .extraMatchLabels -}}
78+
requiredDuringSchedulingIgnoredDuringExecution:
79+
- labelSelector:
80+
matchLabels: {{- (include "common.labels.matchLabels" .context) | nindent 8 }}
81+
{{- if not (empty $component) }}
82+
{{ printf "docker-cache-server.kubernetes.io/component: %s" $component }}
83+
{{- end }}
84+
{{- range $key, $value := $extraMatchLabels }}
85+
{{ $key }}: {{ $value | quote }}
86+
{{- end }}
87+
namespaces:
88+
- {{ include "common.names.namespace" .context | quote }}
89+
topologyKey: kubernetes.io/hostname
90+
{{- end -}}
91+
92+
{{/*
93+
Return a podAffinity/podAntiAffinity definition
94+
{{ include "common.affinities.pods" (dict "type" "soft" "key" "FOO" "values" (list "BAR" "BAZ")) -}}
95+
*/}}
96+
{{- define "common.affinities.pods" -}}
97+
{{- if eq .type "soft" }}
98+
{{- include "common.affinities.pods.soft" . -}}
99+
{{- else if eq .type "hard" }}
100+
{{- include "common.affinities.pods.hard" . -}}
101+
{{- end -}}
102+
{{- end -}}

chart/templates/_app.tpl

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{{- define "docker-cache-server.image" -}}
2+
{{- $image := (include "common.images.image" (dict "imageRoot" .Values.image "global" .Values.global)) }}
3+
{{- if eq .Values.image.tag "" -}}
4+
{{- $image = (printf "%s%s" $image .Chart.AppVersion) -}}
5+
{{- end -}}
6+
{{- $image -}}
7+
{{- end -}}
8+
{{- define "docker-cache-server.imagePullSecrets" -}}
9+
{{- include "common.images.pullSecrets" (dict "images" (list .Values.image) "global" .Values.global) -}}
10+
{{- end -}}
11+
{{- define "docker-cache-server.serviceAccountName" -}}
12+
{{- if .Values.serviceAccount.create -}}
13+
{{ default (include "common.names.fullname" .) .Values.serviceAccount.name }}
14+
{{- else -}}
15+
{{ default "default" .Values.serviceAccount.name }}
16+
{{- end -}}
17+
{{- end -}}
18+
{{- define "docker-cache-server.configMapName" -}}
19+
{{- if .Values.existingConfigMap -}}
20+
{{- .Values.existingConfigMap -}}
21+
{{- else -}}
22+
{{ template "common.names.fullname" . }}-config
23+
{{- end -}}
24+
{{- end -}}
25+
26+
{{- define "docker-cache-server.resources.requests" }}
27+
{{- $def := dict -}}
28+
{{- if not .Values.cacheStorage.persistence.enabled -}}
29+
{{- $def = dict "ephemeral-storage" .Values.cacheStorage.emptyDir.sizeLimit }}
30+
{{- end -}}
31+
{{- merge .Values.resources.requests $def | toYaml -}}
32+
{{- end }}
33+
34+
{{- define "docker-cache-server.cacheStorage.pvcName" }}
35+
{{- printf "%s-cache" (include "common.names.fullname" .) }}
36+
{{- end }}
37+
38+
{{- define "docker-cache-server.configmapName" -}}
39+
{{- printf "%s-config" (include "common.names.fullname" .) -}}
40+
{{- end }}
41+

chart/templates/_capabilities.tpl

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
{{/* vim: set filetype=mustache: */}}
2+
3+
{{/*
4+
Return the target Kubernetes version
5+
*/}}
6+
{{- define "common.capabilities.kubeVersion" -}}
7+
{{- if .Values.global }}
8+
{{- if .Values.global.kubeVersion }}
9+
{{- .Values.global.kubeVersion -}}
10+
{{- else }}
11+
{{- default .Capabilities.KubeVersion.Version .Values.kubeVersion -}}
12+
{{- end -}}
13+
{{- else }}
14+
{{- default .Capabilities.KubeVersion.Version .Values.kubeVersion -}}
15+
{{- end -}}
16+
{{- end -}}
17+
18+
{{/*
19+
Return the appropriate apiVersion for poddisruptionbudget.
20+
*/}}
21+
{{- define "common.capabilities.policy.apiVersion" -}}
22+
{{- if semverCompare "<1.21-0" (include "common.capabilities.kubeVersion" .) -}}
23+
{{- print "policy/v1beta1" -}}
24+
{{- else -}}
25+
{{- print "policy/v1" -}}
26+
{{- end -}}
27+
{{- end -}}
28+
29+
{{/*
30+
Return the appropriate apiVersion for networkpolicy.
31+
*/}}
32+
{{- define "common.capabilities.networkPolicy.apiVersion" -}}
33+
{{- if semverCompare "<1.7-0" (include "common.capabilities.kubeVersion" .) -}}
34+
{{- print "extensions/v1beta1" -}}
35+
{{- else -}}
36+
{{- print "networking.k8s.io/v1" -}}
37+
{{- end -}}
38+
{{- end -}}
39+
40+
{{/*
41+
Return the appropriate apiVersion for cronjob.
42+
*/}}
43+
{{- define "common.capabilities.cronjob.apiVersion" -}}
44+
{{- if semverCompare "<1.21-0" (include "common.capabilities.kubeVersion" .) -}}
45+
{{- print "batch/v1beta1" -}}
46+
{{- else -}}
47+
{{- print "batch/v1" -}}
48+
{{- end -}}
49+
{{- end -}}
50+
51+
{{/*
52+
Return the appropriate apiVersion for deployment.
53+
*/}}
54+
{{- define "common.capabilities.deployment.apiVersion" -}}
55+
{{- if semverCompare "<1.14-0" (include "common.capabilities.kubeVersion" .) -}}
56+
{{- print "extensions/v1beta1" -}}
57+
{{- else -}}
58+
{{- print "apps/v1" -}}
59+
{{- end -}}
60+
{{- end -}}
61+
62+
{{/*
63+
Return the appropriate apiVersion for statefulset.
64+
*/}}
65+
{{- define "common.capabilities.statefulset.apiVersion" -}}
66+
{{- if semverCompare "<1.14-0" (include "common.capabilities.kubeVersion" .) -}}
67+
{{- print "apps/v1beta1" -}}
68+
{{- else -}}
69+
{{- print "apps/v1" -}}
70+
{{- end -}}
71+
{{- end -}}
72+
73+
{{/*
74+
Return the appropriate apiVersion for ingress.
75+
*/}}
76+
{{- define "common.capabilities.ingress.apiVersion" -}}
77+
{{- if .Values.ingress -}}
78+
{{- if .Values.ingress.apiVersion -}}
79+
{{- .Values.ingress.apiVersion -}}
80+
{{- else if semverCompare "<1.14-0" (include "common.capabilities.kubeVersion" .) -}}
81+
{{- print "extensions/v1beta1" -}}
82+
{{- else if semverCompare "<1.19-0" (include "common.capabilities.kubeVersion" .) -}}
83+
{{- print "networking.k8s.io/v1beta1" -}}
84+
{{- else -}}
85+
{{- print "networking.k8s.io/v1" -}}
86+
{{- end }}
87+
{{- else if semverCompare "<1.14-0" (include "common.capabilities.kubeVersion" .) -}}
88+
{{- print "extensions/v1beta1" -}}
89+
{{- else if semverCompare "<1.19-0" (include "common.capabilities.kubeVersion" .) -}}
90+
{{- print "networking.k8s.io/v1beta1" -}}
91+
{{- else -}}
92+
{{- print "networking.k8s.io/v1" -}}
93+
{{- end -}}
94+
{{- end -}}
95+
96+
{{/*
97+
Return the appropriate apiVersion for RBAC resources.
98+
*/}}
99+
{{- define "common.capabilities.rbac.apiVersion" -}}
100+
{{- if semverCompare "<1.17-0" (include "common.capabilities.kubeVersion" .) -}}
101+
{{- print "rbac.authorization.k8s.io/v1beta1" -}}
102+
{{- else -}}
103+
{{- print "rbac.authorization.k8s.io/v1" -}}
104+
{{- end -}}
105+
{{- end -}}
106+
107+
{{/*
108+
Return the appropriate apiVersion for CRDs.
109+
*/}}
110+
{{- define "common.capabilities.crd.apiVersion" -}}
111+
{{- if semverCompare "<1.19-0" (include "common.capabilities.kubeVersion" .) -}}
112+
{{- print "apiextensions.k8s.io/v1beta1" -}}
113+
{{- else -}}
114+
{{- print "apiextensions.k8s.io/v1" -}}
115+
{{- end -}}
116+
{{- end -}}
117+
118+
{{/*
119+
Return the appropriate apiVersion for APIService.
120+
*/}}
121+
{{- define "common.capabilities.apiService.apiVersion" -}}
122+
{{- if semverCompare "<1.10-0" (include "common.capabilities.kubeVersion" .) -}}
123+
{{- print "apiregistration.k8s.io/v1beta1" -}}
124+
{{- else -}}
125+
{{- print "apiregistration.k8s.io/v1" -}}
126+
{{- end -}}
127+
{{- end -}}
128+
129+
{{/*
130+
Return the appropriate apiVersion for Horizontal Pod Autoscaler.
131+
*/}}
132+
{{- define "common.capabilities.hpa.apiVersion" -}}
133+
{{- if semverCompare "<1.23-0" (include "common.capabilities.kubeVersion" .context) -}}
134+
{{- if .beta2 -}}
135+
{{- print "autoscaling/v2beta2" -}}
136+
{{- else -}}
137+
{{- print "autoscaling/v2beta1" -}}
138+
{{- end -}}
139+
{{- else -}}
140+
{{- print "autoscaling/v2" -}}
141+
{{- end -}}
142+
{{- end -}}
143+
144+
{{/*
145+
Returns true if the used Helm version is 3.3+.
146+
A way to check the used Helm version was not introduced until version 3.3.0 with .Capabilities.HelmVersion, which contains an additional "{}}" structure.
147+
This check is introduced as a regexMatch instead of {{ if .Capabilities.HelmVersion }} because checking for the key HelmVersion in <3.3 results in a "interface not found" error.
148+
**To be removed when the catalog's minimun Helm version is 3.3**
149+
*/}}
150+
{{- define "common.capabilities.supportsHelmVersion" -}}
151+
{{- if regexMatch "{(v[0-9])*[^}]*}}$" (.Capabilities | toString ) }}
152+
{{- true -}}
153+
{{- end -}}
154+
{{- end -}}

chart/templates/_helper.tpl

Whitespace-only changes.

chart/templates/_images.tpl

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
{{/* vim: set filetype=mustache: */}}
2+
{{/*
3+
Return the proper image name
4+
{{ include "common.images.image" ( dict "imageRoot" .Values.path.to.the.image "global" $) }}
5+
*/}}
6+
{{- define "common.images.image" -}}
7+
{{- $registryName := .imageRoot.registry -}}
8+
{{- $repositoryName := .imageRoot.repository -}}
9+
{{- $separator := ":" -}}
10+
{{- $termination := .imageRoot.tag | toString -}}
11+
{{- if .global }}
12+
{{- if .global.imageRegistry }}
13+
{{- $registryName = .global.imageRegistry -}}
14+
{{- end -}}
15+
{{- end -}}
16+
{{- if .imageRoot.digest }}
17+
{{- $separator = "@" -}}
18+
{{- $termination = .imageRoot.digest | toString -}}
19+
{{- end -}}
20+
{{- printf "%s/%s%s%s" $registryName $repositoryName $separator $termination -}}
21+
{{- end -}}
22+
23+
{{/*
24+
Return the proper Docker Image Registry Secret Names (deprecated: use common.images.renderPullSecrets instead)
25+
{{ include "common.images.pullSecrets" ( dict "images" (list .Values.path.to.the.image1, .Values.path.to.the.image2) "global" .Values.global) }}
26+
*/}}
27+
{{- define "common.images.pullSecrets" -}}
28+
{{- $pullSecrets := list }}
29+
30+
{{- if .global }}
31+
{{- range .global.imagePullSecrets -}}
32+
{{- $pullSecrets = append $pullSecrets . -}}
33+
{{- end -}}
34+
{{- end -}}
35+
36+
{{- range .images -}}
37+
{{- range .pullSecrets -}}
38+
{{- $pullSecrets = append $pullSecrets . -}}
39+
{{- end -}}
40+
{{- end -}}
41+
42+
{{- if (not (empty $pullSecrets)) }}
43+
imagePullSecrets:
44+
{{- range $pullSecrets }}
45+
- name: {{ . }}
46+
{{- end }}
47+
{{- end }}
48+
{{- end -}}
49+
50+
{{/*
51+
Return the proper Docker Image Registry Secret Names evaluating values as templates
52+
{{ include "common.images.renderPullSecrets" ( dict "images" (list .Values.path.to.the.image1, .Values.path.to.the.image2) "context" $) }}
53+
*/}}
54+
{{- define "common.images.renderPullSecrets" -}}
55+
{{- $pullSecrets := list }}
56+
{{- $context := .context }}
57+
58+
{{- if $context.Values.global }}
59+
{{- range $context.Values.global.imagePullSecrets -}}
60+
{{- $pullSecrets = append $pullSecrets (include "common.tplvalues.render" (dict "value" . "context" $context)) -}}
61+
{{- end -}}
62+
{{- end -}}
63+
64+
{{- range .images -}}
65+
{{- range .pullSecrets -}}
66+
{{- $pullSecrets = append $pullSecrets (include "common.tplvalues.render" (dict "value" . "context" $context)) -}}
67+
{{- end -}}
68+
{{- end -}}
69+
70+
{{- if (not (empty $pullSecrets)) }}
71+
imagePullSecrets:
72+
{{- range $pullSecrets }}
73+
- name: {{ . }}
74+
{{- end }}
75+
{{- end }}
76+
{{- end -}}

0 commit comments

Comments
 (0)