Skip to content

Commit 67be641

Browse files
committed
feat: add Helm Chart support with auto-generation from Kustomize
Signed-off-by: Wenxue Zhao <ballista01@outlook.com>
1 parent 5359abd commit 67be641

File tree

15 files changed

+1415
-18
lines changed

15 files changed

+1415
-18
lines changed

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,12 @@ go.work
2828

2929
# macOS
3030
.DS_Store
31+
32+
# Helm Chart generated directory
33+
# The .gitignore inside helm/ controls specific ignored files
34+
helm/Chart.yaml
35+
helm/values.yaml
36+
helm/templates/
37+
helm/crds/
38+
helm/charts/
39+
helm/*.tgz

Makefile

Lines changed: 86 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,43 @@ vet: ## Run go vet against code.
7878
test: manifests generate fmt vet envtest ## Run tests.
7979
ENVTEST_K8S_VERSION=$(ENVTEST_K8S_VERSION) \
8080
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test -v $$(go list ./... | grep -v /e2e) -coverprofile cover.out
81+
@echo "==> Validating Helm Chart generation..."
82+
$(MAKE) helm
83+
@echo "==> Running Helm lint..."
84+
$(HELM) lint helm/
85+
@echo "==> Testing Helm template rendering..."
86+
$(HELM) template test helm/ > /dev/null
87+
@echo "✅ All tests passed including Helm validation!"
8188

8289
# TODO(user): To use a different vendor for e2e tests, modify the setup under 'tests/e2e'.
8390
# The default setup assumes Kind is pre-installed and builds/loads the Manager Docker image locally.
8491
# Prometheus and CertManager are installed by default; skip with:
8592
# - PROMETHEUS_INSTALL_SKIP=true
8693
# - CERT_MANAGER_INSTALL_SKIP=true
94+
#
95+
# DEPLOY_METHOD controls the deployment method for E2E tests:
96+
# - all (default): Test both deployment methods sequentially
97+
# - kustomize: Deploy using Kustomize only
98+
# - helm: Deploy using Helm Chart only
99+
DEPLOY_METHOD ?= all
100+
87101
.PHONY: test-e2e
88-
test-e2e: generate fmt vet kind ## Run the e2e tests. Expected an isolated environment using Kind.
89-
ETCD_VERSION="$(E2E_ETCD_VERSION)" PATH="$(LOCALBIN):$(PATH)" go test ./test/e2e/ -v
102+
test-e2e: generate fmt vet kind helm-tool ## Run the e2e tests. Expected an isolated environment using Kind.
103+
@if [ "$(DEPLOY_METHOD)" = "all" ]; then \
104+
echo "==> Testing all deployment methods..."; \
105+
echo ""; \
106+
echo "==> [1/2] Testing Kustomize deployment"; \
107+
DEPLOY_METHOD=kustomize ETCD_VERSION="$(E2E_ETCD_VERSION)" PATH="$(LOCALBIN):$(PATH)" go test ./test/e2e/ -v || exit 1; \
108+
echo ""; \
109+
echo "==> [2/2] Testing Helm deployment"; \
110+
$(MAKE) helm; \
111+
DEPLOY_METHOD=helm ETCD_VERSION="$(E2E_ETCD_VERSION)" PATH="$(LOCALBIN):$(PATH)" go test ./test/e2e/ -v || exit 1; \
112+
echo ""; \
113+
echo "✅ All deployment methods tested successfully!"; \
114+
else \
115+
echo "==> Testing with DEPLOY_METHOD=$(DEPLOY_METHOD)"; \
116+
ETCD_VERSION="$(E2E_ETCD_VERSION)" PATH="$(LOCALBIN):$(PATH)" go test ./test/e2e/ -v; \
117+
fi
90118

91119
.PHONY: lint
92120
lint: golangci-lint ## Run golangci-lint linter
@@ -157,6 +185,27 @@ build-installer: manifests generate kustomize ## Generate a consolidated YAML wi
157185
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
158186
$(KUSTOMIZE) build config/default > dist/install$(VERSION_SUFFIX).yaml
159187

188+
##@ Helm
189+
190+
.PHONY: helm
191+
helm: manifests kustomize helmify yq helm-tool ## Generate Helm Chart from Kustomize manifests.
192+
@echo "==> Generating Helm Chart..."
193+
@mkdir -p helm
194+
$(KUSTOMIZE) build config/default | $(HELMIFY) -crd-dir -image-pull-secrets helm
195+
@echo "==> Updating Chart metadata..."
196+
$(YQ) -i '.name = "etcd-operator"' helm/Chart.yaml
197+
$(YQ) -i '.description = "Official Kubernetes operator for etcd"' helm/Chart.yaml
198+
$(YQ) -i '.home = "https://github.com/etcd-io/etcd-operator"' helm/Chart.yaml
199+
@echo "==> Validating generated Chart..."
200+
@$(HELM) lint helm/ || (echo "❌ Helm Chart validation failed!" && exit 1)
201+
@echo "✅ Helm Chart generated and validated at helm/"
202+
203+
.PHONY: helm-lint
204+
helm-lint: helm ## Lint the generated Helm Chart.
205+
@echo "==> Linting Helm Chart..."
206+
@$(HELM) lint helm/
207+
@echo "✅ Helm Chart validation passed!"
208+
160209
##@ Deployment
161210

162211
ifndef ignore-not-found
@@ -206,6 +255,9 @@ ENVTEST ?= $(LOCALBIN)/setup-envtest
206255
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
207256
CRD_REF_DOCS ?= $(LOCALBIN)/crd-ref-docs
208257
KIND ?= $(LOCALBIN)/kind
258+
HELMIFY ?= $(LOCALBIN)/helmify
259+
YQ ?= $(LOCALBIN)/yq
260+
HELM ?= $(LOCALBIN)/helm
209261

210262
## Tool Versions
211263
KUSTOMIZE_VERSION = $(shell cd tools/mod && go list -m -f {{.Version}} sigs.k8s.io/kustomize/kustomize/v5)
@@ -214,6 +266,9 @@ ENVTEST_VERSION = $(shell cd tools/mod && go list -m -f {{.Version}} sigs.k8s.io
214266
GOLANGCI_LINT_VERSION = $(shell cd tools/mod && go list -m -f {{.Version}} github.com/golangci/golangci-lint/v2)
215267
CRD_REF_DOCS_VERSION = $(shell cd tools/mod && go list -m -f {{.Version}} github.com/elastic/crd-ref-docs)
216268
KIND_VERSION = $(shell cd tools/mod && go list -m -f {{.Version}} sigs.k8s.io/kind)
269+
HELMIFY_VERSION ?= v0.4.18
270+
YQ_VERSION ?= v4
271+
HELM_VERSION ?= v3.17.0
217272

218273
.PHONY: kustomize
219274
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
@@ -245,6 +300,35 @@ golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
245300
$(GOLANGCI_LINT): $(LOCALBIN)
246301
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s -- -b $(LOCALBIN) $(GOLANGCI_LINT_VERSION)
247302

303+
.PHONY: helmify
304+
helmify: $(HELMIFY) ## Download helmify locally if necessary.
305+
$(HELMIFY): $(LOCALBIN)
306+
$(call go-install-tool,$(HELMIFY),github.com/arttor/helmify/cmd/helmify,$(HELMIFY_VERSION))
307+
308+
.PHONY: yq
309+
yq: $(YQ) ## Download yq locally if necessary.
310+
$(YQ): $(LOCALBIN)
311+
$(call go-install-tool,$(YQ),github.com/mikefarah/yq/$(YQ_VERSION),latest)
312+
313+
.PHONY: helm-tool
314+
helm-tool: $(HELM) ## Download helm locally if necessary.
315+
$(HELM): $(LOCALBIN)
316+
@[ -f "$(HELM)-$(HELM_VERSION)" ] || { \
317+
set -e; \
318+
echo "Downloading Helm $(HELM_VERSION)"; \
319+
rm -f $(HELM) || true; \
320+
OS=$$(uname -s | tr '[:upper:]' '[:lower:]'); \
321+
ARCH=$$(uname -m); \
322+
case $$ARCH in \
323+
x86_64) ARCH=amd64 ;; \
324+
aarch64) ARCH=arm64 ;; \
325+
esac; \
326+
curl -sSL https://get.helm.sh/helm-$(HELM_VERSION)-$${OS}-$${ARCH}.tar.gz | \
327+
tar xz -C $(LOCALBIN) --strip-components=1 $${OS}-$${ARCH}/helm; \
328+
mv $(HELM) $(HELM)-$(HELM_VERSION); \
329+
}
330+
@ln -sf $(HELM)-$(HELM_VERSION) $(HELM)
331+
248332
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
249333
# $1 - target path with name of binary
250334
# $2 - package url which can be installed

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,25 @@ Participation in the Kubernetes community is governed by the [Kubernetes Code of
2424
- kubectl version v1.11.3+.
2525
- Access to a Kubernetes v1.11.3+ cluster.
2626

27-
### To Deploy on the cluster
27+
### Deployment Methods
28+
29+
The etcd-operator supports two deployment methods:
30+
31+
- **Helm**: Package management with easy configuration via values files
32+
- **Kustomize**: Simple, GitOps-friendly deployment
33+
34+
📦 **For Helm deployment**, see the [Helm Chart Documentation](helm/README.md) for:
35+
- Quick start guide
36+
- How the Chart is auto-generated from Kustomize
37+
- Customizing values and configuration
38+
- Example configurations (HA, minimal resources)
39+
- Upgrade and troubleshooting guides
40+
41+
The instructions below use **Kustomize** for deployment.
42+
43+
---
44+
45+
### To Deploy on the cluster (Kustomize)
2846

2947
**Build and push your image to the location specified by `IMG`:**
3048

config/crd/bases/operator.etcd.io_etcdclusters.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
33
kind: CustomResourceDefinition
44
metadata:
55
annotations:
6-
controller-gen.kubebuilder.io/version: v0.18.0
6+
controller-gen.kubebuilder.io/version: v0.19.0
77
name: etcdclusters.operator.etcd.io
88
spec:
99
group: operator.etcd.io

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ require (
1313
go.etcd.io/etcd/client/v3 v3.6.5
1414
go.etcd.io/etcd/server/v3 v3.6.5
1515
go.uber.org/zap v1.27.0
16+
gopkg.in/yaml.v3 v3.0.1
1617
k8s.io/api v0.34.1
1718
k8s.io/apimachinery v0.34.1
1819
k8s.io/client-go v0.34.1
@@ -118,7 +119,6 @@ require (
118119
gopkg.in/evanphx/json-patch.v4 v4.13.0 // indirect
119120
gopkg.in/inf.v0 v0.9.1 // indirect
120121
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
121-
gopkg.in/yaml.v3 v3.0.1 // indirect
122122
k8s.io/apiextensions-apiserver v0.34.1
123123
k8s.io/apiserver v0.34.1 // indirect
124124
k8s.io/component-base v0.34.1 // indirect

helm/.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Helm Chart generated files (created by helmify) - do not commit to Git
2+
# These files are generated by the `make helm` command
3+
Chart.yaml
4+
values.yaml
5+
templates/
6+
crds/
7+
charts/
8+
*.tgz
9+
10+
# Keep manually created example configs and documentation
11+
!examples/
12+
!README.md

helm/.helmignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*.orig
18+
*~
19+
# Various IDEs
20+
.project
21+
.idea/
22+
*.tmproj
23+
.vscode/

0 commit comments

Comments
 (0)