Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/_helm.yml
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions .github/workflows/_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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

Expand Down
23 changes: 23 additions & 0 deletions helm/.helmignore
Original file line number Diff line number Diff line change
@@ -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/
24 changes: 24 additions & 0 deletions helm/Chart.yaml
Original file line number Diff line number Diff line change
@@ -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"
62 changes: 62 additions & 0 deletions helm/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -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 }}
73 changes: 73 additions & 0 deletions helm/templates/clusterIP.tpl
Original file line number Diff line number Diff line change
@@ -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 -}}
Loading
Loading