Skip to content

Commit 80d8487

Browse files
Add helm plugin to distribute projects
This PR introduces an optional Helm plugin, enabling users to scaffold Helm charts for Kubebuilder projects. - **Helm Chart Scaffolding**: Allows generation of a Helm chart under the `dist/chart` directory, providing an alternative for distributing and managing projects via Helm. - **Usage**: - **To add when init the project**: `kubebuilder init --plugins=helm/v1-alpha` for new projects. - **To Init/Update in a project previously scaffolded**: `kubebuilder edit --plugins=helm/v1-alpha` to add or update Helm charts for existing projects. - **Sync Helm Chart**: Syncs the Helm chart with project manifests using the `edit` command, with `--force` required for updates after webhook or `DeployImage` plugin changes in order to overwritten the values.yaml and manager.yaml files.
1 parent 0df6220 commit 80d8487

File tree

75 files changed

+3688
-67
lines changed

Some content is hidden

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

75 files changed

+3688
-67
lines changed
+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Helm Testdata Sample
2+
3+
on:
4+
push:
5+
paths:
6+
- 'testdata/project-v4-with-plugins/**'
7+
- '.github/workflows/test-helm-samples.yml'
8+
pull_request:
9+
paths:
10+
- 'testdata/project-v4-with-plugins/**'
11+
- '.github/workflows/test-helm-samples.yml'
12+
13+
jobs:
14+
helm-test-project-v4-with-plugins:
15+
runs-on: ubuntu-latest
16+
strategy:
17+
fail-fast: true
18+
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@v4
22+
23+
- name: Setup Go
24+
uses: actions/setup-go@v5
25+
with:
26+
go-version: '~1.22'
27+
28+
- name: Install the latest version of kind
29+
run: |
30+
curl -Lo ./kind https://kind.sigs.k8s.io/dl/latest/kind-linux-amd64
31+
chmod +x ./kind
32+
sudo mv ./kind /usr/local/bin/kind
33+
34+
- name: Verify kind installation
35+
run: kind version
36+
37+
- name: Create kind cluster
38+
run: kind create cluster
39+
40+
- name: Prepare project-v4-with-plugins
41+
run: |
42+
cd testdata/project-v4-with-plugins/
43+
go mod tidy
44+
make docker-build IMG=project-v4-with-plugins:v0.1.0
45+
kind load docker-image project-v4-with-plugins:v0.1.0
46+
47+
- name: Install Helm
48+
run: |
49+
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
50+
51+
- name: Verify Helm installation
52+
run: helm version
53+
54+
- name: Lint Helm chart for project-v4-with-plugins
55+
run: |
56+
helm lint testdata/project-v4-with-plugins/dist/chart
57+
58+
- name: Install cert-manager via Helm
59+
run: |
60+
helm repo add jetstack https://charts.jetstack.io
61+
helm repo update
62+
helm install cert-manager jetstack/cert-manager --namespace cert-manager --create-namespace --set installCRDs=true
63+
64+
- name: Wait for cert-manager to be ready
65+
run: |
66+
kubectl wait --namespace cert-manager --for=condition=available --timeout=300s deployment/cert-manager
67+
kubectl wait --namespace cert-manager --for=condition=available --timeout=300s deployment/cert-manager-cainjector
68+
kubectl wait --namespace cert-manager --for=condition=available --timeout=300s deployment/cert-manager-webhook
69+
70+
- name: Install Helm chart for project-v4-with-plugins
71+
run: |
72+
helm install my-release testdata/project-v4-with-plugins/dist/chart --create-namespace --namespace project-v4-with-plugins-system
73+
74+
- name: Check Helm release status
75+
run: |
76+
helm status my-release --namespace project-v4-with-plugins-system

Makefile

+15-2
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,14 @@ generate-testdata: ## Update/generate the testdata in $GOPATH/src/sigs.k8s.io/ku
8080
./test/testdata/generate.sh
8181

8282
.PHONY: generate-docs
83-
generate-docs: ## Update/generate the docs in $GOPATH/src/sigs.k8s.io/kubebuilder
83+
generate-docs: ## Update/generate the docs
8484
./hack/docs/generate.sh
8585

86+
.PHONY: generate-charts
87+
generate-charts: ## Re-generate the helm chart testdata only
88+
rm -rf testdata/project-v4-with-plugins/dist/chart
89+
(cd testdata/project-v4-with-plugins && kubebuilder edit --plugins=helm/v1-alpha)
90+
8691
.PHONY: check-docs
8792
check-docs: ## Run the script to ensure that the docs are updated
8893
./hack/docs/check.sh
@@ -97,7 +102,7 @@ lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
97102

98103
.PHONY: yamllint
99104
yamllint:
100-
@files=$$(find testdata -name '*.yaml' ! -path 'testdata/*/dist/install.yaml'); \
105+
@files=$$(find testdata -name '*.yaml' ! -path 'testdata/*/dist/*'); \
101106
docker run --rm $$(tty -s && echo "-it" || echo) -v $(PWD):/data cytopia/yamllint:latest $$files -d "{extends: relaxed, rules: {line-length: {max: 120}}}" --no-warnings
102107

103108
GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint
@@ -171,3 +176,11 @@ test-spaces: ## Run the trailing spaces check
171176
test-legacy: ## Run the tests to validate legacy path for webhooks
172177
rm -rf ./testdata/**legacy**/
173178
./test/testdata/legacy-webhook-path.sh
179+
180+
.PHONY: install-helm
181+
install-helm: ## Install the latest version of Helm locally
182+
@curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
183+
184+
.PHONY: helm-lint
185+
helm-lint: install-helm ## Lint the Helm chart in testdata
186+
helm lint testdata/project-v4-with-plugins/dist/chart

cmd/main.go

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
deployimagev1alpha1 "sigs.k8s.io/kubebuilder/v4/pkg/plugins/golang/deploy-image/v1alpha1"
3131
golangv4 "sigs.k8s.io/kubebuilder/v4/pkg/plugins/golang/v4"
3232
grafanav1alpha1 "sigs.k8s.io/kubebuilder/v4/pkg/plugins/optional/grafana/v1alpha"
33+
helmv1alpha1 "sigs.k8s.io/kubebuilder/v4/pkg/plugins/optional/helm/v1alpha"
3334
)
3435

3536
func init() {
@@ -61,6 +62,7 @@ func main() {
6162
&kustomizecommonv2.Plugin{},
6263
&deployimagev1alpha1.Plugin{},
6364
&grafanav1alpha1.Plugin{},
65+
&helmv1alpha1.Plugin{},
6466
),
6567
cli.WithPlugins(externalPlugins...),
6668
cli.WithDefaultPlugins(cfgv3.Version, gov4Bundle),

docs/book/src/cronjob-tutorial/testdata/project/README.md

+26-5
Original file line numberDiff line numberDiff line change
@@ -68,27 +68,48 @@ make undeploy
6868

6969
## Project Distribution
7070

71-
Following are the steps to build the installer and distribute this project to users.
71+
Following the options to release and provide this solution to the users.
72+
73+
### By providing a bundle with all YAML files
7274

7375
1. Build the installer for the image built and published in the registry:
7476

7577
```sh
7678
make build-installer IMG=<some-registry>/project:tag
7779
```
7880

79-
NOTE: The makefile target mentioned above generates an 'install.yaml'
81+
**NOTE:** The makefile target mentioned above generates an 'install.yaml'
8082
file in the dist directory. This file contains all the resources built
81-
with Kustomize, which are necessary to install this project without
82-
its dependencies.
83+
with Kustomize, which are necessary to install this project without its
84+
dependencies.
8385

8486
2. Using the installer
8587

86-
Users can just run kubectl apply -f <URL for YAML BUNDLE> to install the project, i.e.:
88+
Users can just run 'kubectl apply -f <URL for YAML BUNDLE>' to install
89+
the project, i.e.:
8790

8891
```sh
8992
kubectl apply -f https://raw.githubusercontent.com/<org>/project/<tag or branch>/dist/install.yaml
9093
```
9194

95+
### By providing a Helm Chart
96+
97+
1. Build the chart using the optional helm plugin
98+
99+
```sh
100+
kubebuilder edit --plugins=helm/v1-alpha
101+
```
102+
103+
2. See that a chart was generated under 'dist/chart', and users
104+
can obtain this solution from there.
105+
106+
**NOTE:** If you change the project, you need to update the Helm Chart
107+
using the same command above to sync the latest changes. Furthermore,
108+
if you create webhooks, you need to use the above command with
109+
the '--force' flag and manually ensure that any custom configuration
110+
previously added to 'dist/chart/values.yaml' or 'dist/chart/manager/manager.yaml'
111+
is manually re-applied afterwards.
112+
92113
## Contributing
93114
// TODO(user): Add detailed information on how you would like others to contribute to this project
94115

docs/book/src/cronjob-tutorial/testdata/project/config/network-policy/allow-metrics-traffic.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This NetworkPolicy allows ingress traffic
22
# with Pods running on namespaces labeled with 'metrics: enabled'. Only Pods on those
3-
# namespaces are able to gathering data from the metrics endpoint.
3+
# namespaces are able to gather data from the metrics endpoint.
44
apiVersion: networking.k8s.io/v1
55
kind: NetworkPolicy
66
metadata:

docs/book/src/getting-started/testdata/project/README.md

+26-5
Original file line numberDiff line numberDiff line change
@@ -68,27 +68,48 @@ make undeploy
6868

6969
## Project Distribution
7070

71-
Following are the steps to build the installer and distribute this project to users.
71+
Following the options to release and provide this solution to the users.
72+
73+
### By providing a bundle with all YAML files
7274

7375
1. Build the installer for the image built and published in the registry:
7476

7577
```sh
7678
make build-installer IMG=<some-registry>/project:tag
7779
```
7880

79-
NOTE: The makefile target mentioned above generates an 'install.yaml'
81+
**NOTE:** The makefile target mentioned above generates an 'install.yaml'
8082
file in the dist directory. This file contains all the resources built
81-
with Kustomize, which are necessary to install this project without
82-
its dependencies.
83+
with Kustomize, which are necessary to install this project without its
84+
dependencies.
8385

8486
2. Using the installer
8587

86-
Users can just run kubectl apply -f <URL for YAML BUNDLE> to install the project, i.e.:
88+
Users can just run 'kubectl apply -f <URL for YAML BUNDLE>' to install
89+
the project, i.e.:
8790

8891
```sh
8992
kubectl apply -f https://raw.githubusercontent.com/<org>/project/<tag or branch>/dist/install.yaml
9093
```
9194

95+
### By providing a Helm Chart
96+
97+
1. Build the chart using the optional helm plugin
98+
99+
```sh
100+
kubebuilder edit --plugins=helm/v1-alpha
101+
```
102+
103+
2. See that a chart was generated under 'dist/chart', and users
104+
can obtain this solution from there.
105+
106+
**NOTE:** If you change the project, you need to update the Helm Chart
107+
using the same command above to sync the latest changes. Furthermore,
108+
if you create webhooks, you need to use the above command with
109+
the '--force' flag and manually ensure that any custom configuration
110+
previously added to 'dist/chart/values.yaml' or 'dist/chart/manager/manager.yaml'
111+
is manually re-applied afterwards.
112+
92113
## Contributing
93114
// TODO(user): Add detailed information on how you would like others to contribute to this project
94115

docs/book/src/getting-started/testdata/project/config/network-policy/allow-metrics-traffic.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This NetworkPolicy allows ingress traffic
22
# with Pods running on namespaces labeled with 'metrics: enabled'. Only Pods on those
3-
# namespaces are able to gathering data from the metrics endpoint.
3+
# namespaces are able to gather data from the metrics endpoint.
44
apiVersion: networking.k8s.io/v1
55
kind: NetworkPolicy
66
metadata:

docs/book/src/multiversion-tutorial/testdata/project/README.md

+26-5
Original file line numberDiff line numberDiff line change
@@ -68,27 +68,48 @@ make undeploy
6868

6969
## Project Distribution
7070

71-
Following are the steps to build the installer and distribute this project to users.
71+
Following the options to release and provide this solution to the users.
72+
73+
### By providing a bundle with all YAML files
7274

7375
1. Build the installer for the image built and published in the registry:
7476

7577
```sh
7678
make build-installer IMG=<some-registry>/project:tag
7779
```
7880

79-
NOTE: The makefile target mentioned above generates an 'install.yaml'
81+
**NOTE:** The makefile target mentioned above generates an 'install.yaml'
8082
file in the dist directory. This file contains all the resources built
81-
with Kustomize, which are necessary to install this project without
82-
its dependencies.
83+
with Kustomize, which are necessary to install this project without its
84+
dependencies.
8385

8486
2. Using the installer
8587

86-
Users can just run kubectl apply -f <URL for YAML BUNDLE> to install the project, i.e.:
88+
Users can just run 'kubectl apply -f <URL for YAML BUNDLE>' to install
89+
the project, i.e.:
8790

8891
```sh
8992
kubectl apply -f https://raw.githubusercontent.com/<org>/project/<tag or branch>/dist/install.yaml
9093
```
9194

95+
### By providing a Helm Chart
96+
97+
1. Build the chart using the optional helm plugin
98+
99+
```sh
100+
kubebuilder edit --plugins=helm/v1-alpha
101+
```
102+
103+
2. See that a chart was generated under 'dist/chart', and users
104+
can obtain this solution from there.
105+
106+
**NOTE:** If you change the project, you need to update the Helm Chart
107+
using the same command above to sync the latest changes. Furthermore,
108+
if you create webhooks, you need to use the above command with
109+
the '--force' flag and manually ensure that any custom configuration
110+
previously added to 'dist/chart/values.yaml' or 'dist/chart/manager/manager.yaml'
111+
is manually re-applied afterwards.
112+
92113
## Contributing
93114
// TODO(user): Add detailed information on how you would like others to contribute to this project
94115

docs/book/src/multiversion-tutorial/testdata/project/config/network-policy/allow-metrics-traffic.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This NetworkPolicy allows ingress traffic
22
# with Pods running on namespaces labeled with 'metrics: enabled'. Only Pods on those
3-
# namespaces are able to gathering data from the metrics endpoint.
3+
# namespaces are able to gather data from the metrics endpoint.
44
apiVersion: networking.k8s.io/v1
55
kind: NetworkPolicy
66
metadata:

0 commit comments

Comments
 (0)