From a0b9e0cdac6ae3c23b35ffe1f393ca71b057a6aa Mon Sep 17 00:00:00 2001 From: Philip Weyer <33149782+philip-weyer@users.noreply.github.com> Date: Tue, 19 Mar 2024 15:10:10 +0100 Subject: [PATCH] [ugc-demo] add chart --- charts/sophora-ugc-demo/Chart.yaml | 12 +++ .../sophora-ugc-demo/templates/_helpers.tpl | 62 ++++++++++++ .../templates/deployment.yaml | 94 +++++++++++++++++++ .../sophora-ugc-demo/templates/ingress.yaml | 38 ++++++++ .../sophora-ugc-demo/templates/service.yaml | 17 ++++ .../sophora-properties-configmap.yaml | 10 ++ .../submitter-properties-configmap.yaml | 9 ++ charts/sophora-ugc-demo/values.yaml | 59 ++++++++++++ 8 files changed, 301 insertions(+) create mode 100644 charts/sophora-ugc-demo/Chart.yaml create mode 100644 charts/sophora-ugc-demo/templates/_helpers.tpl create mode 100644 charts/sophora-ugc-demo/templates/deployment.yaml create mode 100644 charts/sophora-ugc-demo/templates/ingress.yaml create mode 100644 charts/sophora-ugc-demo/templates/service.yaml create mode 100644 charts/sophora-ugc-demo/templates/sophora-properties-configmap.yaml create mode 100644 charts/sophora-ugc-demo/templates/submitter-properties-configmap.yaml create mode 100644 charts/sophora-ugc-demo/values.yaml diff --git a/charts/sophora-ugc-demo/Chart.yaml b/charts/sophora-ugc-demo/Chart.yaml new file mode 100644 index 0000000..31db718 --- /dev/null +++ b/charts/sophora-ugc-demo/Chart.yaml @@ -0,0 +1,12 @@ +apiVersion: v2 +name: sophora-ugc-demo +description: A Helm chart for the UGC demo +type: application + +version: 0.1.0 + +appVersion: 'latest' + +maintainers: + - name: Team Koala + email: team-koala@subshell.com diff --git a/charts/sophora-ugc-demo/templates/_helpers.tpl b/charts/sophora-ugc-demo/templates/_helpers.tpl new file mode 100644 index 0000000..a628933 --- /dev/null +++ b/charts/sophora-ugc-demo/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "ugc-demo.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "ugc-demo.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "ugc-demo.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "ugc-demo.labels" -}} +helm.sh/chart: {{ include "ugc-demo.chart" . }} +{{ include "ugc-demo.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "ugc-demo.selectorLabels" -}} +app.kubernetes.io/name: {{ include "ugc-demo.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "ugc-demo.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "ugc-demo.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/charts/sophora-ugc-demo/templates/deployment.yaml b/charts/sophora-ugc-demo/templates/deployment.yaml new file mode 100644 index 0000000..1d745c1 --- /dev/null +++ b/charts/sophora-ugc-demo/templates/deployment.yaml @@ -0,0 +1,94 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "ugc-demo.fullname" . }} + labels: + {{- include "ugc-demo.labels" . | nindent 4 }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + {{- include "ugc-demo.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + checksum/config: {{ include (print $.Template.BasePath "/sophora-properties-configmap.yaml") . | sha256sum }} + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "ugc-demo.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + initContainers: + - name: config-generator + image: alpine:3.19 + imagePullPolicy: IfNotPresent + env: + - name: SOPHORA_DELIVERY_CLIENT_USERNAME + valueFrom: + secretKeyRef: + key: {{ .Values.sophora.authentication.secret.usernameKey }} + name: {{ .Values.sophora.authentication.secret.name }} + optional: false + - name: SOPHORA_DELIVERY_CLIENT_PASSWORD + valueFrom: + secretKeyRef: + key: {{ .Values.sophora.authentication.secret.passwordKey }} + name: {{ .Values.sophora.authentication.secret.name }} + optional: false + command: [ "/bin/sh" ] + args: + - "-c" + - | + apk update && apk add gettext + mkdir /usr/local/ugc-demo/conf/ + echo "Created conf directory" + envsubst < /usr/local/ugc-demo-template/sophora.properties > /usr/local/ugc-demo/conf/sophora.properties + echo "Generated /usr/local/ugc-demo/conf/sophora.properties from ENV and template" + cp /usr/local/ugc-demo-template/submitter.properties /usr/local/ugc-demo/conf/submitter.properties + echo "Generated /usr/local/ugc-demo/conf/submitter.properties from template" + volumeMounts: + - name: submitter-properties-template + mountPath: /usr/local/ugc-demo-template/submitter.properties + subPath: submitter.properties + - name: sophora-properties-template + mountPath: /usr/local/ugc-demo-template/sophora.properties + subPath: sophora.properties + - name: ugc-demo-config + mountPath: /usr/local/ugc-demo/ + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + volumeMounts: + - name: ugc-demo-config + mountPath: /usr/local/ugc-demo/ + resources: + {{- toYaml .Values.resources | nindent 12 }} + volumes: + - name: ugc-demo-config + emptyDir: {} + - name: submitter-properties-template + configMap: + name: {{ include "ugc-demo.fullname" . }}-submitter-properties + - name: sophora-properties-template + configMap: + name: {{ include "ugc-demo.fullname" . }}-sophora-properties + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/charts/sophora-ugc-demo/templates/ingress.yaml b/charts/sophora-ugc-demo/templates/ingress.yaml new file mode 100644 index 0000000..802cdb4 --- /dev/null +++ b/charts/sophora-ugc-demo/templates/ingress.yaml @@ -0,0 +1,38 @@ +{{- if .Values.ingress.enabled -}} + {{- $fullName := include "ugc-demo.fullname" . -}} +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: {{ $fullName }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if .Values.ingress.ingressClassName }} + ingressClassName: {{ .Values.ingress.ingressClassName }} + {{- end -}} + {{- if .Values.ingress.tls }} + tls: + {{- range .Values.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} + {{- end }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ required "A hostname for the ingress must be provided in .Values.ugc-demo.ingress.host" .host }} + http: + paths: + - path: / + pathType: {{ default "ImplementationSpecific" .pathType }} + backend: + service: + name: {{ $fullName }} + port: + number: 8080 + {{- end }} + {{- end }} diff --git a/charts/sophora-ugc-demo/templates/service.yaml b/charts/sophora-ugc-demo/templates/service.yaml new file mode 100644 index 0000000..d1a299b --- /dev/null +++ b/charts/sophora-ugc-demo/templates/service.yaml @@ -0,0 +1,17 @@ +kind: Service +apiVersion: v1 +metadata: + name: {{ include "ugc-demo.fullname" . }} + labels: + {{- include "ugc-demo.labels" . | nindent 4 }} + {{- with .Values.service.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + selector: {{- include "ugc-demo.selectorLabels" . | nindent 4 }} + type: {{ .Values.service.type }} + ports: + - protocol: TCP + targetPort: 8080 + port: {{ .Values.service.port }} diff --git a/charts/sophora-ugc-demo/templates/sophora-properties-configmap.yaml b/charts/sophora-ugc-demo/templates/sophora-properties-configmap.yaml new file mode 100644 index 0000000..48b2c81 --- /dev/null +++ b/charts/sophora-ugc-demo/templates/sophora-properties-configmap.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "ugc-demo.fullname" . }}-sophora-properties + labels: + {{- include "ugc-demo.labels" . | nindent 4 }} +data: + sophora.properties: |- + + {{ toString (required "A valid sophora.properties configuration needs to be provided." .Values.ugc.demo.sophoraproperties) | nindent 4 }} diff --git a/charts/sophora-ugc-demo/templates/submitter-properties-configmap.yaml b/charts/sophora-ugc-demo/templates/submitter-properties-configmap.yaml new file mode 100644 index 0000000..1648419 --- /dev/null +++ b/charts/sophora-ugc-demo/templates/submitter-properties-configmap.yaml @@ -0,0 +1,9 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "ugc-demo.fullname" . }}-submitter-properties + labels: + {{- include "ugc-demo.labels" . | nindent 4 }} +data: + submitter.properties: |- + {{- toString (required "A valid submitter.properties configuration needs to be provided." .Values.ugc.demo.submitterproperties) | nindent 4 }} diff --git a/charts/sophora-ugc-demo/values.yaml b/charts/sophora-ugc-demo/values.yaml new file mode 100644 index 0000000..f1f1d05 --- /dev/null +++ b/charts/sophora-ugc-demo/values.yaml @@ -0,0 +1,59 @@ +nameOverride: "" +fullnameOverride: "" + +replicaCount: 1 + +image: + repository: docker.subshell.com/ugc/ugc-demo + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "" + +imagePullSecrets: [] + +podAnnotations: {} + +podSecurityContext: {} +# fsGroup: 2000 + +ingress: + enabled: false + ingressClassName: nginx + tls: + hosts: + annotations: {} + +service: + type: ClusterIP + port: 8080 + annotations: {} + +ugc: + demo: + submitterproperties: + + sophoraproperties: + +sophora: + authentication: + secret: + name: secret-name + usernameKey: username + passwordKey: password + +# Additional environment variables can be defined here +env: + +resources: + requests: + cpu: "200m" + memory: "2.5G" + limits: + memory: "2.5G" + + +nodeSelector: {} + +tolerations: [] + +affinity: {}