Skip to content

Commit 317a01e

Browse files
authored
feat: Provide ability to create statefulset (#156)
1 parent d381ad5 commit 317a01e

File tree

6 files changed

+198
-6
lines changed

6 files changed

+198
-6
lines changed

README.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ and their default values.
8383

8484
| Parameter | Description | Default |
8585
| ---------------------------------- | -------------------------------------------------------------------------------- | ------------------------------ |
86+
| `type` | The type of resource to create. Either `deployment` or `statefulset`. Note: Statefulset is primarly useful when Verdaccio is being used as an edge cache | `deployment` |
8687
| `annotations` | Annotations to set on the deployment | `{}` |
8788
| `affinity` | Affinity for pod assignment | `{}` |
8889
| `existingConfigMap` | Name of custom ConfigMap to use | `false` |
@@ -95,7 +96,7 @@ and their default values.
9596
| `persistence.accessMode` | PVC Access Mode for Verdaccio volume | `ReadWriteOnce` |
9697
| `persistence.annotations` | Annotations to add to the PVC | `{}` |
9798
| `persistence.enabled` | Enable persistence using PVC | `true` |
98-
| `persistence.existingClaim` | Use existing PVC | `nil` |
99+
| `persistence.existingClaim` | Use existing PVC. Ignored when `type` is `statefuleset` | `nil` |
99100
| `persistence.mounts` | Additional mounts | `nil` |
100101
| `persistence.resourcePolicy` | Set "keep" to avoid removing PVC during a helm delete operation | `""` |
101102
| `persistence.selector` | Selector to match an existing Persistent Volume | `{}` (evaluated as a template) |
@@ -224,7 +225,7 @@ $ helm install npm \
224225

225226
Due to some breaking changes in Selector Labels and Security Contexts in Chart `3.0.0` you will need to migrate when upgrading.
226227

227-
First off, the `securityContext.enabled` field has been removed.
228+
First off, the `securityContext.enabled` field has been removed.
228229
In addition to this, `fsGroup` is not a valid Container Security Context field and has been migrated to the `podSecurityContext` instead.
229230

230231
```diff
@@ -237,8 +238,8 @@ podSecurityContext:
237238
runAsUser: 10001
238239
```
239240

240-
Secondly, the `apps.v1.Deployment.spec.selector` field is immutable and changes were made to Selector Labels which tries to update this.
241-
To get around this, you will need to `kubectl delete deployment $deploymentName` before doing a `helm upgrade`
241+
Secondly, the `apps.v1.Deployment.spec.selector` field is immutable and changes were made to Selector Labels which tries to update this.
242+
To get around this, you will need to `kubectl delete deployment $deploymentName` before doing a `helm upgrade`
242243
So long as your PVC is not destroyed, the new deployment will be rolled out with the same PVC as before and your data will remain intact.
243244

244245
### Migrating chart 3.x -> 4.x

charts/verdaccio/Chart.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apiVersion: v2
22
description: A lightweight private node.js proxy registry
33
name: verdaccio
4-
version: 4.22.0
4+
version: 4.23.0
55
appVersion: 6.0.2
66
home: https://verdaccio.org
77
icon: https://cdn.verdaccio.dev/logos/default.png

charts/verdaccio/templates/deployment.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{{- if eq .Values.type "deployment" }}
12
apiVersion: apps/v1
23
kind: Deployment
34
metadata:
@@ -180,3 +181,4 @@ spec:
180181
topologySpreadConstraints:
181182
{{- toYaml .Values.topologySpreadConstraints | nindent 8 }}
182183
{{- end }}
184+
{{- end -}}

charts/verdaccio/templates/pvc.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{- if and .Values.persistence.enabled (not .Values.persistence.existingClaim) -}}
1+
{{- if and (eq .Values.type "deployment") (and .Values.persistence.enabled (not .Values.persistence.existingClaim)) -}}
22
kind: PersistentVolumeClaim
33
apiVersion: v1
44
metadata:
+187
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
{{- if eq .Values.type "statefulset" -}}
2+
apiVersion: apps/v1
3+
kind: StatefulSet
4+
metadata:
5+
name: {{ template "verdaccio.fullname" . }}
6+
labels:
7+
{{- include "verdaccio.labels" . | nindent 4 }}
8+
{{- with .Values.annotations }}
9+
annotations:
10+
{{- toYaml . | nindent 4 }}
11+
{{- end }}
12+
spec:
13+
serviceName: {{ template "verdaccio.fullname" . }}
14+
{{- if .Values.replicaCountEnabled }}
15+
replicas: {{ .Values.replicaCount }}
16+
{{- else }}
17+
replicas: 1
18+
{{- end}}
19+
selector:
20+
matchLabels:
21+
{{- include "verdaccio.selectorLabels" . | nindent 6 }}
22+
updateStrategy:
23+
type: RollingUpdate
24+
template:
25+
metadata:
26+
annotations:
27+
checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
28+
checksum/htpasswd-secret: {{ toJson .Values.secrets.htpasswd | sha256sum }}
29+
{{- if .Values.secretEnvVars }}
30+
checksum/env-secret: {{ include (print $.Template.BasePath "/secret.yaml") . | sha256sum }}
31+
{{- end }}
32+
{{- if .Values.cachingNginx.enabled }}
33+
checksum/config-nginx: {{ include (print $.Template.BasePath "/configmap-nginx.yaml") . | sha256sum }}
34+
{{- end }}
35+
{{- include "verdaccio.podAnnotations" . | nindent 8 }}
36+
labels:
37+
{{- include "verdaccio.podLabels" . | nindent 8 }}
38+
spec:
39+
serviceAccountName: {{ include "verdaccio.serviceAccountName" . }}
40+
{{- include "verdaccio.imagePullSecrets" . | nindent 6 }}
41+
{{- with .Values.podSecurityContext }}
42+
securityContext:
43+
{{- toYaml . | nindent 8 }}
44+
{{- end }}
45+
{{- with .Values.extraInitContainers }}
46+
initContainers:
47+
{{- include "tplvalues.render" (dict "value" . "context" $) | nindent 8 }}
48+
{{- end }}
49+
containers:
50+
{{- if .Values.cachingNginx.enabled }}
51+
- name: {{ template "verdaccio.name" . }}-nginx
52+
imagePullPolicy: {{ .Values.cachingNginx.pullPolicy }}
53+
image: {{ .Values.cachingNginx.repository }}:{{ .Values.cachingNginx.tag }}
54+
volumeMounts:
55+
- name: config-volume
56+
mountPath: /etc/nginx/nginx.conf
57+
subPath: nginx.conf
58+
- name: config-volume
59+
mountPath: /etc/nginx/conf.d/default.conf
60+
subPath: default.conf
61+
resources:
62+
{{ toYaml .Values.cachingNginx.resources | nindent 12 }}
63+
ports:
64+
- containerPort: 80
65+
name: caching-nginx
66+
{{- end }}
67+
- name: {{ template "verdaccio.name" . }}
68+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
69+
imagePullPolicy: {{ .Values.image.pullPolicy }}
70+
{{- if or .Values.secretEnvVars .Values.existingSecret }}
71+
envFrom:
72+
{{- if .Values.secretEnvVars }}
73+
- secretRef:
74+
name: {{ template "verdaccio.fullname" . }}-env
75+
{{- end }}
76+
{{- if .Values.existingSecret }}
77+
- secretRef:
78+
name: {{ .Values.existingSecret }}
79+
{{- end }}
80+
{{- end }}
81+
ports:
82+
- containerPort: 4873
83+
name: http
84+
{{- range .Values.extraPorts }}
85+
- containerPort: {{ .port }}
86+
name: {{ .targetPort }}
87+
{{- end }}
88+
livenessProbe:
89+
httpGet:
90+
path: /-/ping
91+
port: http
92+
{{- with .Values.livenessProbe }}
93+
initialDelaySeconds: {{ .initialDelaySeconds | default 5 }}
94+
periodSeconds: {{ .periodSeconds | default 10 }}
95+
timeoutSeconds: {{ .timeoutSeconds | default 1 }}
96+
successThreshold: {{ .successThreshold | default 1 }}
97+
failureThreshold: {{ .failureThreshold | default 3 }}
98+
{{- end }}
99+
readinessProbe:
100+
httpGet:
101+
path: /-/ping
102+
port: http
103+
{{- with .Values.readinessProbe }}
104+
initialDelaySeconds: {{ .initialDelaySeconds | default 5 }}
105+
periodSeconds: {{ .periodSeconds | default 10 }}
106+
timeoutSeconds: {{ .timeoutSeconds | default 1 }}
107+
successThreshold: {{ .successThreshold | default 1 }}
108+
failureThreshold: {{ .failureThreshold | default 3 }}
109+
{{- end }}
110+
{{- with .Values.securityContext }}
111+
securityContext:
112+
{{- toYaml . | nindent 12 }}
113+
{{- end }}
114+
{{- with .Values.resources }}
115+
resources:
116+
{{- toYaml . | nindent 12 }}
117+
{{- end }}
118+
volumeMounts:
119+
{{- with .Values.persistence.mounts }}
120+
{{- include "tplvalues.render" (dict "value" . "context" $) | nindent 12 }}
121+
{{- end }}
122+
- mountPath: /verdaccio/storage
123+
name: storage
124+
readOnly: false
125+
{{- if .Values.secrets.htpasswd }}
126+
- mountPath: /verdaccio/storage/htpasswd
127+
name: htpasswd
128+
subPath: htpasswd
129+
readOnly: true
130+
{{- end }}
131+
- mountPath: /verdaccio/conf
132+
name: config
133+
readOnly: true
134+
{{- with .Values.extraEnvVars }}
135+
env:
136+
{{- toYaml . | nindent 12 }}
137+
{{- end }}
138+
volumes:
139+
- name: config
140+
configMap:
141+
name: {{ .Values.existingConfigMap | default (include "verdaccio.fullname" .) }}
142+
{{- if .Values.secrets.htpasswd }}
143+
- name: htpasswd
144+
secret:
145+
secretName: {{ include "verdaccio.fullname" . }}-htpasswd
146+
{{- end }}
147+
{{- if .Values.cachingNginx.enabled }}
148+
- name: config-volume
149+
configMap:
150+
name: {{ include "verdaccio.fullname" . }}-nginx-config
151+
{{- end }}
152+
{{- with .Values.persistence.volumes }}
153+
{{- include "tplvalues.render" (dict "value" . "context" $) | nindent 6 }}
154+
{{- end }}
155+
{{- if .Values.affinity }}
156+
affinity:
157+
{{- toYaml .Values.affinity | nindent 8 }}
158+
{{- end }}
159+
{{- if .Values.nodeSelector }}
160+
nodeSelector:
161+
{{- toYaml .Values.nodeSelector | nindent 8 }}
162+
{{- end }}
163+
{{- if .Values.tolerations }}
164+
tolerations:
165+
{{- toYaml .Values.tolerations | nindent 8 }}
166+
{{- end }}
167+
{{- if .Values.priorityClass.enabled }}
168+
priorityClassName: {{ .Values.priorityClass.name }}
169+
{{- end }}
170+
{{- if .Values.topologySpreadConstraints }}
171+
topologySpreadConstraints:
172+
{{- toYaml .Values.topologySpreadConstraints | nindent 8 }}
173+
{{- end }}
174+
volumeClaimTemplates:
175+
- metadata:
176+
name: storage
177+
spec:
178+
accessModes: [ {{ .Values.persistence.accessMode | quote }} ]
179+
{{- if (eq "-" .Values.persistence.storageClass) }}
180+
storageClassName: ""
181+
{{- else }}
182+
storageClassName: "{{ .Values.persistence.storageClass }}"
183+
{{- end }}
184+
resources:
185+
requests:
186+
storage: {{ .Values.persistence.size | quote }}
187+
{{- end -}}

charts/verdaccio/values.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ image:
55
pullSecrets: []
66
# - dockerhub-secret
77

8+
type: deployment
9+
810
nameOverride: ""
911
fullnameOverride: ""
1012

0 commit comments

Comments
 (0)