From 881bade8641de2116ab2fc978f71e31b3ac9a27c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maik=20Scha=CC=88fer?= <maik.schaefer@open-xchange.com> Date: Wed, 5 May 2021 15:58:21 +0200 Subject: [PATCH] add sre ci building blocks to CI and rename helm chart --- .gitlab-ci.yml | 42 ++----------------- .../.helmignore | 0 .../Chart.yaml | 6 +-- .../templates/NOTES.txt | 8 ++-- .../templates/_helpers.tpl | 20 ++++----- .../templates/configMap.yaml | 2 +- .../templates/deployment.yaml | 12 +++--- .../templates/hpa.yaml | 6 +-- .../templates/ingress.yaml | 4 +- .../templates/service.yaml | 6 +-- .../templates/serviceaccount.yaml | 4 +- .../templates/tests/test-connection.yaml | 15 +++++++ .../values.yaml | 4 +- .../templates/tests/test-connection.yaml | 15 ------- 14 files changed, 54 insertions(+), 90 deletions(-) rename helm/{manifest-service => core-manifest-service}/.helmignore (100%) rename helm/{manifest-service => core-manifest-service}/Chart.yaml (92%) rename helm/{manifest-service => core-manifest-service}/templates/NOTES.txt (75%) rename helm/{manifest-service => core-manifest-service}/templates/_helpers.tpl (70%) rename helm/{manifest-service => core-manifest-service}/templates/configMap.yaml (69%) rename helm/{manifest-service => core-manifest-service}/templates/deployment.yaml (80%) rename helm/{manifest-service => core-manifest-service}/templates/hpa.yaml (81%) rename helm/{manifest-service => core-manifest-service}/templates/ingress.yaml (88%) rename helm/{manifest-service => core-manifest-service}/templates/service.yaml (52%) rename helm/{manifest-service => core-manifest-service}/templates/serviceaccount.yaml (62%) create mode 100644 helm/core-manifest-service/templates/tests/test-connection.yaml rename helm/{manifest-service => core-manifest-service}/values.yaml (96%) delete mode 100644 helm/manifest-service/templates/tests/test-connection.yaml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ede05ad..a120bb8 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,42 +1,6 @@ -# Kaniko is used for building images in kubernetes. -# For more information see: https://docs.gitlab.com/ee/ci/docker/using_kaniko.html -build: - stage: build - image: - name: gcr.io/kaniko-project/executor:debug - # entrypoint needs to be overridden see: https://docs.gitlab.com/ee/ci/docker/using_kaniko.html - entrypoint: [""] - script: - - echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json - - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG - tags: - - kubernetes - -upload Helm Chart: - stage: build - image: alpine/helm:3.5.3 - rules: - - if: $CI_MERGE_REQUEST_ID - when: never - - if: '$CI_COMMIT_BRANCH == "main"' - when: on_success - variables: - TAG_NAME: stable - - if: '$CI_COMMIT_BRANCH == "develop"' - when: on_success - variables: - TAG_NAME: latest - script: - - HELM_TAG=$(grep -E -o "(version:)(.*)" helm/manifest-service/Chart.yaml | sed -E 's/.*version:[[:space:]](.*)/\1/g') - - export HELM_EXPERIMENTAL_OCI=1 - - helm registry login registry.open-xchange.com -u "$OX_REGISTRY_USER" -p "$OX_REGISTRY_TOKEN" - - helm chart save helm/manifest-service registry.open-xchange.com//frontend/manifest-service:$TAG_NAME - - helm chart save helm/manifest-service registry.open-xchange.com//frontend/manifest-service - - helm chart push registry.open-xchange.com//frontend/manifest-service:$TAG_NAME - - helm chart push registry.open-xchange.com//frontend/manifest-service:$HELM_TAG - tags: - - kubernetes - +include: + - project: 'sre/ci-building-blocks' + file: '/gitlab-ci/node/kaniko.yml' # Helm is used for deploying everything to kubernetes # Afterwards we do a rolling restart of our deployment diff --git a/helm/manifest-service/.helmignore b/helm/core-manifest-service/.helmignore similarity index 100% rename from helm/manifest-service/.helmignore rename to helm/core-manifest-service/.helmignore diff --git a/helm/manifest-service/Chart.yaml b/helm/core-manifest-service/Chart.yaml similarity index 92% rename from helm/manifest-service/Chart.yaml rename to helm/core-manifest-service/Chart.yaml index 0519f28..96b3468 100644 --- a/helm/manifest-service/Chart.yaml +++ b/helm/core-manifest-service/Chart.yaml @@ -1,6 +1,6 @@ apiVersion: v2 -name: manifest-service -description: A Helm chart for Kubernetes +name: core-manifest-service +description: Helm chart for core manifest service # A chart can be either an 'application' or a 'library' chart. # @@ -15,7 +15,7 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 0.1.0 +version: 0.2.0 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to diff --git a/helm/manifest-service/templates/NOTES.txt b/helm/core-manifest-service/templates/NOTES.txt similarity index 75% rename from helm/manifest-service/templates/NOTES.txt rename to helm/core-manifest-service/templates/NOTES.txt index 3fd9958..091f37d 100644 --- a/helm/manifest-service/templates/NOTES.txt +++ b/helm/core-manifest-service/templates/NOTES.txt @@ -6,16 +6,16 @@ {{- end }} {{- end }} {{- else if contains "NodePort" .Values.service.type }} - export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "manifest-service.fullname" . }}) + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "core-manifest-service.fullname" . }}) export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") echo http://$NODE_IP:$NODE_PORT {{- else if contains "LoadBalancer" .Values.service.type }} NOTE: It may take a few minutes for the LoadBalancer IP to be available. - You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "manifest-service.fullname" . }}' - export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "manifest-service.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") + You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "core-manifest-service.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "core-manifest-service.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") echo http://$SERVICE_IP:{{ .Values.service.port }} {{- else if contains "ClusterIP" .Values.service.type }} - export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "manifest-service.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "core-manifest-service.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}") echo "Visit http://127.0.0.1:8080 to use your application" kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT diff --git a/helm/manifest-service/templates/_helpers.tpl b/helm/core-manifest-service/templates/_helpers.tpl similarity index 70% rename from helm/manifest-service/templates/_helpers.tpl rename to helm/core-manifest-service/templates/_helpers.tpl index b8abf5a..8139242 100644 --- a/helm/manifest-service/templates/_helpers.tpl +++ b/helm/core-manifest-service/templates/_helpers.tpl @@ -1,7 +1,7 @@ {{/* Expand the name of the chart. */}} -{{- define "manifest-service.name" -}} +{{- define "core-manifest-service.name" -}} {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} {{- end }} @@ -10,7 +10,7 @@ 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 "manifest-service.fullname" -}} +{{- define "core-manifest-service.fullname" -}} {{- if .Values.fullnameOverride }} {{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} {{- else }} @@ -26,16 +26,16 @@ If release name contains chart name it will be used as a full name. {{/* Create chart name and version as used by the chart label. */}} -{{- define "manifest-service.chart" -}} +{{- define "core-manifest-service.chart" -}} {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} {{- end }} {{/* Common labels */}} -{{- define "manifest-service.labels" -}} -helm.sh/chart: {{ include "manifest-service.chart" . }} -{{ include "manifest-service.selectorLabels" . }} +{{- define "core-manifest-service.labels" -}} +helm.sh/chart: {{ include "core-manifest-service.chart" . }} +{{ include "core-manifest-service.selectorLabels" . }} {{- if .Chart.AppVersion }} app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} {{- end }} @@ -45,17 +45,17 @@ app.kubernetes.io/managed-by: {{ .Release.Service }} {{/* Selector labels */}} -{{- define "manifest-service.selectorLabels" -}} -app.kubernetes.io/name: {{ include "manifest-service.name" . }} +{{- define "core-manifest-service.selectorLabels" -}} +app.kubernetes.io/name: {{ include "core-manifest-service.name" . }} app.kubernetes.io/instance: {{ .Release.Name }} {{- end }} {{/* Create the name of the service account to use */}} -{{- define "manifest-service.serviceAccountName" -}} +{{- define "core-manifest-service.serviceAccountName" -}} {{- if .Values.serviceAccount.create }} -{{- default (include "manifest-service.fullname" .) .Values.serviceAccount.name }} +{{- default (include "core-manifest-service.fullname" .) .Values.serviceAccount.name }} {{- else }} {{- default "default" .Values.serviceAccount.name }} {{- end }} diff --git a/helm/manifest-service/templates/configMap.yaml b/helm/core-manifest-service/templates/configMap.yaml similarity index 69% rename from helm/manifest-service/templates/configMap.yaml rename to helm/core-manifest-service/templates/configMap.yaml index 3f7f1aa..1d216fe 100644 --- a/helm/manifest-service/templates/configMap.yaml +++ b/helm/core-manifest-service/templates/configMap.yaml @@ -1,7 +1,7 @@ apiVersion: v1 kind: ConfigMap metadata: - name: {{ include "manifest-service.fullname" . }} + name: {{ include "core-manifest-service.fullname" . }} data: urls.yaml: | manifests: diff --git a/helm/manifest-service/templates/deployment.yaml b/helm/core-manifest-service/templates/deployment.yaml similarity index 80% rename from helm/manifest-service/templates/deployment.yaml rename to helm/core-manifest-service/templates/deployment.yaml index 4916eb0..dbff4b1 100644 --- a/helm/manifest-service/templates/deployment.yaml +++ b/helm/core-manifest-service/templates/deployment.yaml @@ -1,16 +1,16 @@ apiVersion: apps/v1 kind: Deployment metadata: - name: {{ include "manifest-service.fullname" . }} + name: {{ include "core-manifest-service.fullname" . }} labels: - {{- include "manifest-service.labels" . | nindent 4 }} + {{- include "core-manifest-service.labels" . | nindent 4 }} spec: {{- if not .Values.autoscaling.enabled }} replicas: {{ .Values.replicaCount }} {{- end }} selector: matchLabels: - {{- include "manifest-service.selectorLabels" . | nindent 6 }} + {{- include "core-manifest-service.selectorLabels" . | nindent 6 }} template: metadata: {{- with .Values.podAnnotations }} @@ -18,13 +18,13 @@ spec: {{- toYaml . | nindent 8 }} {{- end }} labels: - {{- include "manifest-service.selectorLabels" . | nindent 8 }} + {{- include "core-manifest-service.selectorLabels" . | nindent 8 }} spec: {{- with .Values.imagePullSecrets }} imagePullSecrets: {{- toYaml . | nindent 8 }} {{- end }} - serviceAccountName: {{ include "manifest-service.serviceAccountName" . }} + serviceAccountName: {{ include "core-manifest-service.serviceAccountName" . }} securityContext: {{- toYaml .Values.podSecurityContext | nindent 8 }} containers: @@ -53,7 +53,7 @@ spec: volumes: - name: manifest-config configMap: - name: {{ include "manifest-service.fullname" . }} + name: {{ include "core-manifest-service.fullname" . }} {{- with .Values.nodeSelector }} nodeSelector: {{- toYaml . | nindent 8 }} diff --git a/helm/manifest-service/templates/hpa.yaml b/helm/core-manifest-service/templates/hpa.yaml similarity index 81% rename from helm/manifest-service/templates/hpa.yaml rename to helm/core-manifest-service/templates/hpa.yaml index 5476e24..03d4e96 100644 --- a/helm/manifest-service/templates/hpa.yaml +++ b/helm/core-manifest-service/templates/hpa.yaml @@ -2,14 +2,14 @@ apiVersion: autoscaling/v2beta1 kind: HorizontalPodAutoscaler metadata: - name: {{ include "manifest-service.fullname" . }} + name: {{ include "core-manifest-service.fullname" . }} labels: - {{- include "manifest-service.labels" . | nindent 4 }} + {{- include "core-manifest-service.labels" . | nindent 4 }} spec: scaleTargetRef: apiVersion: apps/v1 kind: Deployment - name: {{ include "manifest-service.fullname" . }} + name: {{ include "core-manifest-service.fullname" . }} minReplicas: {{ .Values.autoscaling.minReplicas }} maxReplicas: {{ .Values.autoscaling.maxReplicas }} metrics: diff --git a/helm/manifest-service/templates/ingress.yaml b/helm/core-manifest-service/templates/ingress.yaml similarity index 88% rename from helm/manifest-service/templates/ingress.yaml rename to helm/core-manifest-service/templates/ingress.yaml index e967dd6..fac2ec7 100644 --- a/helm/manifest-service/templates/ingress.yaml +++ b/helm/core-manifest-service/templates/ingress.yaml @@ -1,5 +1,5 @@ {{- if .Values.ingress.enabled -}} -{{- $fullName := include "manifest-service.fullname" . -}} +{{- $fullName := include "core-manifest-service.fullname" . -}} {{- $svcPort := .Values.service.port -}} {{- if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} apiVersion: networking.k8s.io/v1beta1 @@ -10,7 +10,7 @@ kind: Ingress metadata: name: {{ $fullName }} labels: - {{- include "manifest-service.labels" . | nindent 4 }} + {{- include "core-manifest-service.labels" . | nindent 4 }} {{- with .Values.ingress.annotations }} annotations: {{- toYaml . | nindent 4 }} diff --git a/helm/manifest-service/templates/service.yaml b/helm/core-manifest-service/templates/service.yaml similarity index 52% rename from helm/manifest-service/templates/service.yaml rename to helm/core-manifest-service/templates/service.yaml index c7ccf57..551297e 100644 --- a/helm/manifest-service/templates/service.yaml +++ b/helm/core-manifest-service/templates/service.yaml @@ -1,9 +1,9 @@ apiVersion: v1 kind: Service metadata: - name: {{ include "manifest-service.fullname" . }} + name: {{ include "core-manifest-service.fullname" . }} labels: - {{- include "manifest-service.labels" . | nindent 4 }} + {{- include "core-manifest-service.labels" . | nindent 4 }} spec: type: {{ .Values.service.type }} ports: @@ -12,4 +12,4 @@ spec: protocol: TCP name: http selector: - {{- include "manifest-service.selectorLabels" . | nindent 4 }} + {{- include "core-manifest-service.selectorLabels" . | nindent 4 }} diff --git a/helm/manifest-service/templates/serviceaccount.yaml b/helm/core-manifest-service/templates/serviceaccount.yaml similarity index 62% rename from helm/manifest-service/templates/serviceaccount.yaml rename to helm/core-manifest-service/templates/serviceaccount.yaml index aa4ac9b..0397682 100644 --- a/helm/manifest-service/templates/serviceaccount.yaml +++ b/helm/core-manifest-service/templates/serviceaccount.yaml @@ -2,9 +2,9 @@ apiVersion: v1 kind: ServiceAccount metadata: - name: {{ include "manifest-service.serviceAccountName" . }} + name: {{ include "core-manifest-service.serviceAccountName" . }} labels: - {{- include "manifest-service.labels" . | nindent 4 }} + {{- include "core-manifest-service.labels" . | nindent 4 }} {{- with .Values.serviceAccount.annotations }} annotations: {{- toYaml . | nindent 4 }} diff --git a/helm/core-manifest-service/templates/tests/test-connection.yaml b/helm/core-manifest-service/templates/tests/test-connection.yaml new file mode 100644 index 0000000..5694c08 --- /dev/null +++ b/helm/core-manifest-service/templates/tests/test-connection.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "core-manifest-service.fullname" . }}-test-connection" + labels: + {{- include "core-manifest-service.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "core-manifest-service.fullname" . }}:{{ .Values.service.port }}'] + restartPolicy: Never diff --git a/helm/manifest-service/values.yaml b/helm/core-manifest-service/values.yaml similarity index 96% rename from helm/manifest-service/values.yaml rename to helm/core-manifest-service/values.yaml index 4eb6616..1ae3e68 100644 --- a/helm/manifest-service/values.yaml +++ b/helm/core-manifest-service/values.yaml @@ -1,4 +1,4 @@ -# Default values for manifest-service. +# Default values for core-manifest-service. # This is a YAML-formatted file. # Declare variables to be passed into your templates. @@ -7,7 +7,7 @@ replicaCount: 1 containerPort: 8080 image: - repository: gitlab.open-xchange.com:4567/frontend/infrastructure/manifest-service + repository: gitlab.open-xchange.com:4567/frontend/infrastructure/core-manifest-service pullPolicy: IfNotPresent # Overrides the image tag whose default is the chart appVersion. tag: "" diff --git a/helm/manifest-service/templates/tests/test-connection.yaml b/helm/manifest-service/templates/tests/test-connection.yaml deleted file mode 100644 index bfa89bc..0000000 --- a/helm/manifest-service/templates/tests/test-connection.yaml +++ /dev/null @@ -1,15 +0,0 @@ -apiVersion: v1 -kind: Pod -metadata: - name: "{{ include "manifest-service.fullname" . }}-test-connection" - labels: - {{- include "manifest-service.labels" . | nindent 4 }} - annotations: - "helm.sh/hook": test -spec: - containers: - - name: wget - image: busybox - command: ['wget'] - args: ['{{ include "manifest-service.fullname" . }}:{{ .Values.service.port }}'] - restartPolicy: Never -- GitLab