From 75294e274d682f861a538b54db8d7889e446f19d Mon Sep 17 00:00:00 2001 From: Giles Knap Date: Fri, 8 Aug 2025 14:16:43 +0000 Subject: [PATCH 1/4] first pass at helm chart for fastcs instances --- .pre-commit-config.yaml | 3 +- helm/.helmignore | 23 ++++ helm/Chart.yaml | 24 ++++ helm/templates/_helpers.tpl | 62 +++++++++ helm/templates/clusterIP.tpl | 73 +++++++++++ helm/templates/deployment.yaml | 150 ++++++++++++++++++++++ helm/templates/service.yaml | 22 ++++ helm/templates/serviceaccount.yaml | 13 ++ helm/templates/tests/test-connection.yaml | 15 +++ helm/values.yaml | 106 +++++++++++++++ 10 files changed, 490 insertions(+), 1 deletion(-) create mode 100644 helm/.helmignore create mode 100644 helm/Chart.yaml create mode 100644 helm/templates/_helpers.tpl create mode 100644 helm/templates/clusterIP.tpl create mode 100644 helm/templates/deployment.yaml create mode 100644 helm/templates/service.yaml create mode 100644 helm/templates/serviceaccount.yaml create mode 100644 helm/templates/tests/test-connection.yaml create mode 100644 helm/values.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 60fc23f9a..319f652ef 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,9 +1,10 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 + rev: v5.0.0 hooks: - id: check-added-large-files - id: check-yaml + exclude: ^helm/templates/ - id: check-merge-conflict - id: end-of-file-fixer diff --git a/helm/.helmignore b/helm/.helmignore new file mode 100644 index 000000000..0e8a0eb36 --- /dev/null +++ b/helm/.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/helm/Chart.yaml b/helm/Chart.yaml new file mode 100644 index 000000000..2ad3ed918 --- /dev/null +++ b/helm/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: fastcs-instance +description: A Helm chart for Kubernetes + +# 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: "1.16.0" diff --git a/helm/templates/_helpers.tpl b/helm/templates/_helpers.tpl new file mode 100644 index 000000000..e019f9a9a --- /dev/null +++ b/helm/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "fastcs.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 "fastcs.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 "fastcs.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "fastcs.labels" -}} +helm.sh/chart: {{ include "fastcs.chart" . }} +{{ include "fastcs.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "fastcs.selectorLabels" -}} +app.kubernetes.io/name: {{ include "fastcs.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "fastcs.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "fastcs.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/helm/templates/clusterIP.tpl b/helm/templates/clusterIP.tpl new file mode 100644 index 000000000..e1b43bec9 --- /dev/null +++ b/helm/templates/clusterIP.tpl @@ -0,0 +1,73 @@ + +{{- define "allocateIpFromName" -}} + {{- $name := printf "%s.%s" .name .namespace -}} + {{- $baseIpWithCIDR := .baseIp -}} + + {{- $startIp := .startIp | int -}} + {{- $conversion := atoi (adler32sum $name) -}} + + {{- $baseIpParts := split "/" $baseIpWithCIDR -}} + {{- $baseIp := index $baseIpParts "_0" -}} + {{- $cidrRange := index $baseIpParts "_1" | int -}} + + {{- $octets := split "." $baseIp -}} + {{- $firstOctet := index $octets "_0" | int -}} + {{- $secondOctet := index $octets "_1" | int -}} + {{- $thirdOctet := index $octets "_2" | int -}} + {{- $fourthOctet := index $octets "_3" | int -}} + + + {{- $totalIps := 1 }} + {{- $loopcnt:= sub 32 $cidrRange -}} + {{- range $i,$k := until ($loopcnt | int) }} + {{- $totalIps = mul $totalIps 2 }} + {{- end }} + + {{- $ipSuffix := add $startIp (mod $conversion $totalIps) -}} + + {{- $secondOctet := add $secondOctet (div $ipSuffix 65536) -}} + {{- $ipSuffix = mod $ipSuffix 65536 -}} + {{- $thirdOctet := add $thirdOctet (div $ipSuffix 256) -}} + {{- $fourthOctet := mod $ipSuffix 256 -}} + + {{- if gt $fourthOctet 255 }} + {{- $fourthOctet = mod $fourthOctet 256 -}} + {{- end }} + {{- if gt $thirdOctet 255 }} + {{- $thirdOctet = mod $thirdOctet 256 -}} + {{- $secondOctet = add $secondOctet 1 -}} + {{- end }} + {{- if gt $secondOctet 255 }} + {{- $secondOctet = mod $secondOctet 256 -}} + {{- end }} + + {{- printf "%d.%d.%d.%d" $firstOctet $secondOctet $thirdOctet $fourthOctet -}} +{{- end -}} + + +{{- define "allocateIpFromNames" -}} + {{- $name := printf "%s.%s" .name .namespace -}} + {{- $baseIpWithCIDR := .baseIp -}} + + {{- $startIp := .startIp | int -}} + {{- $conversion := atoi (adler32sum $name) -}} + + {{- $baseIpParts := split "/" $baseIpWithCIDR -}} + {{- $baseIp := index $baseIpParts "_0" -}} + {{- $cidrRange := index $baseIpParts "_1" | int -}} + + {{- $octets := split "." $baseIp -}} + {{- $firstOctet := index $octets "_0" | int -}} + {{- $secondOctet := index $octets "_1" | int -}} + {{- $thirdOctet := index $octets "_2" | int -}} + {{- $fourthOctet := index $octets "_3" | int -}} + + {{- $totalIps := 1 }} + {{- $loopcnt:= sub 32 $cidrRange -}} + {{- range $i,$k := until ($loopcnt | int) }} + {{- $totalIps = mul $totalIps 2 }} + {{- end }} + {{- printf "CIDR %d IPs %d" $cidrRange $totalIps -}} + + +{{- end -}} diff --git a/helm/templates/deployment.yaml b/helm/templates/deployment.yaml new file mode 100644 index 000000000..5df245e02 --- /dev/null +++ b/helm/templates/deployment.yaml @@ -0,0 +1,150 @@ +{{- /* +Default the derivable substitution values. + +This keeps the length of the values.txt file for each individual IOC +to a minimum +*/ -}} +{{- $location := default .Values.global.location .Values.location | required "ERROR - You must supply location or global.location" -}} +{{- $ioc_group := default .Values.global.ioc_group .Values.ioc_group | required "ERROR - You must supply ioc_group or global.ioc_group" -}} +{{- $opisClaim := default (print $ioc_group "-opi-claim") .Values.opisClaim -}} +{{- $runtimeClaim := default (print $ioc_group "-runtime-claim") .Values.runtimeClaim -}} +{{- $autosaveClaim := default (print $ioc_group "-autosave-claim") .Values.autosaveClaim -}} +{{- $image := .Values.image | required "ERROR - You must supply image." -}} + +{{- $enabled := eq .Values.global.enabled false | ternary false true -}} + +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: {{ include "fastcs.fullname" . }} + labels: + location: {{ $location }} + ioc_group: {{ $ioc_group }} + enabled: {{ $enabled | quote }} + is_ioc: "true" + {{- include "fastcs.labels" . | nindent 4 }} +spec: + replicas: {{ $enabled | ternary 1 0 }} + selector: + matchLabels: + {{- include "fastcs.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "fastcs.labels" . | nindent 8 }} + {{- with .Values.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + # re-deploy in case the configMap has changed - use a random value + # unless the Commit Hash is supplied (by ArgoCD or helm command line) + rollme: {{ .Values.global.commitHash | default (randAlphaNum 5) | quote }} + spec: + serviceAccountName: {{ include "fastcs.serviceAccountName" . }} + {{- with .Values.podSecurityContext }} + securityContext: + {{- toYaml . | nindent 8 }} + {{- end }} + containers: + {{- range .Values.extra_containers }} + - name: {{ .name }} + {{- with $.Values.securityContext }} + securityContext: + {{- toYaml . | nindent 12 }} + {{- end }} + image: {{ .image }} + {{- with .startCommand }} + command: + {{- if (kindIs "string" .) }} + - {{ . }} + {{- else if (kindIs "slice" .) }} + {{- . | toYaml | nindent 10 }} + {{- end }} + {{- end }} + volumeMounts: + {{- with $.Values.volumeMounts }} + {{- toYaml . | nindent 12 }} + {{- end }} + - name: opis-volume + mountPath: /epics/opi + subPath: "{{ $.Release.Name }}" + - name: config-volume + mountPath: {{ $.Values.iocConfig }} + {{- end }} + - name: {{ .Chart.Name }} + {{- with .Values.securityContext }} + securityContext: + {{- toYaml . | nindent 12 }} + {{- end }} + image: "{{ .Values.image }}" + imagePullPolicy: IfNotPresent + {{- with .Values.startCommand }} + command: + {{- if (kindIs "string" .) }} + - {{ . }} + {{- else if (kindIs "slice" .) }} + {{- . | toYaml | nindent 10 }} + {{- end }} + {{- end }} + {{- with .Values.startArgs }} + args: + {{- if (kindIs "string" .) }} + - {{ . }} + {{- else if (kindIs "slice" .) }} + {{- . | toYaml | nindent 10 }} + {{- end }} + {{- end }} + + ports: + - name: channel-access + containerPort: 5064 + protocol: TCP + - name: pv-access + containerPort: 5075 + protocol: TCP + {{- with .Values.livenessProbe }} + livenessProbe: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.readinessProbe }} + readinessProbe: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.resources }} + resources: + {{- toYaml . | nindent 12 }} + {{- end }} + volumeMounts: + {{- with .Values.volumeMounts }} + {{- toYaml . | nindent 12 }} + {{- end }} + - name: opis-volume + mountPath: /epics/opi + subPath: "{{ .Release.Name }}" + - name: config-volume + mountPath: {{ .Values.iocConfig }} + volumes: + {{- with .Values.volumes }} + {{- toYaml . | nindent 8 }} + {{- end }} + - name: opis-volume + persistentVolumeClaim: + claimName: {{ $opisClaim }} + - name: config-volume + configMap: + name: {{ .Release.Name }}-config + {{- 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/helm/templates/service.yaml b/helm/templates/service.yaml new file mode 100644 index 000000000..c5ecec668 --- /dev/null +++ b/helm/templates/service.yaml @@ -0,0 +1,22 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "fastcs.fullname" . }} + labels: + "{{- include "fastcs.labels" . | nindent 4 }}" +spec: + type: {{ .Values.service.type }} + # allocate a fixed clusterIP for this service based on the service name + {{- $alloc_args := dict "name" .Release.Name "namespace" .Release.Namespace "baseIp" .Values.baseIp "startIp" .Values.startIp }} + clusterIP: {{ .Values.clusterIP | default (include "allocateIpFromName" $alloc_args) }} + ports: + - port: {{ .Values.service.ca_port }} + targetPort: 5064 + protocol: TCP + name: channel-access + - port: {{ .Values.service.pva_port }} + targetPort: 5075 + protocol: TCP + name: pv-access + selector: + {{- include "fastcs.selectorLabels" . | nindent 4 }} diff --git a/helm/templates/serviceaccount.yaml b/helm/templates/serviceaccount.yaml new file mode 100644 index 000000000..d2229bce5 --- /dev/null +++ b/helm/templates/serviceaccount.yaml @@ -0,0 +1,13 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "fastcs.serviceAccountName" . }} + labels: + {{- include "fastcs.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +automountServiceAccountToken: {{ .Values.serviceAccount.automount }} +{{- end }} diff --git a/helm/templates/tests/test-connection.yaml b/helm/templates/tests/test-connection.yaml new file mode 100644 index 000000000..c2f6e7fbd --- /dev/null +++ b/helm/templates/tests/test-connection.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "fastcs.fullname" . }}-test-connection" + labels: + {{- include "fastcs.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "fastcs.fullname" . }}:{{ .Values.service.port }}'] + restartPolicy: Never diff --git a/helm/values.yaml b/helm/values.yaml new file mode 100644 index 000000000..7725f6873 --- /dev/null +++ b/helm/values.yaml @@ -0,0 +1,106 @@ +# Default values for fastcs. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +# This sets the container image more information can be found here: https://kubernetes.io/docs/concepts/containers/images/ +image: + repository: + # This sets the pull policy for images. + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: + +# location of config folder (defaults to be the same as c++ IOCs) +iocFolder: /epics/ioc +iocConfig: /epics/ioc/config + +# extra containers to run in the pod +extra_containers: [] +# - name: foo +# image: ghcr.io/epics-containers/ioc-adsimdetector-runtime:2025.8.2 +# startCommand: +# - tickit +# - all +# - /epics/ioc/config/temp_controller.yaml + +# must be the CIDR for services clusterIP (this default is for all DLS clusters) +# used by allocateIpFromName to allocate a fixed cluster IP for the service +baseIp: 10.96.0.0/12 +# supply a fixed cluster IP for the service to override allocateIpFromName +clusterIP: + +# 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 + ca_port: 5064 + pva_port: 5075 + +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: {} +readinessProbe: {} + +# 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 599804550c556dea06dcc168b7b19fc587811f9c Mon Sep 17 00:00:00 2001 From: Giles Knap Date: Fri, 8 Aug 2025 15:39:16 +0000 Subject: [PATCH 2/4] fix service name --- helm/templates/deployment.yaml | 6 +++++- helm/templates/service.yaml | 10 ++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/helm/templates/deployment.yaml b/helm/templates/deployment.yaml index 5df245e02..41d39932b 100644 --- a/helm/templates/deployment.yaml +++ b/helm/templates/deployment.yaml @@ -16,7 +16,7 @@ to a minimum apiVersion: apps/v1 kind: StatefulSet metadata: - name: {{ include "fastcs.fullname" . }} + name: {{ .Release.Name }} labels: location: {{ $location }} ioc_group: {{ $ioc_group }} @@ -35,6 +35,10 @@ spec: {{- toYaml . | nindent 8 }} {{- end }} labels: + location: {{ $location }} + ioc_group: {{ $ioc_group }} + enabled: {{ $enabled | quote }} + is_ioc: "true" {{- include "fastcs.labels" . | nindent 8 }} {{- with .Values.podLabels }} {{- toYaml . | nindent 8 }} diff --git a/helm/templates/service.yaml b/helm/templates/service.yaml index c5ecec668..83b3277a8 100644 --- a/helm/templates/service.yaml +++ b/helm/templates/service.yaml @@ -1,10 +1,16 @@ apiVersion: v1 kind: Service metadata: - name: {{ include "fastcs.fullname" . }} + name: {{ .Release.Name }} labels: - "{{- include "fastcs.labels" . | nindent 4 }}" + {{- include "fastcs.labels" . | nindent 4 }} + app: {{ .Release.Name }} + location: {{ .Values.global.location }} + ioc_group: {{ .Values.global.ioc_group }} + is_ioc: "true" spec: + selector: + app: {{ .Release.Name }} type: {{ .Values.service.type }} # allocate a fixed clusterIP for this service based on the service name {{- $alloc_args := dict "name" .Release.Name "namespace" .Release.Namespace "baseIp" .Values.baseIp "startIp" .Values.startIp }} From 50fe871eb569610d80844601cf5a39e76c018bcf Mon Sep 17 00:00:00 2001 From: Giles Knap Date: Sat, 9 Aug 2025 06:34:29 +0100 Subject: [PATCH 3/4] better port exposure for service.yaml --- helm/templates/service.yaml | 36 ++++++++++++++++++++++++++++++------ helm/values.yaml | 4 ++++ 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/helm/templates/service.yaml b/helm/templates/service.yaml index 83b3277a8..c51433f8b 100644 --- a/helm/templates/service.yaml +++ b/helm/templates/service.yaml @@ -16,13 +16,37 @@ spec: {{- $alloc_args := dict "name" .Release.Name "namespace" .Release.Namespace "baseIp" .Values.baseIp "startIp" .Values.startIp }} clusterIP: {{ .Values.clusterIP | default (include "allocateIpFromName" $alloc_args) }} ports: - - port: {{ .Values.service.ca_port }} - targetPort: 5064 + - name: ca-server-tcp + port: {{ .Values.ca_server_port | default 5064 }} + targetPort: {{ .Values.ca_server_port | default 5064 }} protocol: TCP - name: channel-access - - port: {{ .Values.service.pva_port }} - targetPort: 5075 + - name: ca-server-udp + port: {{ .Values.ca_server_port | default 5064 }} + targetPort: {{ .Values.ca_server_port | default 5064 }} + protocol: UDP + - name: ca-repeater-tcp + port: {{ add1 (.Values.ca_server_port | default 5064) }} + targetPort: {{ add1 (.Values.ca_server_port | default 5064) }} protocol: TCP - name: pv-access + - name: ca-repeater-udp + port: {{ add1 (.Values.ca_server_port | default 5064) }} + targetPort: {{ add1 (.Values.ca_server_port | default 5064) }} + protocol: UDP + - name: pva-server-tcp + port: {{ .Values.pva_server_port | default 5075 }} + targetPort: {{ .Values.pva_server_port | default 5075 }} + protocol: TCP + - name: pva-server-udp + port: {{ .Values.pva_server_port | default 5075 }} + targetPort: {{ .Values.pva_server_port | default 5075 }} + protocol: UDP + - name: pva-broadcast-tcp + port: {{ add1 (.Values.pva_server_port | default 5075) }} + targetPort: {{ add1 (.Values.pva_server_port | default 5075) }} + protocol: TCP + - name: pva-broadcast-udp + port: {{ add1 (.Values.pva_server_port | default 5075) }} + targetPort: {{ add1 (.Values.pva_server_port | default 5075) }} + protocol: UDP selector: {{- include "fastcs.selectorLabels" . | nindent 4 }} diff --git a/helm/values.yaml b/helm/values.yaml index 7725f6873..9b1362dd4 100644 --- a/helm/values.yaml +++ b/helm/values.yaml @@ -14,6 +14,10 @@ image: iocFolder: /epics/ioc iocConfig: /epics/ioc/config +# ports to expose on the service +ca_server_port: 5064 +pva_server_port: 5075 + # extra containers to run in the pod extra_containers: [] # - name: foo From e63597f603987d056520f4196925e0c787c00e26 Mon Sep 17 00:00:00 2001 From: Giles Knap Date: Sat, 9 Aug 2025 07:24:46 +0100 Subject: [PATCH 4/4] add helm chart publishing --- .github/workflows/_helm.yml | 32 ++++++++++++++++++++++++++++++++ .github/workflows/_release.yml | 11 +++++++++++ .github/workflows/ci.yml | 5 ++++- package-helm-chart.sh | 21 +++++++++++++++++++++ 4 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/_helm.yml create mode 100755 package-helm-chart.sh diff --git a/.github/workflows/_helm.yml b/.github/workflows/_helm.yml new file mode 100644 index 000000000..23d69e12f --- /dev/null +++ b/.github/workflows/_helm.yml @@ -0,0 +1,32 @@ +name: Package helm charts + +on: + workflow_call: + +env: + HELM_VERSION_TO_INSTALL: 3.14.3 + +jobs: + package-helm-charts: + name: Test helm chart packaging + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Install helm + uses: Azure/setup-helm@v3 + with: + version: ${{ env.HELM_VERSION_TO_INSTALL }} + + - name: Package helm charts + run: | + ./package-helm-chart.sh + + - name: Upload helm charts as artifacts + uses: actions/upload-artifact@v4 + with: + name: charts + path: charts diff --git a/.github/workflows/_release.yml b/.github/workflows/_release.yml index 81b626438..c27836321 100644 --- a/.github/workflows/_release.yml +++ b/.github/workflows/_release.yml @@ -20,6 +20,17 @@ jobs: rm -rf $GITHUB_REF_NAME fi + - name: Push tagged helm chart to registry + run: | + set -x + + echo "${{ secrets.GITHUB_TOKEN }}" | helm registry login ghcr.io/${{ github.repository_owner }} --username ${{ github.repository_owner }} --password-stdin + + IFS='@' read -r NAME VERSION <<< "${GITHUB_REF_NAME}" + REGISTRY=oci://ghcr.io/diamondlightsource + + helm push "${NAME}-${VERSION}.tgz" ${REGISTRY} + - name: Create GitHub Release # We pin to the SHA, not the tag, for security reasons. # https://docs.github.com/en/actions/learn-github-actions/security-hardening-for-github-actions#using-third-party-actions diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9529f09e4..30f54203b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,9 +51,12 @@ jobs: permissions: id-token: write + helm: + uses: ./.github/workflows/_helm.yml + release: if: github.ref_type == 'tag' - needs: [dist, docs] + needs: [dist, docs, helm] uses: ./.github/workflows/_release.yml permissions: contents: write diff --git a/package-helm-chart.sh b/package-helm-chart.sh new file mode 100755 index 000000000..b8074e7e8 --- /dev/null +++ b/package-helm-chart.sh @@ -0,0 +1,21 @@ +#!/bin/env bash + +set -xeuo pipefail + +FULL_REF=$(git describe --tags) +VERSION="${FULL_REF#*@}" + +# Check that alpha/beta versions have the form 2025.8.1+b1 requried by Helm +if [[ "${VERSION}" =~ '^[0-9]+\.[0-9]+\.[0-9]+(\+.*)?$' ]]; then + echo "Valid version format: ${VERSION}" +else + echo "Invalid version format: ${VERSION}. Expected format: X.Y.Z or X.Y.Z+string" + return 1 +fi + +mkdir -p charts + +cd helm + +helm package -u --app-version ${VERSION} --version ${VERSION} . +mv *.tgz ../../charts