Skip to content

Commit 48db38c

Browse files
🌱 (ci): Add GH action to validate generated helm charts for tutorials (#4472)
add gh action to validate book helm charts
1 parent 9d93a04 commit 48db38c

File tree

81 files changed

+14357
-3
lines changed

Some content is hidden

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

81 files changed

+14357
-3
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
name: Helm Docs Tutorials
2+
3+
on:
4+
push:
5+
paths:
6+
- "docs/book/src/cronjob-tutorial/testdata/project/**"
7+
- "docs/book/src/getting-started/testdata/project/**"
8+
- "docs/book/src/multiversion-tutorial/testdata/project/**"
9+
- ".github/workflows/test-helm-book.yml"
10+
pull_request:
11+
paths:
12+
- "docs/book/src/cronjob-tutorial/testdata/project/** "
13+
- "docs/book/src/getting-started/testdata/project/**"
14+
- "docs/book/src/multiversion-tutorial/testdata/project/**"
15+
- ".github/workflows/test-helm-book.yml"
16+
17+
jobs:
18+
helm-test:
19+
runs-on: ubuntu-latest
20+
strategy:
21+
fail-fast: true
22+
matrix:
23+
folder: [
24+
"docs/book/src/getting-started/testdata/project",
25+
"docs/book/src/cronjob-tutorial/testdata/project",
26+
"docs/book/src/multiversion-tutorial/testdata/project"
27+
]
28+
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
29+
steps:
30+
- name: Set project name
31+
id: project
32+
run: echo "name=$(basename ${{ matrix.folder }})" >> $GITHUB_OUTPUT
33+
34+
- name: Checkout repository
35+
uses: actions/checkout@v4
36+
37+
- name: Setup Go
38+
uses: actions/setup-go@v5
39+
with:
40+
go-version-file: go.mod
41+
42+
- name: Install the latest version of kind
43+
run: |
44+
curl -Lo ./kind https://kind.sigs.k8s.io/dl/latest/kind-linux-amd64
45+
chmod +x ./kind
46+
sudo mv ./kind /usr/local/bin/kind
47+
48+
- name: Verify kind installation
49+
run: kind version
50+
51+
- name: Create kind cluster
52+
run: kind create cluster
53+
54+
- name: Prepare project
55+
run: |
56+
cd ${{ matrix.folder }}
57+
go mod tidy
58+
make docker-build IMG=${{ steps.project.outputs.name}}:v0.1.0
59+
kind load docker-image ${{ steps.project.outputs.name}}:v0.1.0
60+
61+
- name: Install Helm
62+
run: |
63+
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
64+
65+
- name: Verify Helm installation
66+
run: helm version
67+
68+
- name: Lint Helm chart
69+
run: |
70+
helm lint ${{ matrix.folder }}/dist/chart
71+
72+
- name: Install Prometheus Operator CRDs
73+
run: |
74+
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
75+
helm repo update
76+
helm install prometheus-crds prometheus-community/prometheus-operator-crds
77+
78+
- name: Install cert-manager via Helm
79+
run: |
80+
helm repo add jetstack https://charts.jetstack.io
81+
helm repo update
82+
helm install cert-manager jetstack/cert-manager --namespace cert-manager --create-namespace --set installCRDs=true
83+
84+
- name: Wait for cert-manager to be ready
85+
run: |
86+
kubectl wait --namespace cert-manager --for=condition=available --timeout=300s deployment/cert-manager
87+
kubectl wait --namespace cert-manager --for=condition=available --timeout=300s deployment/cert-manager-cainjector
88+
kubectl wait --namespace cert-manager --for=condition=available --timeout=300s deployment/cert-manager-webhook
89+
90+
- name: Render Helm chart
91+
run: |
92+
helm template ${{ matrix.folder }}/dist/chart --namespace=${{ steps.project.outputs.name }}-system
93+
94+
- name: Install Helm chart
95+
run: |
96+
helm install my-release ${{ matrix.folder }}/dist/chart --create-namespace --namespace ${{ steps.project.outputs.name}}-system
97+
98+
- name: Check Helm release status
99+
run: |
100+
helm status my-release --namespace ${{ steps.project.outputs.name}}-system
101+

‎Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,16 @@ generate-docs: ## Update/generate the docs
8989
./hack/docs/generate.sh
9090

9191
.PHONY: generate-charts
92-
generate-charts: build ## Re-generate the helm chart testdata only
92+
generate-charts: build ## Re-generate the helm chart testdata and docs samples
9393
rm -rf testdata/project-v4-with-plugins/dist/chart
94+
rm -rf docs/book/src/getting-started/testdata/project/dist/chart
95+
rm -rf docs/book/src/cronjob-tutorial/testdata/project/dist/chart
96+
rm -rf docs/book/src/multiversion-tutorial/testdata/project/dist/chart
97+
9498
(cd testdata/project-v4-with-plugins && ../../bin/kubebuilder edit --plugins=helm/v1-alpha)
99+
(cd docs/book/src/getting-started/testdata/project && ../../../../../../bin/kubebuilder edit --plugins=helm/v1-alpha)
100+
(cd docs/book/src/cronjob-tutorial/testdata/project && ../../../../../../bin/kubebuilder edit --plugins=helm/v1-alpha)
101+
(cd docs/book/src/multiversion-tutorial/testdata/project && ../../../../../../bin/kubebuilder edit --plugins=helm/v1-alpha)
95102

96103
.PHONY: check-docs
97104
check-docs: ## Run the script to ensure that the docs are updated
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: Test Chart
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
test-e2e:
9+
name: Run on Ubuntu
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Clone the code
13+
uses: actions/checkout@v4
14+
15+
- name: Setup Go
16+
uses: actions/setup-go@v5
17+
with:
18+
go-version-file: go.mod
19+
20+
- name: Install the latest version of kind
21+
run: |
22+
curl -Lo ./kind https://kind.sigs.k8s.io/dl/latest/kind-linux-amd64
23+
chmod +x ./kind
24+
sudo mv ./kind /usr/local/bin/kind
25+
26+
- name: Verify kind installation
27+
run: kind version
28+
29+
- name: Create kind cluster
30+
run: kind create cluster
31+
32+
- name: Prepare project
33+
run: |
34+
go mod tidy
35+
make docker-build IMG=project:v0.1.0
36+
kind load docker-image project:v0.1.0
37+
38+
- name: Install Helm
39+
run: |
40+
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
41+
42+
- name: Verify Helm installation
43+
run: helm version
44+
45+
- name: Lint Helm Chart
46+
run: |
47+
helm lint ./dist/chart
48+
49+
# TODO: Uncomment if cert-manager is enabled
50+
# - name: Install cert-manager via Helm
51+
# run: |
52+
# helm repo add jetstack https://charts.jetstack.io
53+
# helm repo update
54+
# helm install cert-manager jetstack/cert-manager --namespace cert-manager --create-namespace --set installCRDs=true
55+
#
56+
# - name: Wait for cert-manager to be ready
57+
# run: |
58+
# kubectl wait --namespace cert-manager --for=condition=available --timeout=300s deployment/cert-manager
59+
# kubectl wait --namespace cert-manager --for=condition=available --timeout=300s deployment/cert-manager-cainjector
60+
# kubectl wait --namespace cert-manager --for=condition=available --timeout=300s deployment/cert-manager-webhook
61+
62+
# TODO: Uncomment if Prometheus is enabled
63+
# - name: Install Prometheus Operator CRDs
64+
# run: |
65+
# helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
66+
# helm repo update
67+
# helm install prometheus-crds prometheus-community/prometheus-operator-crds
68+
#
69+
# - name: Install Prometheus via Helm
70+
# run: |
71+
# helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
72+
# helm repo update
73+
# helm install prometheus prometheus-community/prometheus --namespace monitoring --create-namespace
74+
#
75+
# - name: Wait for Prometheus to be ready
76+
# run: |
77+
# kubectl wait --namespace monitoring --for=condition=available --timeout=300s deployment/prometheus-server
78+
79+
- name: Install Helm chart for project
80+
run: |
81+
helm install my-release ./dist/chart --create-namespace --namespace project-system
82+
83+
- name: Check Helm release status
84+
run: |
85+
helm status my-release --namespace project-system
86+
87+
# TODO: Uncomment if prometheus.enabled is set to true to confirm that the ServiceMonitor gets created
88+
# - name: Check Presence of ServiceMonitor
89+
# run: |
90+
# kubectl wait --namespace project-system --for=jsonpath='{.kind}'=ServiceMonitor servicemonitor/project-controller-manager-metrics-monitor

‎docs/book/src/cronjob-tutorial/testdata/project/PROJECT

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
domain: tutorial.kubebuilder.io
66
layout:
77
- go.kubebuilder.io/v4
8+
plugins:
9+
helm.kubebuilder.io/v1-alpha: {}
810
projectName: project
911
repo: tutorial.kubebuilder.io/project
1012
resources:
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Patterns to ignore when building Helm packages.
2+
# Operating system files
3+
.DS_Store
4+
5+
# Version control directories
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.hg/
10+
.hgignore
11+
.svn/
12+
13+
# Backup and temporary files
14+
*.swp
15+
*.tmp
16+
*.bak
17+
*.orig
18+
*~
19+
20+
# IDE and editor-related files
21+
.idea/
22+
.vscode/
23+
24+
# Helm chart artifacts
25+
dist/chart/*.tgz
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: v2
2+
name: project
3+
description: A Helm chart to distribute the project project
4+
type: application
5+
version: 0.1.0
6+
appVersion: "0.1.0"
7+
icon: "https://example.com/icon.png"
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
project
9+
{{- end }}
10+
{{- else }}
11+
project
12+
{{- end }}
13+
{{- end }}
14+
15+
16+
{{- define "chart.labels" -}}
17+
{{- if .Chart.AppVersion -}}
18+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
19+
{{- end }}
20+
{{- if .Chart.Version }}
21+
helm.sh/chart: {{ .Chart.Version | quote }}
22+
{{- end }}
23+
app.kubernetes.io/name: {{ include "chart.name" . }}
24+
app.kubernetes.io/instance: {{ .Release.Name }}
25+
app.kubernetes.io/managed-by: {{ .Release.Service }}
26+
{{- end }}
27+
28+
29+
{{- define "chart.selectorLabels" -}}
30+
app.kubernetes.io/name: {{ include "chart.name" . }}
31+
app.kubernetes.io/instance: {{ .Release.Name }}
32+
{{- end }}
33+
34+
35+
{{- define "chart.hasMutatingWebhooks" -}}
36+
{{- $hasMutating := false }}
37+
{{- range . }}
38+
{{- if eq .type "mutating" }}
39+
$hasMutating = true }}{{- end }}
40+
{{- end }}
41+
{{ $hasMutating }}}}{{- end }}
42+
43+
44+
{{- define "chart.hasValidatingWebhooks" -}}
45+
{{- $hasValidating := false }}
46+
{{- range . }}
47+
{{- if eq .type "validating" }}
48+
$hasValidating = true }}{{- end }}
49+
{{- end }}
50+
{{ $hasValidating }}}}{{- end }}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{{- if .Values.certmanager.enable }}
2+
# Self-signed Issuer
3+
apiVersion: cert-manager.io/v1
4+
kind: Issuer
5+
metadata:
6+
labels:
7+
{{- include "chart.labels" . | nindent 4 }}
8+
name: selfsigned-issuer
9+
namespace: {{ .Release.Namespace }}
10+
spec:
11+
selfSigned: {}
12+
{{- if .Values.webhook.enable }}
13+
---
14+
# Certificate for the webhook
15+
apiVersion: cert-manager.io/v1
16+
kind: Certificate
17+
metadata:
18+
annotations:
19+
{{- if .Values.crd.keep }}
20+
"helm.sh/resource-policy": keep
21+
{{- end }}
22+
name: serving-cert
23+
namespace: {{ .Release.Namespace }}
24+
labels:
25+
{{- include "chart.labels" . | nindent 4 }}
26+
spec:
27+
dnsNames:
28+
- project.{{ .Release.Namespace }}.svc
29+
- project.{{ .Release.Namespace }}.svc.cluster.local
30+
- project-webhook-service.{{ .Release.Namespace }}.svc
31+
issuerRef:
32+
kind: Issuer
33+
name: selfsigned-issuer
34+
secretName: webhook-server-cert
35+
{{- end }}
36+
{{- if .Values.metrics.enable }}
37+
---
38+
# Certificate for the metrics
39+
apiVersion: cert-manager.io/v1
40+
kind: Certificate
41+
metadata:
42+
annotations:
43+
{{- if .Values.crd.keep }}
44+
"helm.sh/resource-policy": keep
45+
{{- end }}
46+
labels:
47+
{{- include "chart.labels" . | nindent 4 }}
48+
name: metrics-certs
49+
namespace: {{ .Release.Namespace }}
50+
spec:
51+
dnsNames:
52+
- project.{{ .Release.Namespace }}.svc
53+
- project.{{ .Release.Namespace }}.svc.cluster.local
54+
- project-metrics-service.{{ .Release.Namespace }}.svc
55+
issuerRef:
56+
kind: Issuer
57+
name: selfsigned-issuer
58+
secretName: metrics-server-cert
59+
{{- end }}
60+
{{- end }}

0 commit comments

Comments
 (0)