Skip to content

Commit a88f78b

Browse files
committed
feat: add Helm Chart support with auto-generation from Kustomize
Signed-off-by: Wenxue Zhao <[email protected]>
1 parent c4d7a62 commit a88f78b

File tree

17 files changed

+1591
-45
lines changed

17 files changed

+1591
-45
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: 91 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,48 @@ vet: ## Run go vet against code.
7575
go vet ./...
7676

7777
.PHONY: test
78-
test: manifests generate fmt vet envtest ## Run tests.
78+
test: manifests generate fmt vet envtest helm-tool ## Run tests.
7979
ENVTEST_K8S_VERSION=$(ENVTEST_K8S_VERSION) \
80-
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test -v $$(go list ./... | grep -v /e2e) -coverprofile cover.out
80+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" \
81+
PATH="$(LOCALBIN):$(PATH)" \
82+
go test -v $$(go list ./... | grep -v /e2e) -coverprofile cover.out
83+
@echo "==> Validating Helm Chart generation..."
84+
$(MAKE) helm
85+
@echo "==> Running Helm lint..."
86+
$(HELM) lint helm/
87+
@echo "==> Testing Helm template rendering..."
88+
$(HELM) template test helm/ > /dev/null
89+
@echo "✅ All tests passed including Helm validation!"
8190

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

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

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

162213
ifndef ignore-not-found
@@ -206,6 +257,9 @@ ENVTEST ?= $(LOCALBIN)/setup-envtest
206257
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
207258
CRD_REF_DOCS ?= $(LOCALBIN)/crd-ref-docs
208259
KIND ?= $(LOCALBIN)/kind
260+
HELMIFY ?= $(LOCALBIN)/helmify
261+
YQ ?= $(LOCALBIN)/yq
262+
HELM ?= $(LOCALBIN)/helm
209263

210264
## Tool Versions
211265
KUSTOMIZE_VERSION = $(shell cd tools/mod && go list -m -f {{.Version}} sigs.k8s.io/kustomize/kustomize/v5)
@@ -214,6 +268,10 @@ ENVTEST_VERSION = $(shell cd tools/mod && go list -m -f {{.Version}} sigs.k8s.io
214268
GOLANGCI_LINT_VERSION = $(shell cd tools/mod && go list -m -f {{.Version}} github.com/golangci/golangci-lint/v2)
215269
CRD_REF_DOCS_VERSION = $(shell cd tools/mod && go list -m -f {{.Version}} github.com/elastic/crd-ref-docs)
216270
KIND_VERSION = $(shell cd tools/mod && go list -m -f {{.Version}} sigs.k8s.io/kind)
271+
HELMIFY_VERSION = $(shell cd tools/mod && go list -m -f {{.Version}} github.com/arttor/helmify)
272+
YQ_VERSION = $(shell cd tools/mod && go list -m -f {{.Version}} github.com/mikefarah/yq/v4)
273+
# Helm is not a Go module, must specify version directly
274+
HELM_VERSION ?= v3.17.0
217275

218276
.PHONY: kustomize
219277
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
@@ -245,6 +303,35 @@ golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
245303
$(GOLANGCI_LINT): $(LOCALBIN)
246304
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s -- -b $(LOCALBIN) $(GOLANGCI_LINT_VERSION)
247305

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

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)