From 10662cb50d2fab6cb88664a4ade00e6a3c4528c9 Mon Sep 17 00:00:00 2001 From: Yurii Vlasov Date: Tue, 31 Jan 2023 10:11:00 +0200 Subject: [PATCH] Added HPA and many extra fields --- Chart.yaml | 4 -- templates/_helpers.tpl | 3 ++ templates/api/deployment.yaml | 16 ++++++-- templates/api/hpa.yaml | 32 ++++++++++++++++ templates/api/service.yaml | 3 ++ templates/frontend/deployment.yaml | 31 ++++++--------- templates/frontend/hpa.yaml | 32 ++++++++++++++++ templates/frontend/service.yaml | 5 ++- templates/serviceaccount.yaml | 3 ++ values.yaml | 60 +++++++++++++++++++++++------- 10 files changed, 148 insertions(+), 41 deletions(-) create mode 100644 templates/api/hpa.yaml create mode 100644 templates/frontend/hpa.yaml diff --git a/Chart.yaml b/Chart.yaml index 8054a78..5c55083 100644 --- a/Chart.yaml +++ b/Chart.yaml @@ -1,6 +1,3 @@ - - - apiVersion: v2 type: application name: vikunja @@ -40,4 +37,3 @@ maintainers: sources: - https://kolaente.dev/vikunja/helm-chart - https://vikunja.io - diff --git a/templates/_helpers.tpl b/templates/_helpers.tpl index d97f6ad..756dd81 100644 --- a/templates/_helpers.tpl +++ b/templates/_helpers.tpl @@ -48,6 +48,9 @@ Selector labels {{- define "vikunja.selectorLabels" -}} app.kubernetes.io/name: {{ include "vikunja.name" . }} app.kubernetes.io/instance: {{ .Release.Name }} +{{- with .Values.extraLabels }} +{{- toYaml . | nindent 0 }} +{{- end }} {{- end }} {{/* diff --git a/templates/api/deployment.yaml b/templates/api/deployment.yaml index 7856446..e0f4642 100644 --- a/templates/api/deployment.yaml +++ b/templates/api/deployment.yaml @@ -8,6 +8,9 @@ spec: {{- if not .Values.api.autoscaling.enabled }} replicas: {{ .Values.api.replicaCount }} {{- end }} + {{- with .Values.api.extraDeploymentSpec }} + {{- toYaml . | nindent 2 }} + {{- end }} selector: matchLabels: {{- include "vikunja.apiSelectorLabels" . | nindent 6 }} @@ -29,19 +32,26 @@ spec: securityContext: {{- toYaml . | nindent 8 }} {{- end }} + {{- with .Values.api.initContainers }} + initContainers: + {{- toYaml . | nindent 8 }} + {{- end }} containers: - - name: {{ .Chart.Name }} + {{- with .Values.api.sidecarContainers }} + {{- toYaml . | nindent 8 }} + {{- end }} + - name: api {{- with .Values.api.securityContext }} securityContext: {{- toYaml . | nindent 10 }} {{- end }} {{- $image := required ".image.repository is not set" .Values.api.image.repository }} - {{- $tag := required ".image.tag is not set" .Values.api.image.tag }} + {{- $tag := default .Chart.AppVersion .Values.api.image.tag | toString }} image: {{ printf "%s:%s" $image $tag | quote }} imagePullPolicy: {{ .Values.api.image.pullPolicy }} ports: - name: http - containerPort: 5000 + containerPort: {{ (.Values.api.config.service.interface | split ":")._1 | int }} protocol: TCP {{- with .Values.api.env }} env: diff --git a/templates/api/hpa.yaml b/templates/api/hpa.yaml new file mode 100644 index 0000000..b778e94 --- /dev/null +++ b/templates/api/hpa.yaml @@ -0,0 +1,32 @@ +{{- if .Values.api.autoscaling.enabled }} +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "vikunja.apiFullname" . }} + labels: + {{- include "vikunja.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "vikunja.apiFullname" . }} + minReplicas: {{ int .Values.api.autoscaling.minReplicas }} + maxReplicas: {{ int .Values.api.autoscaling.maxReplicas }} + metrics: + {{- if .Values.api.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: {{ int .Values.api.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.api.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + target: + type: Utilization + averageUtilization: {{ int .Values.api.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} +{{- end }} diff --git a/templates/api/service.yaml b/templates/api/service.yaml index 1c73918..c9c9aa6 100644 --- a/templates/api/service.yaml +++ b/templates/api/service.yaml @@ -13,3 +13,6 @@ spec: name: http selector: {{- include "vikunja.apiSelectorLabels" . | nindent 4 }} + {{- with .Values.api.service.extraSpec }} + {{- toYaml . | nindent 2 }} + {{- end }} diff --git a/templates/frontend/deployment.yaml b/templates/frontend/deployment.yaml index a37c68f..a1cbffb 100644 --- a/templates/frontend/deployment.yaml +++ b/templates/frontend/deployment.yaml @@ -8,6 +8,9 @@ spec: {{- if not .Values.frontend.autoscaling.enabled }} replicas: {{ .Values.frontend.replicaCount }} {{- end }} + {{- with .Values.frontend.extraDeploymentSpec }} + {{- toYaml . | nindent 2 }} + {{- end }} selector: matchLabels: {{- include "vikunja.frontendSelectorLabels" . | nindent 6 }} @@ -29,29 +32,21 @@ spec: securityContext: {{- toYaml . | nindent 8 }} {{- end }} + {{- with .Values.frontend.initContainers }} initContainers: - - name: permissions - image: alpine:3.16.3 - imagePullPolicy: IfNotPresent - command: ["/bin/sh", "-c"] - args: - - |- - cd /var/cache/nginx - for i in client_temp proxy_temp fastcgi_temp uwsgi_temp csgi_temp scgi_temp; do - mkdir -p "$i" - chown -Rv 1000:1000 "$i" - done - volumeMounts: - - name: nginx-cache - mountPath: /var/cache/nginx + {{- toYaml . | nindent 8 }} + {{- end }} containers: - - name: {{ .Chart.Name }} + {{- with .Values.frontend.sidecarContainers }} + {{- toYaml . | nindent 8 }} + {{- end }} + - name: frontend {{- with .Values.frontend.securityContext }} securityContext: {{- toYaml . | nindent 10 }} {{- end }} {{- $image := required ".image.repository is not set" .Values.frontend.image.repository }} - {{- $tag := required ".image.tag is not set" .Values.frontend.image.tag }} + {{- $tag := default .Chart.AppVersion .Values.frontend.image.tag | toString }} image: {{ printf "%s:%s" $image $tag | quote }} imagePullPolicy: {{ .Values.frontend.image.pullPolicy }} ports: @@ -89,16 +84,12 @@ spec: volumeMounts: - name: tmp mountPath: /tmp - - name: nginx-cache - mountPath: /var/cache/nginx {{- with .Values.frontend.extraVolumeMounts }} {{- toYaml . | nindent 8 }} {{- end }} volumes: - name: tmp emptyDir: {} - - name: nginx-cache - emptyDir: {} {{- with .Values.frontend.extraVolumes }} {{- toYaml . | nindent 6 }} {{- end }} diff --git a/templates/frontend/hpa.yaml b/templates/frontend/hpa.yaml new file mode 100644 index 0000000..9264d45 --- /dev/null +++ b/templates/frontend/hpa.yaml @@ -0,0 +1,32 @@ +{{- if .Values.frontend.autoscaling.enabled }} +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "vikunja.frontendFullname" . }} + labels: + {{- include "vikunja.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "vikunja.frontendFullname" . }} + minReplicas: {{ int .Values.frontend.autoscaling.minReplicas }} + maxReplicas: {{ int .Values.frontend.autoscaling.maxReplicas }} + metrics: + {{- if .Values.frontend.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: {{ int .Values.frontend.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.frontend.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + target: + type: Utilization + averageUtilization: {{ int .Values.frontend.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} +{{- end }} diff --git a/templates/frontend/service.yaml b/templates/frontend/service.yaml index ac45900..34dc798 100644 --- a/templates/frontend/service.yaml +++ b/templates/frontend/service.yaml @@ -1,7 +1,7 @@ apiVersion: v1 kind: Service metadata: - name: {{ include "vikunja.fullname" . }} + name: {{ include "vikunja.frontendFullname" . }} labels: {{- include "vikunja.labels" . | nindent 4 }} spec: @@ -13,3 +13,6 @@ spec: name: http selector: {{- include "vikunja.frontendSelectorLabels" . | nindent 4 }} + {{- with .Values.frontend.service.extraSpec }} + {{- toYaml . | nindent 2 }} + {{- end }} diff --git a/templates/serviceaccount.yaml b/templates/serviceaccount.yaml index e3f63c2..3cfbcdd 100644 --- a/templates/serviceaccount.yaml +++ b/templates/serviceaccount.yaml @@ -5,6 +5,9 @@ metadata: name: {{ include "vikunja.serviceAccountName" . }} labels: {{- include "vikunja.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.labels }} + {{- toYaml . | nindent 4 }} + {{- end }} {{- with .Values.serviceAccount.annotations }} annotations: {{- toYaml . | nindent 4 }} diff --git a/values.yaml b/values.yaml index f00505d..717beeb 100644 --- a/values.yaml +++ b/values.yaml @@ -10,15 +10,21 @@ serviceAccount: create: true # Annotations to add to the service account annotations: {} + # Extra labels + extraLabels: {} # The name of the service account to use. # If not set and create is true, a name is generated using the fullname template name: "" +# Extra labels that will be added to all resources +extraLabels: {} + # ┬─┐┬─┐┌─┐┌┐┐┌┐┐┬─┐┌┐┐┬─┐ # ├─ │┬┘│ ││││ │ ├─ ││││ │ # ┘ ┘└┘┘─┘┘└┘ ┘ ┴─┘┘└┘┘─┘ frontend: + # Public API URL that client's browser will reach apiUrl: "" replicaCount: 1 @@ -27,11 +33,7 @@ frontend: repository: vikunja/frontend pullPolicy: IfNotPresent # Overrides the image tag whose default is the chart appVersion. - tag: 0.20.2 - - imagePullSecrets: [] - - podAnnotations: {} + tag: "" podSecurityContext: fsGroup: 1000 @@ -47,6 +49,8 @@ frontend: service: type: ClusterIP port: 80 + # If you want to set other fields, like externalName, externalTrafficPolicy, etc. + extraSpec: {} ingress: enabled: false @@ -83,6 +87,18 @@ frontend: targetCPUUtilizationPercentage: 80 # targetMemoryUtilizationPercentage: 80 + initContainers: [] + + sidecarContainers: [] + + # Extra keys to set in deployment.spec. + # Useful if you want to set minReadySeconds, progressDeadlineSeconds, strategy + extraDeploymentSpec: {} + + imagePullSecrets: [] + + podAnnotations: {} + nodeSelector: {} tolerations: [] @@ -115,6 +131,7 @@ frontend: # ┘ ┘┘ ┘ api: + # Values for this config are described here https://vikunja.io/docs/config-options/ config: service: JWTSecret: "" @@ -163,14 +180,7 @@ api: repository: vikunja/api pullPolicy: IfNotPresent # Overrides the image tag whose default is the chart appVersion. - tag: 0.20.1 - - imagePullSecrets: [] - - podAnnotations: {} - - podSecurityContext: {} - # fsGroup: 1000 + tag: "" securityContext: capabilities: @@ -183,6 +193,8 @@ api: service: type: ClusterIP port: 80 + # If you want to set other fields, like externalName, externalTrafficPolicy, etc. + extraSpec: {} ingress: enabled: false @@ -219,6 +231,21 @@ api: targetCPUUtilizationPercentage: 80 # targetMemoryUtilizationPercentage: 80 + initContainers: [] + + sidecarContainers: [] + + # Extra keys to set in deployment.spec. + # Useful if you want to set minReadySeconds, progressDeadlineSeconds, strategy + extraDeploymentSpec: {} + + imagePullSecrets: [] + + podAnnotations: {} + + podSecurityContext: {} + # fsGroup: 1000 + nodeSelector: {} tolerations: [] @@ -261,3 +288,10 @@ postgresql: {} redisEnabled: true # Please refer to Redis subchart for a full list of possible values redis: {} + +# ┬─┐┬─┐┐ ┬ +# │┬┘│─┤│││ +# ┘└┘┘ ┘└┴┘ + +# You can create custom resources from the plaintext definition +raw: []