From b805908a45ba4ca0260aee34e007af53737cea7d Mon Sep 17 00:00:00 2001 From: "Ware, Joseph (DLSLtd,RAL,LSCI)" Date: Thu, 19 Dec 2024 16:13:02 +0000 Subject: [PATCH 01/11] Naive helm create --- numtracker/.helmignore | 23 ++++ numtracker/Chart.yaml | 24 ++++ numtracker/templates/NOTES.txt | 22 ++++ numtracker/templates/_helpers.tpl | 62 +++++++++ numtracker/templates/deployment.yaml | 68 ++++++++++ numtracker/templates/hpa.yaml | 32 +++++ numtracker/templates/ingress.yaml | 43 ++++++ numtracker/templates/service.yaml | 15 +++ numtracker/templates/serviceaccount.yaml | 13 ++ .../templates/tests/test-connection.yaml | 15 +++ numtracker/values.yaml | 123 ++++++++++++++++++ 11 files changed, 440 insertions(+) create mode 100644 numtracker/.helmignore create mode 100644 numtracker/Chart.yaml create mode 100644 numtracker/templates/NOTES.txt create mode 100644 numtracker/templates/_helpers.tpl create mode 100644 numtracker/templates/deployment.yaml create mode 100644 numtracker/templates/hpa.yaml create mode 100644 numtracker/templates/ingress.yaml create mode 100644 numtracker/templates/service.yaml create mode 100644 numtracker/templates/serviceaccount.yaml create mode 100644 numtracker/templates/tests/test-connection.yaml create mode 100644 numtracker/values.yaml diff --git a/numtracker/.helmignore b/numtracker/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/numtracker/.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/numtracker/Chart.yaml b/numtracker/Chart.yaml new file mode 100644 index 0000000..291ad0c --- /dev/null +++ b/numtracker/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: numtracker +description: Helm chart to deploy the numtracker service for unifying beamline filenaming + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +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 + +# 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 +# follow Semantic Versioning. They should reflect the version the application is using. +# It is recommended to use it with quotes. +appVersion: "0.1.0" diff --git a/numtracker/templates/NOTES.txt b/numtracker/templates/NOTES.txt new file mode 100644 index 0000000..b436d62 --- /dev/null +++ b/numtracker/templates/NOTES.txt @@ -0,0 +1,22 @@ +1. Get the application URL by running these commands: +{{- if .Values.ingress.enabled }} +{{- range $host := .Values.ingress.hosts }} + {{- range .paths }} + http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }} + {{- 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 "numtracker.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 its status by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "numtracker.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "numtracker.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 "numtracker.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 +{{- end }} diff --git a/numtracker/templates/_helpers.tpl b/numtracker/templates/_helpers.tpl new file mode 100644 index 0000000..f056e15 --- /dev/null +++ b/numtracker/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "numtracker.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 "numtracker.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 "numtracker.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "numtracker.labels" -}} +helm.sh/chart: {{ include "numtracker.chart" . }} +{{ include "numtracker.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "numtracker.selectorLabels" -}} +app.kubernetes.io/name: {{ include "numtracker.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "numtracker.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "numtracker.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/numtracker/templates/deployment.yaml b/numtracker/templates/deployment.yaml new file mode 100644 index 0000000..9397d91 --- /dev/null +++ b/numtracker/templates/deployment.yaml @@ -0,0 +1,68 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "numtracker.fullname" . }} + labels: + {{- include "numtracker.labels" . | nindent 4 }} +spec: + {{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "numtracker.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "numtracker.labels" . | nindent 8 }} + {{- with .Values.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "numtracker.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 }} + ports: + - name: http + containerPort: {{ .Values.service.port }} + protocol: TCP + livenessProbe: + {{- toYaml .Values.livenessProbe | nindent 12 }} + readinessProbe: + {{- toYaml .Values.readinessProbe | nindent 12 }} + resources: + {{- toYaml .Values.resources | nindent 12 }} + {{- with .Values.volumeMounts }} + volumeMounts: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.volumes }} + volumes: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- 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/numtracker/templates/hpa.yaml b/numtracker/templates/hpa.yaml new file mode 100644 index 0000000..aaf44ab --- /dev/null +++ b/numtracker/templates/hpa.yaml @@ -0,0 +1,32 @@ +{{- if .Values.autoscaling.enabled }} +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "numtracker.fullname" . }} + labels: + {{- include "numtracker.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "numtracker.fullname" . }} + minReplicas: {{ .Values.autoscaling.minReplicas }} + maxReplicas: {{ .Values.autoscaling.maxReplicas }} + metrics: + {{- if .Values.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + target: + type: Utilization + averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} +{{- end }} diff --git a/numtracker/templates/ingress.yaml b/numtracker/templates/ingress.yaml new file mode 100644 index 0000000..b3228cf --- /dev/null +++ b/numtracker/templates/ingress.yaml @@ -0,0 +1,43 @@ +{{- if .Values.ingress.enabled -}} +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: {{ include "numtracker.fullname" . }} + labels: + {{- include "numtracker.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- with .Values.ingress.className }} + 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: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ .path }} + {{- with .pathType }} + pathType: {{ . }} + {{- end }} + backend: + service: + name: {{ include "numtracker.fullname" $ }} + port: + number: {{ $.Values.service.port }} + {{- end }} + {{- end }} +{{- end }} diff --git a/numtracker/templates/service.yaml b/numtracker/templates/service.yaml new file mode 100644 index 0000000..5aaf2c2 --- /dev/null +++ b/numtracker/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "numtracker.fullname" . }} + labels: + {{- include "numtracker.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + {{- include "numtracker.selectorLabels" . | nindent 4 }} diff --git a/numtracker/templates/serviceaccount.yaml b/numtracker/templates/serviceaccount.yaml new file mode 100644 index 0000000..18cea03 --- /dev/null +++ b/numtracker/templates/serviceaccount.yaml @@ -0,0 +1,13 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "numtracker.serviceAccountName" . }} + labels: + {{- include "numtracker.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +automountServiceAccountToken: {{ .Values.serviceAccount.automount }} +{{- end }} diff --git a/numtracker/templates/tests/test-connection.yaml b/numtracker/templates/tests/test-connection.yaml new file mode 100644 index 0000000..9695c1c --- /dev/null +++ b/numtracker/templates/tests/test-connection.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "numtracker.fullname" . }}-test-connection" + labels: + {{- include "numtracker.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "numtracker.fullname" . }}:{{ .Values.service.port }}'] + restartPolicy: Never diff --git a/numtracker/values.yaml b/numtracker/values.yaml new file mode 100644 index 0000000..c6fc09f --- /dev/null +++ b/numtracker/values.yaml @@ -0,0 +1,123 @@ +# Default values for numtracker. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +# This will set the replicaset count more information can be found here: https://kubernetes.io/docs/concepts/workloads/controllers/replicaset/ +replicaCount: 1 + +# This sets the container image more information can be found here: https://kubernetes.io/docs/concepts/containers/images/ +image: + repository: ghcr.io/diamondlightsource/numtracker + # This sets the pull policy for images. + pullPolicy: Always + # Overrides the image tag whose default is the chart appVersion. + tag: "" + +# This is for the secretes for pulling an image from a private repository more information can be found here: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/ +imagePullSecrets: [] +# This is to override the chart name. +nameOverride: "" +fullnameOverride: "" + +#This section builds out the service account more information can be found here: https://kubernetes.io/docs/concepts/security/service-accounts/ +serviceAccount: + # Specifies whether a service account should be created + create: true + # Automatically mount a ServiceAccount's API credentials? + automount: 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: "" + +# This is for setting Kubernetes Annotations to a Pod. +# For more information checkout: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/ +podAnnotations: {} +# This is for setting Kubernetes Labels to a Pod. +# For more information checkout: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/ +podLabels: {} + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +# This is for setting up a service more information can be found here: https://kubernetes.io/docs/concepts/services-networking/service/ +service: + # This sets the service type more information can be found here: https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types + type: ClusterIP + # This sets the ports more information can be found here: https://kubernetes.io/docs/concepts/services-networking/service/#field-spec-ports + port: 80 + +# This block is for setting up the ingress for more information can be found here: https://kubernetes.io/docs/concepts/services-networking/ingress/ +ingress: + enabled: false + className: "" + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: + - path: / + pathType: ImplementationSpecific + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +# This is to setup the liveness and readiness probes more information can be found here: https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/ +livenessProbe: + httpGet: + path: / + port: http +readinessProbe: + httpGet: + path: / + port: http + +#This section is for setting up autoscaling more information can be found here: https://kubernetes.io/docs/concepts/workloads/autoscaling/ +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + +# Additional volumes on the output Deployment definition. +volumes: [] +# - name: foo +# secret: +# secretName: mysecret +# optional: false + +# Additional volumeMounts on the output Deployment definition. +volumeMounts: [] +# - name: foo +# mountPath: "/etc/foo" +# readOnly: true + +nodeSelector: {} + +tolerations: [] + +affinity: {} From 520f3d30d3a3f3d87b723ff1f5d5721f65c74c00 Mon Sep 17 00:00:00 2001 From: "Ware, Joseph (DLSLtd,RAL,LSCI)" Date: Thu, 19 Dec 2024 16:15:37 +0000 Subject: [PATCH 02/11] Add publish actions --- .github/workflows/publish.yaml | 47 ++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 8c86123..dd39876 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -15,6 +15,23 @@ jobs: build: runs-on: ubuntu-latest steps: + + # Validate that the Image is published with a tag that is a valid SemVer, required by Helm chart + - name: Validate SemVer2 version compliance + if: startsWith(github.ref, 'refs/tags/') + env: + SEMVER_REGEX: ^v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$ + + run: | + ref="${{ github.ref_name }}" + my_regex="${{env.SEMVER_REGEX}}" + if [[ "$ref" =~ $my_regex ]]; then + echo "SemVer compliant version: $ref" + else + echo "Invalid SemVer version: $ref" + exit 1 + fi + - name: Checkout uses: actions/checkout@v4 @@ -59,3 +76,33 @@ jobs: labels: ${{ steps.meta.outputs.labels }} annotations: ${{ steps.meta.outputs.annotations }} push: true + + + build-and-publish-chart: + runs-on: ubuntu-latest + needs: build-and-push-image + steps: + - name: checkout repo + uses: actions/checkout@v3 + + - name: install helm + uses: Azure/setup-helm@v3 + with: + token: ${{ secrets.GITHUB_TOKEN }} + id: install + + - name: login to gcr using helm + run: | + echo ${{ secrets.GITHUB_TOKEN }} | helm registry login ${{ env.GCR_IMAGE }} --username ${{ github.repository_owner }} --password-stdin + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@57396166ad8aefe6098280995947635806a0e6ea + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=ref,event=tag + - name: package chart and push it + run: | + helm dependencies update helm/numtracker + helm package helm/numtracker --version ${GITHUB_REF##*/?(v)} --app-version ${GITHUB_REF##*/} -d /tmp/ + helm push /tmp/numtracker-${GITHUB_REF##*/?(v)}.tgz oci://ghcr.io/diamondlightsource/charts From d32180d004ead8c3bac5dca1d26eadc680fec924 Mon Sep 17 00:00:00 2001 From: "Ware, Joseph (DLSLtd,RAL,LSCI)" Date: Mon, 6 Jan 2025 13:29:14 +0000 Subject: [PATCH 03/11] Move semver check into docker metadata job --- .github/workflows/publish.yaml | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index dd39876..706bd98 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -15,23 +15,6 @@ jobs: build: runs-on: ubuntu-latest steps: - - # Validate that the Image is published with a tag that is a valid SemVer, required by Helm chart - - name: Validate SemVer2 version compliance - if: startsWith(github.ref, 'refs/tags/') - env: - SEMVER_REGEX: ^v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$ - - run: | - ref="${{ github.ref_name }}" - my_regex="${{env.SEMVER_REGEX}}" - if [[ "$ref" =~ $my_regex ]]; then - echo "SemVer compliant version: $ref" - else - echo "Invalid SemVer version: $ref" - exit 1 - fi - - name: Checkout uses: actions/checkout@v4 From 4e0a5211584a52504c4e19822328e4d07d6ff4ef Mon Sep 17 00:00:00 2001 From: "Ware, Joseph (DLSLtd,RAL,LSCI)" Date: Mon, 6 Jan 2025 13:32:34 +0000 Subject: [PATCH 04/11] Re-use metadata from docker image build for Helm chart publish --- .github/workflows/publish.yaml | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 706bd98..e2b79e4 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -12,7 +12,7 @@ on: pull_request: jobs: - build: + build-image: runs-on: ubuntu-latest steps: - name: Checkout @@ -60,14 +60,6 @@ jobs: annotations: ${{ steps.meta.outputs.annotations }} push: true - - build-and-publish-chart: - runs-on: ubuntu-latest - needs: build-and-push-image - steps: - - name: checkout repo - uses: actions/checkout@v3 - - name: install helm uses: Azure/setup-helm@v3 with: @@ -77,15 +69,9 @@ jobs: - name: login to gcr using helm run: | echo ${{ secrets.GITHUB_TOKEN }} | helm registry login ${{ env.GCR_IMAGE }} --username ${{ github.repository_owner }} --password-stdin - - name: Extract metadata (tags, labels) for Docker - id: meta - uses: docker/metadata-action@57396166ad8aefe6098280995947635806a0e6ea - with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - tags: | - type=ref,event=tag + - name: package chart and push it run: | helm dependencies update helm/numtracker - helm package helm/numtracker --version ${GITHUB_REF##*/?(v)} --app-version ${GITHUB_REF##*/} -d /tmp/ - helm push /tmp/numtracker-${GITHUB_REF##*/?(v)}.tgz oci://ghcr.io/diamondlightsource/charts + helm package helm/numtracker --version ${{ steps.meta.outputs.version }} --app-version ${{ steps.meta.outputs.version }} -d /tmp/ + helm push /tmp/numtracker-${{ steps.meta.outputs.version }}.tgz oci://ghcr.io/diamondlightsource/charts From d3b2c5d13097877cc7585022ab03350e47a87519 Mon Sep 17 00:00:00 2001 From: "Ware, Joseph (DLSLtd,RAL,LSCI)" Date: Mon, 6 Jan 2025 13:39:43 +0000 Subject: [PATCH 05/11] Remove env var expectation --- .github/workflows/publish.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index e2b79e4..cd4ebbd 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -68,7 +68,7 @@ jobs: - name: login to gcr using helm run: | - echo ${{ secrets.GITHUB_TOKEN }} | helm registry login ${{ env.GCR_IMAGE }} --username ${{ github.repository_owner }} --password-stdin + echo ${{ secrets.GITHUB_TOKEN }} | helm registry login ghcr.io/${{ github.repository }} --username ${{ github.repository_owner }} --password-stdin - name: package chart and push it run: | From 62451b6d511438bfcdd15d4c71ca56ffbae32c4d Mon Sep 17 00:00:00 2001 From: "Ware, Joseph (DLSLtd,RAL,LSCI)" Date: Mon, 6 Jan 2025 13:44:35 +0000 Subject: [PATCH 06/11] Move helm chart into subdirectory --- {numtracker => helm/numtracker}/.helmignore | 0 {numtracker => helm/numtracker}/Chart.yaml | 0 {numtracker => helm/numtracker}/templates/NOTES.txt | 0 {numtracker => helm/numtracker}/templates/_helpers.tpl | 0 {numtracker => helm/numtracker}/templates/deployment.yaml | 0 {numtracker => helm/numtracker}/templates/hpa.yaml | 0 {numtracker => helm/numtracker}/templates/ingress.yaml | 0 {numtracker => helm/numtracker}/templates/service.yaml | 0 {numtracker => helm/numtracker}/templates/serviceaccount.yaml | 0 .../numtracker}/templates/tests/test-connection.yaml | 0 {numtracker => helm/numtracker}/values.yaml | 0 11 files changed, 0 insertions(+), 0 deletions(-) rename {numtracker => helm/numtracker}/.helmignore (100%) rename {numtracker => helm/numtracker}/Chart.yaml (100%) rename {numtracker => helm/numtracker}/templates/NOTES.txt (100%) rename {numtracker => helm/numtracker}/templates/_helpers.tpl (100%) rename {numtracker => helm/numtracker}/templates/deployment.yaml (100%) rename {numtracker => helm/numtracker}/templates/hpa.yaml (100%) rename {numtracker => helm/numtracker}/templates/ingress.yaml (100%) rename {numtracker => helm/numtracker}/templates/service.yaml (100%) rename {numtracker => helm/numtracker}/templates/serviceaccount.yaml (100%) rename {numtracker => helm/numtracker}/templates/tests/test-connection.yaml (100%) rename {numtracker => helm/numtracker}/values.yaml (100%) diff --git a/numtracker/.helmignore b/helm/numtracker/.helmignore similarity index 100% rename from numtracker/.helmignore rename to helm/numtracker/.helmignore diff --git a/numtracker/Chart.yaml b/helm/numtracker/Chart.yaml similarity index 100% rename from numtracker/Chart.yaml rename to helm/numtracker/Chart.yaml diff --git a/numtracker/templates/NOTES.txt b/helm/numtracker/templates/NOTES.txt similarity index 100% rename from numtracker/templates/NOTES.txt rename to helm/numtracker/templates/NOTES.txt diff --git a/numtracker/templates/_helpers.tpl b/helm/numtracker/templates/_helpers.tpl similarity index 100% rename from numtracker/templates/_helpers.tpl rename to helm/numtracker/templates/_helpers.tpl diff --git a/numtracker/templates/deployment.yaml b/helm/numtracker/templates/deployment.yaml similarity index 100% rename from numtracker/templates/deployment.yaml rename to helm/numtracker/templates/deployment.yaml diff --git a/numtracker/templates/hpa.yaml b/helm/numtracker/templates/hpa.yaml similarity index 100% rename from numtracker/templates/hpa.yaml rename to helm/numtracker/templates/hpa.yaml diff --git a/numtracker/templates/ingress.yaml b/helm/numtracker/templates/ingress.yaml similarity index 100% rename from numtracker/templates/ingress.yaml rename to helm/numtracker/templates/ingress.yaml diff --git a/numtracker/templates/service.yaml b/helm/numtracker/templates/service.yaml similarity index 100% rename from numtracker/templates/service.yaml rename to helm/numtracker/templates/service.yaml diff --git a/numtracker/templates/serviceaccount.yaml b/helm/numtracker/templates/serviceaccount.yaml similarity index 100% rename from numtracker/templates/serviceaccount.yaml rename to helm/numtracker/templates/serviceaccount.yaml diff --git a/numtracker/templates/tests/test-connection.yaml b/helm/numtracker/templates/tests/test-connection.yaml similarity index 100% rename from numtracker/templates/tests/test-connection.yaml rename to helm/numtracker/templates/tests/test-connection.yaml diff --git a/numtracker/values.yaml b/helm/numtracker/values.yaml similarity index 100% rename from numtracker/values.yaml rename to helm/numtracker/values.yaml From d1e3fd440dd4dd32aa4b15683c3e6ecbebc98d94 Mon Sep 17 00:00:00 2001 From: "Ware, Joseph (DLSLtd,RAL,LSCI)" Date: Mon, 6 Jan 2025 13:49:15 +0000 Subject: [PATCH 07/11] Conditionally only attempt to publish --- .github/workflows/publish.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index cd4ebbd..bd0ac3b 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -49,7 +49,6 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} - name: Publish image - if: ${{ github.event_name == 'push' && github.ref_type == 'tag' }} uses: docker/build-push-action@v6 env: DOCKER_BUILD_RECORD_UPLOAD: false @@ -58,7 +57,8 @@ jobs: tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} annotations: ${{ steps.meta.outputs.annotations }} - push: true + push: ${{ github.event_name == 'push' && github.ref_type == 'tag' }} + - name: install helm uses: Azure/setup-helm@v3 @@ -67,10 +67,12 @@ jobs: id: install - name: login to gcr using helm + if: ${{ github.event_name == 'push' && github.ref_type == 'tag' }} run: | echo ${{ secrets.GITHUB_TOKEN }} | helm registry login ghcr.io/${{ github.repository }} --username ${{ github.repository_owner }} --password-stdin - name: package chart and push it + if: ${{ github.event_name == 'push' && github.ref_type == 'tag' }} run: | helm dependencies update helm/numtracker helm package helm/numtracker --version ${{ steps.meta.outputs.version }} --app-version ${{ steps.meta.outputs.version }} -d /tmp/ From 47fdec230f2531952d2248bf73950af8ad919928 Mon Sep 17 00:00:00 2001 From: "Ware, Joseph (DLSLtd,RAL,LSCI)" Date: Mon, 6 Jan 2025 14:01:35 +0000 Subject: [PATCH 08/11] Grammar, spelling --- .github/workflows/publish.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index bd0ac3b..5c121c1 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -12,7 +12,7 @@ on: pull_request: jobs: - build-image: + build: runs-on: ubuntu-latest steps: - name: Checkout @@ -60,18 +60,18 @@ jobs: push: ${{ github.event_name == 'push' && github.ref_type == 'tag' }} - - name: install helm + - name: Install Helm uses: Azure/setup-helm@v3 with: token: ${{ secrets.GITHUB_TOKEN }} id: install - - name: login to gcr using helm + - name: Helm login to GHCR if: ${{ github.event_name == 'push' && github.ref_type == 'tag' }} run: | echo ${{ secrets.GITHUB_TOKEN }} | helm registry login ghcr.io/${{ github.repository }} --username ${{ github.repository_owner }} --password-stdin - - name: package chart and push it + - name: Package and push chart if: ${{ github.event_name == 'push' && github.ref_type == 'tag' }} run: | helm dependencies update helm/numtracker From 76c885446715bcb02c898e094ad4f7cf7565efc6 Mon Sep 17 00:00:00 2001 From: Peter Holloway Date: Tue, 7 Jan 2025 11:40:32 +0000 Subject: [PATCH 09/11] Convert deployment to statefulset and add env vars --- .../{deployment.yaml => statefulset.yaml} | 30 +++++++++-- helm/numtracker/templates/storage.yaml | 10 ++++ helm/numtracker/values.yaml | 53 ++++++++++++------- 3 files changed, 72 insertions(+), 21 deletions(-) rename helm/numtracker/templates/{deployment.yaml => statefulset.yaml} (63%) create mode 100644 helm/numtracker/templates/storage.yaml diff --git a/helm/numtracker/templates/deployment.yaml b/helm/numtracker/templates/statefulset.yaml similarity index 63% rename from helm/numtracker/templates/deployment.yaml rename to helm/numtracker/templates/statefulset.yaml index 9397d91..58e14f5 100644 --- a/helm/numtracker/templates/deployment.yaml +++ b/helm/numtracker/templates/statefulset.yaml @@ -1,5 +1,5 @@ apiVersion: apps/v1 -kind: Deployment +kind: StatefulSet metadata: name: {{ include "numtracker.fullname" . }} labels: @@ -32,6 +32,25 @@ spec: {{- toYaml .Values.podSecurityContext | nindent 8 }} containers: - name: {{ .Chart.Name }} + env: + - name: NUMTRACKER_DB + value: {{ .Values.numtracker.storage.mount }}/{{ .Values.numtracker.db.fileName }} + - name: NUMTRACKER_PORT + value: "{{- .Values.service.port -}}" + {{- if .Values.numtracker.tracing.enabled }} + - name: NUMTRACKER_TRACING + value: {{ .Values.numtracker.tracing.host }} + - name: NUMTRACKER_TRACING_LEVEL + value: {{ .Values.numtracker.tracing.level }} + {{- end }} + {{- if .Values.numtracker.auth.enabled }} + - name: NUMTRACKER_AUTH_HOST + value: {{ .Values.numtracker.auth.host }} + - name: NUMTRACKER_AUTH_ACCESS + value: {{ .Values.numtracker.auth.access }} + - name: NUMTRACKER_AUTH_ADMIN + value: {{ .Values.numtracker.auth.admin }} + {{- end }} securityContext: {{- toYaml .Values.securityContext | nindent 12 }} image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" @@ -46,12 +65,17 @@ spec: {{- toYaml .Values.readinessProbe | nindent 12 }} resources: {{- toYaml .Values.resources | nindent 12 }} - {{- with .Values.volumeMounts }} volumeMounts: + - name: numtracker-data + mountPath: /data + {{- with .Values.extraVolumeMounts }} {{- toYaml . | nindent 12 }} {{- end }} - {{- with .Values.volumes }} volumes: + - name: numtracker-data + persistentVolumeClaim: + claimName: {{ .Values.numtracker.storage.claimName }} + {{- with .Values.extraVolumes }} {{- toYaml . | nindent 8 }} {{- end }} {{- with .Values.nodeSelector }} diff --git a/helm/numtracker/templates/storage.yaml b/helm/numtracker/templates/storage.yaml new file mode 100644 index 0000000..0edfe27 --- /dev/null +++ b/helm/numtracker/templates/storage.yaml @@ -0,0 +1,10 @@ +kind: PersistentVolumeClaim +apiVersion: v1 +metadata: + name: {{ .Values.numtracker.storage.claimName }} +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: {{ .Values.numtracker.storage.size }} diff --git a/helm/numtracker/values.yaml b/helm/numtracker/values.yaml index c6fc09f..b1b7870 100644 --- a/helm/numtracker/values.yaml +++ b/helm/numtracker/values.yaml @@ -13,6 +13,25 @@ image: # Overrides the image tag whose default is the chart appVersion. tag: "" +numtracker: + db: + fileName: numtracker.db + storage: + claimName: daq-numtracker-db-volume + mount: /data + size: 50M + tracing: + enabled: false + host: "https://jaeger.diamond.ac.uk" + level: DEBUG + auth: + enabled: false + host: authz.diamond.ac.uk + admin: /v1/data/diamond/policy/admin/configure_beamline + access: /v1/data/diamond/policy/session/write_to_beamline_visit + + + # This is for the secretes for pulling an image from a private repository more information can be found here: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/ imagePullSecrets: [] # This is to override the chart name. @@ -22,7 +41,7 @@ fullnameOverride: "" #This section builds out the service account more information can be found here: https://kubernetes.io/docs/concepts/security/service-accounts/ serviceAccount: # Specifies whether a service account should be created - create: true + create: false # Automatically mount a ServiceAccount's API credentials? automount: true # Annotations to add to the service account @@ -32,7 +51,7 @@ serviceAccount: name: "" # This is for setting Kubernetes Annotations to a Pod. -# For more information checkout: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/ +# For more information checkout: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/ podAnnotations: {} # This is for setting Kubernetes Labels to a Pod. # For more information checkout: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/ @@ -86,35 +105,33 @@ resources: {} # memory: 128Mi # This is to setup the liveness and readiness probes more information can be found here: https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/ -livenessProbe: - httpGet: - path: / - port: http -readinessProbe: - httpGet: - path: / - port: http +livenessProbe: {} + # httpGet: + # path: / + # port: http +readinessProbe: {} + # httpGet: + # path: / + # port: http #This section is for setting up autoscaling more information can be found here: https://kubernetes.io/docs/concepts/workloads/autoscaling/ autoscaling: enabled: false minReplicas: 1 - maxReplicas: 100 + maxReplicas: 3 targetCPUUtilizationPercentage: 80 # targetMemoryUtilizationPercentage: 80 -# Additional volumes on the output Deployment definition. -volumes: [] +# Additional volumes for GDA var directories +extraVolumes: [] + # - name: foo # secret: # secretName: mysecret # optional: false -# Additional volumeMounts on the output Deployment definition. -volumeMounts: [] -# - name: foo -# mountPath: "/etc/foo" -# readOnly: true +# Additional volumeMounts for GDA var directories +extraVolumeMounts: [] nodeSelector: {} From 9afd50cf3d428b00b9dfbfd3e1f731c9bf077642 Mon Sep 17 00:00:00 2001 From: Peter Holloway Date: Tue, 7 Jan 2025 14:33:45 +0000 Subject: [PATCH 10/11] Use status endpoint for livenessProbe --- helm/numtracker/values.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/helm/numtracker/values.yaml b/helm/numtracker/values.yaml index b1b7870..58b40f3 100644 --- a/helm/numtracker/values.yaml +++ b/helm/numtracker/values.yaml @@ -105,10 +105,10 @@ resources: {} # memory: 128Mi # This is to setup the liveness and readiness probes more information can be found here: https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/ -livenessProbe: {} - # httpGet: - # path: / - # port: http +livenessProbe: + httpGet: + path: /status + port: http readinessProbe: {} # httpGet: # path: / From 429854d3726ac85035b6670aa0ad614e5f68b3fa Mon Sep 17 00:00:00 2001 From: "Ware, Joseph (DLSLtd,RAL,LSCI)" Date: Tue, 7 Jan 2025 15:56:24 +0000 Subject: [PATCH 11/11] Autoscale as correct resource type --- helm/numtracker/templates/hpa.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helm/numtracker/templates/hpa.yaml b/helm/numtracker/templates/hpa.yaml index aaf44ab..3ef1f39 100644 --- a/helm/numtracker/templates/hpa.yaml +++ b/helm/numtracker/templates/hpa.yaml @@ -8,7 +8,7 @@ metadata: spec: scaleTargetRef: apiVersion: apps/v1 - kind: Deployment + kind: StatefulSet name: {{ include "numtracker.fullname" . }} minReplicas: {{ .Values.autoscaling.minReplicas }} maxReplicas: {{ .Values.autoscaling.maxReplicas }}