From a3f6a562c18139f7b2c8dfcbfcdcceb9c6612afd Mon Sep 17 00:00:00 2001 From: Andreas Fritzler Date: Wed, 8 Sep 2021 16:13:35 +0200 Subject: [PATCH] Added helm chart --- charts/template-operator/.helmignore | 23 +++++++ charts/template-operator/Chart.yaml | 13 ++++ charts/template-operator/crds | 1 + .../template-operator/templates/_helpers.tpl | 62 ++++++++++++++++++ .../templates/deployment.yaml | 61 ++++++++++++++++++ charts/template-operator/templates/hpa.yaml | 28 ++++++++ .../templates/leader_election_role.yaml | 37 +++++++++++ .../leader_election_role_binding.yaml | 12 ++++ charts/template-operator/templates/role.yaml | 47 ++++++++++++++ .../templates/role_binding.yaml | 12 ++++ .../template-operator/templates/service.yaml | 15 +++++ .../templates/serviceaccount.yaml | 12 ++++ .../templates/tests/test-connection.yaml | 15 +++++ charts/template-operator/values.yaml | 64 +++++++++++++++++++ 14 files changed, 402 insertions(+) create mode 100644 charts/template-operator/.helmignore create mode 100644 charts/template-operator/Chart.yaml create mode 120000 charts/template-operator/crds create mode 100644 charts/template-operator/templates/_helpers.tpl create mode 100644 charts/template-operator/templates/deployment.yaml create mode 100644 charts/template-operator/templates/hpa.yaml create mode 100644 charts/template-operator/templates/leader_election_role.yaml create mode 100644 charts/template-operator/templates/leader_election_role_binding.yaml create mode 100644 charts/template-operator/templates/role.yaml create mode 100644 charts/template-operator/templates/role_binding.yaml create mode 100644 charts/template-operator/templates/service.yaml create mode 100644 charts/template-operator/templates/serviceaccount.yaml create mode 100644 charts/template-operator/templates/tests/test-connection.yaml create mode 100644 charts/template-operator/values.yaml diff --git a/charts/template-operator/.helmignore b/charts/template-operator/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/charts/template-operator/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/charts/template-operator/Chart.yaml b/charts/template-operator/Chart.yaml new file mode 100644 index 0000000..58ef394 --- /dev/null +++ b/charts/template-operator/Chart.yaml @@ -0,0 +1,13 @@ +apiVersion: v2 +name: template-operator +description: A Helm chart for the template operator +type: application +version: 0.1.0 +appVersion: 0.1.0 +engine: gotpl +home: https://github.com/onmetal/template-operator +sources: +- https://github.com/onmetal/template-operator +maintainers: +- name: adracus +- name: afritzler diff --git a/charts/template-operator/crds b/charts/template-operator/crds new file mode 120000 index 0000000..dad8a57 --- /dev/null +++ b/charts/template-operator/crds @@ -0,0 +1 @@ +../../config/crd/bases \ No newline at end of file diff --git a/charts/template-operator/templates/_helpers.tpl b/charts/template-operator/templates/_helpers.tpl new file mode 100644 index 0000000..05b450f --- /dev/null +++ b/charts/template-operator/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "template-operator.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 "template-operator.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 "template-operator.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "template-operator.labels" -}} +helm.sh/chart: {{ include "template-operator.chart" . }} +{{ include "template-operator.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "template-operator.selectorLabels" -}} +app.kubernetes.io/name: {{ include "template-operator.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "template-operator.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "template-operator.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/charts/template-operator/templates/deployment.yaml b/charts/template-operator/templates/deployment.yaml new file mode 100644 index 0000000..8dbd46a --- /dev/null +++ b/charts/template-operator/templates/deployment.yaml @@ -0,0 +1,61 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "template-operator.fullname" . }} + labels: + {{- include "template-operator.labels" . | nindent 4 }} +spec: + {{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "template-operator.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "template-operator.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "template-operator.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + livenessProbe: + httpGet: + path: /readyz + port: 8081 + initialDelaySeconds: 15 + periodSeconds: 20 + readinessProbe: + httpGet: + path: /healthz + port: 8081 + initialDelaySeconds: 5 + periodSeconds: 10 + resources: + {{- toYaml .Values.resources | nindent 12 }} + {{- 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/template-operator/templates/hpa.yaml b/charts/template-operator/templates/hpa.yaml new file mode 100644 index 0000000..53e293e --- /dev/null +++ b/charts/template-operator/templates/hpa.yaml @@ -0,0 +1,28 @@ +{{- if .Values.autoscaling.enabled }} +apiVersion: autoscaling/v2beta1 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "template-operator.fullname" . }} + labels: + {{- include "template-operator.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "template-operator.fullname" . }} + minReplicas: {{ .Values.autoscaling.minReplicas }} + maxReplicas: {{ .Values.autoscaling.maxReplicas }} + metrics: + {{- if .Values.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} +{{- end }} diff --git a/charts/template-operator/templates/leader_election_role.yaml b/charts/template-operator/templates/leader_election_role.yaml new file mode 100644 index 0000000..4190ec8 --- /dev/null +++ b/charts/template-operator/templates/leader_election_role.yaml @@ -0,0 +1,37 @@ +# permissions to do leader election. +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: leader-election-role +rules: +- apiGroups: + - "" + resources: + - configmaps + verbs: + - get + - list + - watch + - create + - update + - patch + - delete +- apiGroups: + - coordination.k8s.io + resources: + - leases + verbs: + - get + - list + - watch + - create + - update + - patch + - delete +- apiGroups: + - "" + resources: + - events + verbs: + - create + - patch diff --git a/charts/template-operator/templates/leader_election_role_binding.yaml b/charts/template-operator/templates/leader_election_role_binding.yaml new file mode 100644 index 0000000..8811f08 --- /dev/null +++ b/charts/template-operator/templates/leader_election_role_binding.yaml @@ -0,0 +1,12 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: leader-election-rolebinding +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: leader-election-role +subjects: +- kind: ServiceAccount + name: {{ include "template-operator.serviceAccountName" . }} + namespace: {{ .Release.Namespace }} diff --git a/charts/template-operator/templates/role.yaml b/charts/template-operator/templates/role.yaml new file mode 100644 index 0000000..722bec3 --- /dev/null +++ b/charts/template-operator/templates/role.yaml @@ -0,0 +1,47 @@ +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + creationTimestamp: null + name: manager-role +rules: +{{- range .Values.rbac.adminGroupResouces }} +- apiGroups: +{{ .groups | toYaml | indent 4 }} + resources: +{{ .resources | toYaml | indent 4 }} + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +{{- end }} +- apiGroups: + - template.onmetal.de + resources: + - templates + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - template.onmetal.de + resources: + - templates/finalizers + verbs: + - update +- apiGroups: + - template.onmetal.de + resources: + - templates/status + verbs: + - get + - patch + - update diff --git a/charts/template-operator/templates/role_binding.yaml b/charts/template-operator/templates/role_binding.yaml new file mode 100644 index 0000000..f9d7003 --- /dev/null +++ b/charts/template-operator/templates/role_binding.yaml @@ -0,0 +1,12 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: manager-rolebinding +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: manager-role +subjects: +- kind: ServiceAccount + name: {{ include "template-operator.serviceAccountName" . }} + namespace: {{ .Release.Namespace }} diff --git a/charts/template-operator/templates/service.yaml b/charts/template-operator/templates/service.yaml new file mode 100644 index 0000000..fd1b9c4 --- /dev/null +++ b/charts/template-operator/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "template-operator.fullname" . }} + labels: + {{- include "template-operator.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + {{- include "template-operator.selectorLabels" . | nindent 4 }} diff --git a/charts/template-operator/templates/serviceaccount.yaml b/charts/template-operator/templates/serviceaccount.yaml new file mode 100644 index 0000000..f6938f5 --- /dev/null +++ b/charts/template-operator/templates/serviceaccount.yaml @@ -0,0 +1,12 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "template-operator.serviceAccountName" . }} + labels: + {{- include "template-operator.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/charts/template-operator/templates/tests/test-connection.yaml b/charts/template-operator/templates/tests/test-connection.yaml new file mode 100644 index 0000000..d0db600 --- /dev/null +++ b/charts/template-operator/templates/tests/test-connection.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "template-operator.fullname" . }}-test-connection" + labels: + {{- include "template-operator.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "template-operator.fullname" . }}:{{ .Values.service.port }}'] + restartPolicy: Never diff --git a/charts/template-operator/values.yaml b/charts/template-operator/values.yaml new file mode 100644 index 0000000..88ab22b --- /dev/null +++ b/charts/template-operator/values.yaml @@ -0,0 +1,64 @@ +replicaCount: 1 + +rbac: + adminGroupResouces: + - groups: + - "" + resources: + - secrets + +image: + repository: ghcr.io/onmetal/template-operator + pullPolicy: IfNotPresent + tag: latest + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + # Specifies whether a service account should be created + create: true + # Annotations to add to the service account + annotations: {} + # The name of the service account to use. + # If not set and create is true, a name is generated using the fullname template + name: "" + +podAnnotations: {} + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +service: + type: ClusterIP + port: 80 + +resources: {} + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + +nodeSelector: {} + +tolerations: [] + +affinity: {}