Skip to content

Commit c35cd8f

Browse files
authored
Merge pull request #4377 from camilamacedo86/helm-github
✨ (helm/v1alpha1): add GitHub action to make easier validate the chart generate
2 parents d40e7f2 + 82150b0 commit c35cd8f

File tree

3 files changed

+208
-2
lines changed

3 files changed

+208
-2
lines changed

pkg/plugins/optional/helm/v1alpha/scaffolds/init.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ import (
2323
"regexp"
2424
"strings"
2525

26-
"sigs.k8s.io/kubebuilder/v4/pkg/plugins/optional/helm/v1alpha/scaffolds/internal/templates/chart-templates/prometheus"
27-
2826
"sigs.k8s.io/yaml"
2927

3028
log "github.com/sirupsen/logrus"
@@ -38,7 +36,9 @@ import (
3836
templatescertmanager "sigs.k8s.io/kubebuilder/v4/pkg/plugins/optional/helm/v1alpha/scaffolds/internal/templates/chart-templates/cert-manager"
3937
"sigs.k8s.io/kubebuilder/v4/pkg/plugins/optional/helm/v1alpha/scaffolds/internal/templates/chart-templates/manager"
4038
templatesmetrics "sigs.k8s.io/kubebuilder/v4/pkg/plugins/optional/helm/v1alpha/scaffolds/internal/templates/chart-templates/metrics"
39+
"sigs.k8s.io/kubebuilder/v4/pkg/plugins/optional/helm/v1alpha/scaffolds/internal/templates/chart-templates/prometheus"
4140
templateswebhooks "sigs.k8s.io/kubebuilder/v4/pkg/plugins/optional/helm/v1alpha/scaffolds/internal/templates/chart-templates/webhook"
41+
github "sigs.k8s.io/kubebuilder/v4/pkg/plugins/optional/helm/v1alpha/scaffolds/internal/templates/github"
4242
)
4343

4444
var _ plugins.Scaffolder = &initScaffolder{}
@@ -82,6 +82,7 @@ func (s *initScaffolder) Scaffold() error {
8282
)
8383

8484
buildScaffold := []machinery.Builder{
85+
&github.HelmChartCI{},
8586
&templates.HelmChart{},
8687
&templates.HelmValues{
8788
HasWebhooks: len(webhooks) > 0,
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/*
2+
Copyright 2024 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package github
18+
19+
import (
20+
"path/filepath"
21+
22+
"sigs.k8s.io/kubebuilder/v4/pkg/machinery"
23+
)
24+
25+
var _ machinery.Template = &HelmChartCI{}
26+
27+
// HelmChartCI scaffolds the GitHub Action for testing Helm charts
28+
type HelmChartCI struct {
29+
machinery.TemplateMixin
30+
machinery.ProjectNameMixin
31+
}
32+
33+
// SetTemplateDefaults implements machinery.Template
34+
func (f *HelmChartCI) SetTemplateDefaults() error {
35+
if f.Path == "" {
36+
f.Path = filepath.Join(".github", "workflows", "test-chart.yml")
37+
}
38+
39+
f.TemplateBody = testChartTemplate
40+
41+
f.IfExistsAction = machinery.SkipFile
42+
43+
return nil
44+
}
45+
46+
// nolint:lll
47+
const testChartTemplate = `name: Test Chart
48+
49+
on:
50+
push:
51+
pull_request:
52+
53+
jobs:
54+
test-e2e:
55+
name: Run on Ubuntu
56+
runs-on: ubuntu-latest
57+
steps:
58+
- name: Clone the code
59+
uses: actions/checkout@v4
60+
61+
- name: Setup Go
62+
uses: actions/setup-go@v5
63+
with:
64+
go-version: '~1.22'
65+
66+
- name: Install the latest version of kind
67+
run: |
68+
curl -Lo ./kind https://kind.sigs.k8s.io/dl/latest/kind-linux-amd64
69+
chmod +x ./kind
70+
sudo mv ./kind /usr/local/bin/kind
71+
72+
- name: Verify kind installation
73+
run: kind version
74+
75+
- name: Create kind cluster
76+
run: kind create cluster
77+
78+
- name: Prepare {{ .ProjectName }}
79+
run: |
80+
go mod tidy
81+
make docker-build IMG={{ .ProjectName }}:v0.1.0
82+
kind load docker-image {{ .ProjectName }}:v0.1.0
83+
84+
- name: Install Helm
85+
run: |
86+
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
87+
88+
- name: Verify Helm installation
89+
run: helm version
90+
91+
- name: Lint Helm Chart
92+
run: |
93+
helm lint ./dist/chart
94+
95+
# TODO: Uncomment if cert-manager is enabled
96+
# - name: Install cert-manager via Helm
97+
# run: |
98+
# helm repo add jetstack https://charts.jetstack.io
99+
# helm repo update
100+
# helm install cert-manager jetstack/cert-manager --namespace cert-manager --create-namespace --set installCRDs=true
101+
#
102+
# - name: Wait for cert-manager to be ready
103+
# run: |
104+
# kubectl wait --namespace cert-manager --for=condition=available --timeout=300s deployment/cert-manager
105+
# kubectl wait --namespace cert-manager --for=condition=available --timeout=300s deployment/cert-manager-cainjector
106+
# kubectl wait --namespace cert-manager --for=condition=available --timeout=300s deployment/cert-manager-webhook
107+
108+
# TODO: Uncomment if Prometheus is enabled
109+
# - name: Install Prometheus via Helm
110+
# run: |
111+
# helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
112+
# helm repo update
113+
# helm install prometheus prometheus-community/prometheus --namespace monitoring --create-namespace
114+
#
115+
# - name: Wait for Prometheus to be ready
116+
# run: |
117+
# kubectl wait --namespace monitoring --for=condition=available --timeout=300s deployment/prometheus-server
118+
119+
- name: Install Helm chart for project
120+
run: |
121+
helm install my-release ./dist/chart --create-namespace --namespace {{ .ProjectName }}-system
122+
123+
- name: Check Helm release status
124+
run: |
125+
helm status my-release --namespace {{ .ProjectName }}-system
126+
`
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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: '~1.22'
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-v4-with-plugins
33+
run: |
34+
go mod tidy
35+
make docker-build IMG=project-v4-with-plugins:v0.1.0
36+
kind load docker-image project-v4-with-plugins: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 via Helm
64+
# run: |
65+
# helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
66+
# helm repo update
67+
# helm install prometheus prometheus-community/prometheus --namespace monitoring --create-namespace
68+
#
69+
# - name: Wait for Prometheus to be ready
70+
# run: |
71+
# kubectl wait --namespace monitoring --for=condition=available --timeout=300s deployment/prometheus-server
72+
73+
- name: Install Helm chart for project
74+
run: |
75+
helm install my-release ./dist/chart --create-namespace --namespace project-v4-with-plugins-system
76+
77+
- name: Check Helm release status
78+
run: |
79+
helm status my-release --namespace project-v4-with-plugins-system

0 commit comments

Comments
 (0)