Skip to content

Commit 1578072

Browse files
authored
Migrate Helm chart from helm/v1-alpha to helm/v2-alpha plugin (#409)
Signed-off-by: Andreas Fritzler <andreas.fritzler@sap.com>
1 parent 687cc26 commit 1578072

44 files changed

Lines changed: 1461 additions & 628 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/publish-chart.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ jobs:
8282
- name: Set container image repository and tag
8383
run: |
8484
IMAGE_TAG=sha-$(echo ${{ github.sha }} | cut -c1-7)
85-
yq -i '.controllerManager.manager.image.repository = "ghcr.io/ironcore-dev/boot-operator"' dist/chart/values.yaml
86-
yq -i '.controllerManager.manager.image.tag = "'$IMAGE_TAG'"' dist/chart/values.yaml
85+
yq -i '.manager.image.repository = "ghcr.io/ironcore-dev/boot-operator"' dist/chart/values.yaml
86+
yq -i '.manager.image.tag = "'$IMAGE_TAG'"' dist/chart/values.yaml
8787
8888
- name: Package Helm chart with crds folder in template
8989
run: |

‎.github/workflows/test-chart.yml‎

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,34 @@
11
name: Test Chart
22

3-
permissions:
4-
contents: read
5-
63
on:
74
pull_request:
85
types: [labeled, opened, synchronize, reopened]
96

7+
permissions: {}
8+
109
jobs:
1110
test-e2e:
11+
permissions:
12+
contents: read
1213
name: Run on Ubuntu
1314
runs-on: ubuntu-latest
1415
if: contains(github.event.pull_request.labels.*.name, 'ok-to-test')
16+
env:
17+
IMG: controller:latest
1518
steps:
1619
- name: Clone the code
17-
uses: actions/checkout@v7
20+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
21+
with:
22+
persist-credentials: false
1823

1924
- name: Setup Go
20-
uses: actions/setup-go@v7
25+
uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
2126
with:
2227
go-version-file: go.mod
2328

24-
- name: Install Helm
25-
run: |
26-
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
27-
28-
- name: Verify Helm installation
29-
run: helm version
30-
31-
- name: Lint Helm Chart
32-
run: |
33-
helm lint ./dist/chart
34-
3529
- name: Install the latest version of kind
3630
run: |
37-
curl -Lo ./kind https://kind.sigs.k8s.io/dl/latest/kind-linux-amd64
31+
curl -Lo ./kind https://kind.sigs.k8s.io/dl/latest/kind-linux-$(go env GOARCH)
3832
chmod +x ./kind
3933
sudo mv ./kind /usr/local/bin/kind
4034
@@ -47,25 +41,38 @@ jobs:
4741
- name: Prepare boot-operator
4842
run: |
4943
go mod tidy
50-
make docker-build IMG=boot-operator:v0.1.0
51-
kind load docker-image boot-operator:v0.1.0
44+
make docker-build
45+
kind load docker-image $IMG
46+
47+
- name: Install Helm
48+
run: make install-helm
49+
50+
- name: Lint Helm Chart
51+
run: |
52+
helm lint ./dist/chart
5253
5354
- name: Install cert-manager via Helm
5455
run: |
5556
helm repo add jetstack https://charts.jetstack.io
5657
helm repo update
57-
helm install cert-manager jetstack/cert-manager --namespace cert-manager --create-namespace --set installCRDs=true
58+
helm install cert-manager jetstack/cert-manager \
59+
--namespace cert-manager \
60+
--create-namespace \
61+
--set crds.enabled=true \
62+
--wait \
63+
--timeout 300s
5864
59-
- name: Wait for cert-manager to be ready
60-
run: |
61-
kubectl wait --namespace cert-manager --for=condition=available --timeout=300s deployment/cert-manager
62-
kubectl wait --namespace cert-manager --for=condition=available --timeout=300s deployment/cert-manager-cainjector
63-
kubectl wait --namespace cert-manager --for=condition=available --timeout=300s deployment/cert-manager-webhook
65+
# TODO: Uncomment if Prometheus is enabled
66+
# - name: Install Prometheus Operator CRDs
67+
# run: |
68+
# helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
69+
# helm repo update
70+
# helm install prometheus-crds prometheus-community/prometheus-operator-crds
6471

65-
- name: Install Helm chart for project
72+
- name: Deploy manager via Helm
6673
run: |
67-
helm install my-release ./dist/chart --create-namespace --namespace boot-operator-system
74+
make helm-deploy
6875
6976
- name: Check Helm release status
7077
run: |
71-
helm status my-release --namespace boot-operator-system
78+
make helm-status

‎Makefile‎

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ undeploy: kustomize ## Undeploy controller from the K8s cluster specified in ~/.
179179
$(KUSTOMIZE) build config/default | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
180180

181181
.PHONY: helm
182-
helm: manifests kubebuilder
183-
$(KUBEBUILDER) edit --plugins=helm/v1-alpha
182+
helm: manifests build-installer kubebuilder
183+
$(KUBEBUILDER) edit --plugins=helm/v2-alpha
184184

185185
##@ Dependencies
186186

@@ -298,3 +298,50 @@ mv $(1) $(1)-$(3) ;\
298298
} ;\
299299
ln -sf $(1)-$(3) $(1)
300300
endef
301+
302+
##@ Helm Deployment
303+
304+
## Helm binary to use for deploying the chart
305+
HELM ?= helm
306+
## Namespace to deploy the Helm release
307+
HELM_NAMESPACE ?= boot-operator-system
308+
## Name of the Helm release
309+
HELM_RELEASE ?= boot-operator
310+
## Path to the Helm chart directory
311+
HELM_CHART_DIR ?= dist/chart
312+
## Additional arguments to pass to helm commands
313+
HELM_EXTRA_ARGS ?=
314+
315+
.PHONY: install-helm
316+
install-helm: ## Install the latest version of Helm.
317+
@command -v $(HELM) >/dev/null 2>&1 || { \
318+
echo "Installing Helm..." && \
319+
curl -fsSL https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-4 | bash; \
320+
}
321+
322+
.PHONY: helm-deploy
323+
helm-deploy: install-helm ## Deploy manager to the K8s cluster via Helm. Specify an image with IMG.
324+
IMG="$(IMG)"; $(HELM) upgrade --install $(HELM_RELEASE) $(HELM_CHART_DIR) \
325+
--namespace $(HELM_NAMESPACE) \
326+
--create-namespace \
327+
--set manager.image.repository=$${IMG%:*} \
328+
--set manager.image.tag=$${IMG##*:} \
329+
--wait \
330+
--timeout 5m \
331+
$(HELM_EXTRA_ARGS)
332+
333+
.PHONY: helm-uninstall
334+
helm-uninstall: ## Uninstall the Helm release from the K8s cluster.
335+
$(HELM) uninstall $(HELM_RELEASE) --namespace $(HELM_NAMESPACE)
336+
337+
.PHONY: helm-status
338+
helm-status: ## Show Helm release status.
339+
$(HELM) status $(HELM_RELEASE) --namespace $(HELM_NAMESPACE)
340+
341+
.PHONY: helm-history
342+
helm-history: ## Show Helm release history.
343+
$(HELM) history $(HELM_RELEASE) --namespace $(HELM_NAMESPACE)
344+
345+
.PHONY: helm-rollback
346+
helm-rollback: ## Rollback to previous Helm release.
347+
$(HELM) rollback $(HELM_RELEASE) --namespace $(HELM_NAMESPACE)

‎PROJECT‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ domain: ironcore.dev
66
layout:
77
- go.kubebuilder.io/v4
88
plugins:
9-
helm.kubebuilder.io/v1-alpha: {}
9+
helm.kubebuilder.io/v2-alpha:
10+
manifests: dist/install.yaml
11+
output: dist
1012
projectName: boot-operator
1113
repo: github.com/ironcore-dev/boot-operator
1214
resources:
@@ -19,4 +21,13 @@ resources:
1921
kind: HTTPBootConfig
2022
path: github.com/ironcore-dev/boot-operator/api/v1alpha1
2123
version: v1alpha1
24+
- api:
25+
crdVersion: v1
26+
namespaced: true
27+
controller: true
28+
domain: ironcore.dev
29+
group: boot
30+
kind: IPXEBootConfig
31+
path: github.com/ironcore-dev/boot-operator/api/v1alpha1
32+
version: v1alpha1
2233
version: "3"

‎config/manager/kustomization.yaml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
resources:
22
- manager.yaml
3+
apiVersion: kustomize.config.k8s.io/v1beta1
4+
kind: Kustomization
5+
images:
6+
- name: controller

‎dist/chart/Chart.yaml‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
apiVersion: v2
22
name: boot-operator
3-
description: A Helm chart to distribute the project boot-operator
3+
description: A Helm chart to distribute boot-operator
44
type: application
5+
56
version: 0.1.0
67
appVersion: "0.1.0"
7-
icon: "https://example.com/icon.png"
8+
9+
keywords:
10+
- kubernetes
11+
- operator
12+
13+
annotations:
14+
kubebuilder.io/generated-by: kubebuilder

‎dist/chart/templates/NOTES.txt‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Thank you for installing {{ .Chart.Name }}.
2+
3+
Your release is named {{ .Release.Name }}.
4+
5+
The controller and CRDs have been installed in namespace {{ .Release.Namespace }}.
6+
7+
To verify the installation:
8+
9+
kubectl get pods -n {{ .Release.Namespace }}
10+
kubectl get customresourcedefinitions
11+
12+
To learn more about the release, try:
13+
14+
$ helm status {{ .Release.Name }} -n {{ .Release.Namespace }}
15+
$ helm get all {{ .Release.Name }} -n {{ .Release.Namespace }}

‎dist/chart/templates/_helpers.tpl‎

Lines changed: 53 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,63 @@
1-
{{- define "chart.name" -}}
2-
{{- if .Chart }}
3-
{{- if .Chart.Name }}
4-
{{- .Chart.Name | trunc 63 | trimSuffix "-" }}
5-
{{- else if .Values.nameOverride }}
6-
{{ .Values.nameOverride | trunc 63 | trimSuffix "-" }}
7-
{{- else }}
8-
boot-operator
9-
{{- end }}
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "boot-operator.name" -}}
5+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
6+
{{- end }}
7+
8+
{{/*
9+
Create a default fully qualified app name.
10+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
11+
If release name contains chart name it will be used as a full name.
12+
*/}}
13+
{{- define "boot-operator.fullname" -}}
14+
{{- if .Values.fullnameOverride }}
15+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
1016
{{- else }}
11-
boot-operator
12-
{{- end }}
13-
{{- end }}
14-
15-
16-
{{- define "chart.labels" -}}
17-
{{- if .Chart.AppVersion -}}
18-
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
17+
{{- $name := default .Chart.Name .Values.nameOverride }}
18+
{{- if contains $name .Release.Name }}
19+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
20+
{{- else }}
21+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
1922
{{- end }}
20-
{{- if .Chart.Version }}
21-
helm.sh/chart: {{ .Chart.Version | quote }}
2223
{{- end }}
23-
app.kubernetes.io/name: {{ include "chart.name" . }}
24-
app.kubernetes.io/instance: {{ .Release.Name }}
25-
app.kubernetes.io/managed-by: {{ .Release.Service }}
2624
{{- end }}
2725

28-
29-
{{- define "chart.selectorLabels" -}}
30-
app.kubernetes.io/name: {{ include "chart.name" . }}
31-
app.kubernetes.io/instance: {{ .Release.Name }}
26+
{{/*
27+
Namespace for generated references.
28+
Always uses the Helm release namespace.
29+
*/}}
30+
{{- define "boot-operator.namespaceName" -}}
31+
{{- .Release.Namespace }}
3232
{{- end }}
3333

34-
35-
{{- define "chart.hasMutatingWebhooks" -}}
36-
{{- $hasMutating := false }}
37-
{{- range . }}
38-
{{- if eq .type "mutating" }}
39-
$hasMutating = true }}{{- end }}
34+
{{/*
35+
Resource name with proper truncation for Kubernetes 63-character limit.
36+
Takes a dict with:
37+
- .suffix: Resource name suffix (e.g., "metrics", "webhook")
38+
- .context: Template context (root context with .Values, .Release, etc.)
39+
Dynamically calculates safe truncation to ensure total name length <= 63 chars.
40+
*/}}
41+
{{- define "boot-operator.resourceName" -}}
42+
{{- $fullname := include "boot-operator.fullname" .context }}
43+
{{- $suffix := .suffix }}
44+
{{- $maxLen := sub 62 (len $suffix) | int }}
45+
{{- if gt (len $fullname) $maxLen }}
46+
{{- printf "%s-%s" (trunc $maxLen $fullname | trimSuffix "-") $suffix | trunc 63 | trimSuffix "-" }}
47+
{{- else }}
48+
{{- printf "%s-%s" $fullname $suffix | trunc 63 | trimSuffix "-" }}
49+
{{- end }}
4050
{{- end }}
41-
{{ $hasMutating }}}}{{- end }}
42-
4351

44-
{{- define "chart.hasValidatingWebhooks" -}}
45-
{{- $hasValidating := false }}
46-
{{- range . }}
47-
{{- if eq .type "validating" }}
48-
$hasValidating = true }}{{- end }}
52+
{{/*
53+
ServiceAccount name to use.
54+
When enabled, use the chart's ServiceAccount name.
55+
When disabled, serviceAccount.name must be set; use "default" to pick the namespace default ServiceAccount.
56+
*/}}
57+
{{- define "boot-operator.serviceAccountName" -}}
58+
{{- if .Values.serviceAccount.enabled }}
59+
{{- include "boot-operator.resourceName" (dict "suffix" "controller-manager" "context" .) }}
60+
{{- else }}
61+
{{- required "serviceAccount.name is required when serviceAccount.enabled=false (set name: default explicitly to use the namespace default ServiceAccount)" .Values.serviceAccount.name }}
62+
{{- end }}
4963
{{- end }}
50-
{{ $hasValidating }}}}{{- end }}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{{- if and .Values.certManager.enabled .Values.metrics.enabled .Values.metrics.secure }}
2+
apiVersion: cert-manager.io/v1
3+
kind: Certificate
4+
metadata:
5+
labels:
6+
app.kubernetes.io/managed-by: {{ .Release.Service }}
7+
app.kubernetes.io/name: {{ include "boot-operator.name" . }}
8+
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
9+
app.kubernetes.io/instance: {{ .Release.Name }}
10+
name: {{ include "boot-operator.resourceName" (dict "suffix" "metrics-certs" "context" $) }}
11+
namespace: {{ .Release.Namespace }}
12+
spec:
13+
dnsNames:
14+
- {{ include "boot-operator.resourceName" (dict "suffix" "controller-manager-metrics-service" "context" $) }}.{{ include "boot-operator.namespaceName" $ }}.svc
15+
- {{ include "boot-operator.resourceName" (dict "suffix" "controller-manager-metrics-service" "context" $) }}.{{ include "boot-operator.namespaceName" $ }}.svc.cluster.local
16+
issuerRef:
17+
kind: Issuer
18+
name: {{ include "boot-operator.resourceName" (dict "suffix" "selfsigned-issuer" "context" $) }}
19+
secretName: metrics-server-cert
20+
{{- end }}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{{- if .Values.certManager.enabled }}
2+
apiVersion: cert-manager.io/v1
3+
kind: Issuer
4+
metadata:
5+
labels:
6+
app.kubernetes.io/managed-by: {{ .Release.Service }}
7+
app.kubernetes.io/name: {{ include "boot-operator.name" . }}
8+
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
9+
app.kubernetes.io/instance: {{ .Release.Name }}
10+
name: {{ include "boot-operator.resourceName" (dict "suffix" "selfsigned-issuer" "context" $) }}
11+
namespace: {{ .Release.Namespace }}
12+
spec:
13+
selfSigned: {}
14+
{{- end }}

0 commit comments

Comments
 (0)