Skip to content

Commit a33217c

Browse files
authored
Introducing new go module for API, remove g/g dependency (#988)
* removed dependency on vgopath and k8s.io/apiserver * removed ginkgo unit test and added golang native unit test for secret reconciler * removed g/g dependency * added generated client, moved code-gen scripts to api module, updated k8s dependencies * fixed unit tests and created a new Makefile target for unit tests in api go module * fixed issues reported by gosec * fixed ci check script * added clean-generated-code script * Fixed IT tests and modified .ci/check, removed GOTESTFMT tool * adapted api package change * removed check-apidiff and check-generate scripts - moved to api/hack and fixed skaffold, no need to have gcloud auth login * removed config, moved samples, generating pki resources, copying crds for helm, corrected helm charts, created client as go module * fixed crd paths to refer to api/core/crds in IT tests * added go.work * adopted go version check for multi-module go project * removed -mod=mod as it does not work with go workspaces * changed skaffold, now using latest version * e2e test script now call prepare-local-deploy * added helm chart usage doc, added new make target, corrected paths of pki resources and fixed skaffold debug profile config * added git_tags for client and api go modules ensuring proper tagging upon release * added allow dependency-type: all in dependabot, updated docs with links * using directories to specify multiple manifests for dependabot * upgraded helm to v3.16.4 * renamed chart template files and added NOTES.txt * added icon url to chart.yaml * now using make --directory to run API make targets from CI check script * added pipeline definition to push helm charts as OCI artifact * configured publish helmcharts for jobs * renamed samples to examples, refactored, added client example * removed go mod files from examples/client * added etcd-druid client dependency to parent go.mod * regenerated code with license header without YEAR for generated code * added new lines to helm template yaml files ----------- Co-authored-by: Saketh Kalaga <[email protected]> Co-authored-by: Sonu Kumar Singh <[email protected]>
1 parent 0c24c05 commit a33217c

File tree

275 files changed

+7553
-4697
lines changed

Some content is hidden

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

275 files changed

+7553
-4697
lines changed

.ci/check

+7-3
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,15 @@ cd /go/src/github.com/gardener/etcd-druid
1919
echo "> Running check..."
2020
make check
2121

22-
echo "> Running check-generate..."
23-
make check-generate
24-
2522
# Run Static Application Security Testing (SAST) using gosec
2623
echo "> Running SAST checks..."
2724
make sast-report
2825

26+
echo "Running API Make targets..."
27+
28+
make --directory=api \
29+
check \
30+
tidy \
31+
check-generate
32+
2933
echo -e "\n> All checks successful"

.ci/pipeline_definitions

+27
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11
etcd-druid:
2+
templates:
3+
helmcharts:
4+
- &etcd-druid-chart
5+
name: etcd-druid
6+
dir: charts
7+
registry: europe-docker.pkg.dev/gardener-project/snapshots/charts/gardener/etcd-druid
8+
mappings:
9+
- ref: ocm-resource:etcd-druid.repository
10+
attribute: image.repository
11+
- ref: ocm-resource:etcd-druid.tag
12+
attribute: image.tag
13+
214
base_definition:
315
repo:
416
source_labels:
@@ -58,9 +70,19 @@ etcd-druid:
5870
component_descriptor:
5971
ocm_repository_mappings:
6072
- repository: europe-docker.pkg.dev/gardener-project/releases
73+
options:
74+
public_build_logs: true
75+
publish:
76+
helmcharts:
77+
- *etcd-druid-chart
6178
pull-request:
6279
traits:
6380
pull-request: ~
81+
options:
82+
public_build_logs: true
83+
publish:
84+
helmcharts:
85+
- *etcd-druid-chart
6486
release:
6587
traits:
6688
version:
@@ -72,6 +94,9 @@ etcd-druid:
7294
etcd-druid:
7395
image: europe-docker.pkg.dev/gardener-project/releases/gardener/etcd-druid
7496
tag_as_latest: True
97+
helmcharts:
98+
- <<: *etcd-druid-chart
99+
registry: europe-docker.pkg.dev/gardener-project/releases/charts/gardener/etcd-druid
75100
release:
76101
nextversion: 'bump_minor'
77102
assets:
@@ -86,6 +111,8 @@ etcd-druid:
86111
see: https://github.com/securego/gosec
87112
git_tags:
88113
- ref_template: 'refs/tags/{VERSION}'
114+
- ref_template: 'refs/tags/api/{VERSION}'
115+
- ref_template: 'refs/tags/client/{VERSION}'
89116
release_callback: .ci/bump_tag
90117
slack:
91118
default_channel: 'internal_scp_workspace'

.github/dependabot.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
version: 2
1010
updates:
1111
- package-ecosystem: gomod
12-
directory: "/"
12+
directories:
13+
- "/"
14+
- "/api"
15+
- "/client"
1316
schedule:
1417
interval: monthly
1518
open-pull-requests-limit: 5

.gitignore

+24-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
/args
22
/bin
3-
/hack/tools/bin
4-
/hack/kind/*
53
/.kube-secrets
64
/tmp/*
75
/dev
@@ -14,9 +12,6 @@ default.bkp*
1412
/cover.out
1513
*coverprofile.out
1614
*.html
17-
.vscode
18-
.idea
19-
.DS_Store
2015
.ignore
2116
*~
2217

@@ -41,5 +36,29 @@ hack/e2e-test/infrastructure/kind/kubeconfig
4136
.cache_ggshield
4237
.gitguardian.yaml
4338

39+
# Binaries for programs and plugins
40+
*.exe
41+
*.exe~
42+
*.dll
43+
*.so
44+
*.dylib
45+
4446
# gosec
4547
gosec-report.sarif
48+
49+
# env file
50+
.env
51+
52+
# code editor ignores
53+
.vscode
54+
.idea
55+
.DS_Store
56+
57+
# hack tools binaries and generated configurations
58+
/hack/tools/bin/*
59+
/hack/kind/*
60+
api/hack/tools/bin/*
61+
62+
# generated/copied chart resources
63+
charts/pki-resources/*
64+
charts/crds/*

Makefile

+45-59
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
REPO_ROOT := $(shell dirname "$(realpath $(lastword $(MAKEFILE_LIST)))")
66
HACK_DIR := $(REPO_ROOT)/hack
7+
API_HACK_DIR := $(REPO_ROOT)/api/hack
78
VERSION := $(shell $(HACK_DIR)/get-version.sh)
89
GIT_SHA := $(shell git rev-parse --short HEAD || echo "GitNotFound")
910
REGISTRY_ROOT := europe-docker.pkg.dev/gardener-project
@@ -24,39 +25,16 @@ KUBECONFIG_PATH := $(HACK_DIR)/kind/kubeconfig
2425
TOOLS_DIR := $(HACK_DIR)/tools
2526
include $(HACK_DIR)/tools.mk
2627

27-
# Rules for generation (code and manifests)
28-
# -------------------------------------------------------------------------
29-
.PHONY: check-generate
30-
check-generate:
31-
@$(HACK_DIR)/check-generate.sh "$(REPO_ROOT)"
32-
33-
# Generate manifests e.g. CRD, RBAC etc.
34-
.PHONY: manifests
35-
manifests: $(VGOPATH) $(CONTROLLER_GEN)
36-
@HACK_DIR=$(HACK_DIR) VGOPATH=$(VGOPATH) go generate ./config/crd/bases
37-
@find "$(REPO_ROOT)/config/crd/bases" -name "*.yaml" -exec cp '{}' "$(REPO_ROOT)/charts/druid/charts/crds/templates/" \;
38-
@controller-gen rbac:roleName=manager-role paths="./internal/controller/..."
39-
40-
.PHONY: generate-api-docs
41-
generate-api-docs: $(CRD_REF_DOCS)
42-
@crd-ref-docs --source-path "$(REPO_ROOT)/api" --config "$(HACK_DIR)/api-reference/config.yaml" --output-path "$(REPO_ROOT)/docs/api-reference/etcd-druid-api.md" --renderer markdown
43-
44-
# Generate code
45-
.PHONY: generate
46-
generate: manifests generate-api-docs $(CONTROLLER_GEN) $(GOIMPORTS) $(MOCKGEN)
47-
@go generate "$(REPO_ROOT)/internal/..."
48-
@"$(HACK_DIR)/update-codegen.sh"
28+
ifndef CERT_EXPIRY_DAYS
29+
override CERT_EXPIRY_DAYS = 365
30+
endif
4931

5032
# Rules for verification, formatting, linting and cleaning
5133
# -------------------------------------------------------------------------
5234
.PHONY: tidy
5335
tidy:
5436
@env GO111MODULE=on go mod tidy
5537

56-
.PHONY: clean
57-
clean:
58-
@$(HACK_DIR)/clean.sh ./api/... ./internal/...
59-
6038
# Clean go mod cache
6139
.PHONY: clean-mod-cache
6240
clean-mod-cache:
@@ -74,16 +52,12 @@ add-license-headers: $(GO_ADD_LICENSE)
7452
# Format code and arrange imports.
7553
.PHONY: format
7654
format: $(GOIMPORTS_REVISER)
77-
@$(HACK_DIR)/format.sh ./api/ ./internal/ ./test/
55+
@$(HACK_DIR)/format.sh ./internal/ ./test/ ./examples/
7856

7957
# Check packages
8058
.PHONY: check
81-
check: $(GOLANGCI_LINT) $(GOIMPORTS) format manifests
82-
@$(HACK_DIR)/check.sh --golangci-lint-config=./.golangci.yaml ./api/... ./internal/...
83-
84-
.PHONY: check-apidiff
85-
check-apidiff: $(GO_APIDIFF)
86-
@$(HACK_DIR)/check-apidiff.sh
59+
check: $(GOLANGCI_LINT) $(GOIMPORTS) format
60+
@$(HACK_DIR)/check.sh --golangci-lint-config=./.golangci.yaml ./internal/...
8761

8862
.PHONY: sast
8963
sast: $(GOSEC)
@@ -97,17 +71,19 @@ sast-report: $(GOSEC)
9771
# -------------------------------------------------------------------------
9872
# Run tests
9973
.PHONY: test-unit
100-
test-unit: $(GINKGO) $(GOTESTFMT)
74+
test-unit: $(GINKGO)
10175
# run ginkgo unit tests. These will be ported to golang native tests over a period of time.
10276
@TEST_COVER=$(TEST_COVER) "$(HACK_DIR)/test.sh" ./internal/controller/etcdcopybackupstask/... \
103-
./internal/controller/secret/... \
10477
./internal/controller/utils/... \
10578
./internal/mapper/... \
10679
./internal/metrics/... \
107-
./internal/health/...
80+
./internal/health/... \
81+
./internal/utils/imagevector/...
82+
10883
# run the golang native unit tests.
109-
@TEST_COVER=$(TEST_COVER) "$(HACK_DIR)/test-go.sh" ./api/... \
84+
@TEST_COVER=$(TEST_COVER) "$(HACK_DIR)/test-go.sh" \
11085
./internal/controller/etcd/... \
86+
./internal/controller/secret/... \
11187
./internal/controller/compaction/... \
11288
./internal/component/... \
11389
./internal/errors/... \
@@ -116,7 +92,7 @@ test-unit: $(GINKGO) $(GOTESTFMT)
11692
./internal/webhook/...
11793

11894
.PHONY: test-integration
119-
test-integration: $(GINKGO) $(SETUP_ENVTEST) $(GOTESTFMT)
95+
test-integration: $(GINKGO) $(SETUP_ENVTEST)
12096
@SETUP_ENVTEST="true" "$(HACK_DIR)/test.sh" ./test/integration/...
12197
@SETUP_ENVTEST="true" "$(HACK_DIR)/test-go.sh" ./test/it/...
12298

@@ -131,6 +107,7 @@ test-cov-clean:
131107

132108
.PHONY: test-e2e
133109
test-e2e: $(KUBECTL) $(HELM) $(SKAFFOLD) $(KUSTOMIZE) $(GINKGO)
110+
@$(HACK_DIR)/prepare-chart-resources.sh $(BUCKET_NAME) $(CERT_EXPIRY_DAYS)
134111
@VERSION=$(VERSION) GIT_SHA=$(GIT_SHA) $(HACK_DIR)/e2e-test/run-e2e-test.sh $(PROVIDERS)
135112

136113
.PHONY: ci-e2e-kind
@@ -178,43 +155,47 @@ docker-clean:
178155
# -------------------------------------------------------------------------
179156
kind-up kind-down ci-e2e-kind ci-e2e-kind-azure ci-e2e-kind-gcs deploy-localstack deploy-fakegcs deploy-azurite test-e2e deploy deploy-dev deploy-debug undeploy: export KUBECONFIG = $(KUBECONFIG_PATH)
180157

158+
ifndef CLUSTER_NAME
159+
override CLUSTER_NAME = etcd-druid-e2e
160+
endif
161+
181162
.PHONY: kind-up
182163
kind-up: $(KIND)
183-
@$(HACK_DIR)/kind-up.sh
164+
@$(HACK_DIR)/kind-up.sh --cluster-name $(CLUSTER_NAME)
184165
@printf "\n\033[0;33m📌 NOTE: To target the newly created KinD cluster, please run the following command:\n\n export KUBECONFIG=$(KUBECONFIG_PATH)\n\033[0m\n"
185166

186167
.PHONY: kind-down
187168
kind-down: $(KIND)
188-
@$(HACK_DIR)/kind-down.sh
189-
190-
# Install CRDs into a cluster
191-
.PHONY: install
192-
install: manifests
193-
kubectl apply -f config/crd/bases
194-
195-
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
196-
.PHONY: deploy-via-kustomize
197-
deploy-via-kustomize: manifests $(KUSTOMIZE)
198-
kubectl apply -f config/crd/bases
199-
kustomize build config/default | kubectl apply -f -
169+
@$(HACK_DIR)/kind-down.sh --cluster-name $(CLUSTER_NAME)
200170

171+
# Make targets to deploy etcd-druid operator using skaffold
172+
# --------------------------------------------------------------------------------------------------------
201173
# Deploy controller to the Kubernetes cluster specified in the environment variable KUBECONFIG
202174
# Modify the Helm template located at charts/druid/templates if any changes are required
175+
176+
ifndef NAMESPACE
177+
override NAMESPACE = default
178+
endif
179+
180+
.PHONY: prepare-helm-charts
181+
prepare-helm-charts:
182+
@$(HACK_DIR)/prepare-chart-resources.sh $(NAMESPACE) $(CERT_EXPIRY_DAYS)
183+
203184
.PHONY: deploy
204-
deploy: $(SKAFFOLD) $(HELM)
205-
@VERSION=$(VERSION) GIT_SHA=$(GIT_SHA) $(SKAFFOLD) run -m etcd-druid
185+
deploy: $(SKAFFOLD) $(HELM) prepare-helm-charts
186+
@VERSION=$(VERSION) GIT_SHA=$(GIT_SHA) $(SKAFFOLD) run -m etcd-druid -n $(NAMESPACE)
206187

207188
.PHONY: deploy-dev
208-
deploy-dev: $(SKAFFOLD) $(HELM)
209-
@VERSION=$(VERSION) GIT_SHA=$(GIT_SHA) $(SKAFFOLD) dev --cleanup=false -m etcd-druid --trigger='manual'
189+
deploy-dev: $(SKAFFOLD) $(HELM) prepare-helm-charts
190+
@VERSION=$(VERSION) GIT_SHA=$(GIT_SHA) $(SKAFFOLD) dev --cleanup=false -m etcd-druid --trigger='manual' -n $(NAMESPACE)
210191

211192
.PHONY: deploy-debug
212-
deploy-debug: $(SKAFFOLD) $(HELM)
213-
@VERSION=$(VERSION) GIT_SHA=$(GIT_SHA) $(SKAFFOLD) debug --cleanup=false -m etcd-druid -p debug
193+
deploy-debug: $(SKAFFOLD) $(HELM) prepare-helm-charts
194+
@VERSION=$(VERSION) GIT_SHA=$(GIT_SHA) $(SKAFFOLD) debug --cleanup=false -m etcd-druid -p debug -n $(NAMESPACE)
214195

215196
.PHONY: undeploy
216197
undeploy: $(SKAFFOLD) $(HELM)
217-
$(SKAFFOLD) delete -m etcd-druid
198+
$(SKAFFOLD) delete -m etcd-druid -n $(NAMESPACE)
218199

219200
.PHONY: deploy-localstack
220201
deploy-localstack: $(KUBECTL)
@@ -226,4 +207,9 @@ deploy-azurite: $(KUBECTL)
226207

227208
.PHONY: deploy-fakegcs
228209
deploy-fakegcs: $(KUBECTL)
229-
@$(HACK_DIR)/deploy-fakegcs.sh
210+
@$(HACK_DIR)/deploy-fakegcs.sh
211+
212+
.PHONY: clean-chart-resources
213+
clean-chart-resources:
214+
@rm -f $(REPO_ROOT)/charts/crds/*.yaml
215+
@rm -rf $(REPO_ROOT)/charts/pki-resources/*

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![REUSE status](https://api.reuse.software/badge/github.com/gardener/etcd-druid)](https://api.reuse.software/info/github.com/gardener/etcd-druid) [![CI Build status](https://concourse.ci.gardener.cloud/api/v1/teams/gardener/pipelines/etcd-druid-master/jobs/master-head-update-job/badge)](https://concourse.ci.gardener.cloud/teams/gardener/pipelines/etcd-druid-master/jobs/master-head-update-job) [![Go Report Card](https://goreportcard.com/badge/github.com/gardener/etcd-druid)](https://goreportcard.com/report/github.com/gardener/etcd-druid) [![License: Apache-2.0](https://img.shields.io/badge/License-Apache--2.0-blue.svg)](LICENSE) [![Release](https://img.shields.io/github/v/release/gardener/etcd-druid.svg?style=flat)](https://github.com/gardener/etcd-druid) [![Go Reference](https://pkg.go.dev/badge/github.com/gardener/etcd-druid.svg)](https://pkg.go.dev/github.com/gardener/etcd-druid) [![Docs](https://img.shields.io/badge/Docs-reference-orange)](https://gardener.github.io/etcd-druid/index.html)
44

5-
`etcd-druid` is an [etcd](https://github.com/etcd-io/etcd) [operator](https://kubernetes.io/docs/concepts/extend-kubernetes/operator/) which makes it easy to configure, provision, reconcile, monitor and delete etcd clusters. It enables management of etcd clusters through [declarative Kubernetes API model](config/crd/bases/crd-druid.gardener.cloud_etcds.yaml).
5+
`etcd-druid` is an [etcd](https://github.com/etcd-io/etcd) [operator](https://kubernetes.io/docs/concepts/extend-kubernetes/operator/) which makes it easy to configure, provision, reconcile, monitor and delete etcd clusters. It enables management of etcd clusters through [declarative Kubernetes API model](api/core/crds/druid.gardener.cloud_etcds.yaml).
66

77
In every etcd cluster managed by `etcd-druid`, each etcd member is a two container `Pod` which consists of:
88

api/Makefile

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# SPDX-FileCopyrightText: 2025 SAP SE or an SAP affiliate company and Gardener contributors
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
API_MODULE_ROOT := $(shell dirname "$(realpath $(lastword $(MAKEFILE_LIST)))")
6+
REPO_ROOT := $(shell dirname "$(API_MODULE_ROOT)")
7+
HACK_DIR := $(API_MODULE_ROOT)/hack
8+
API_MODULE_TOOLS_DIR := $(HACK_DIR)/tools
9+
REPO_TOOLS_DIR := $(REPO_ROOT)/hack/tools
10+
11+
include $(HACK_DIR)/tools.mk
12+
13+
.PHONY: check-generate
14+
check-generate:
15+
@$(HACK_DIR)/check-generate.sh "$(API_MODULE_ROOT)"
16+
17+
.PHONY: generate-api-docs
18+
generate-api-docs: $(CRD_REF_DOCS)
19+
@crd-ref-docs --source-path "$(REPO_ROOT)/api" --config "$(HACK_DIR)/api-reference/config.yaml" --output-path "$(REPO_ROOT)/docs/api-reference/etcd-druid-api.md" --renderer markdown
20+
21+
.PHONY: check-apidiff
22+
check-apidiff: $(GO_APIDIFF)
23+
@$(HACK_DIR)/check-apidiff.sh
24+
25+
.PHONY: generate
26+
generate: $(CONTROLLER_GEN) tidy generate-api-docs
27+
@$(HACK_DIR)/generate.sh
28+
29+
.PHONY: clean-generated-code
30+
clean-generated-code:
31+
@$(HACK_DIR)/clean-generated-code.sh
32+
33+
.PHONY: tidy
34+
tidy:
35+
@env GO111MODULE=on go mod tidy
36+
37+
.PHONY: test-unit
38+
test-unit:
39+
@go test ./...
40+
41+
.PHONY: format
42+
format: $(GOIMPORTS_REVISER)
43+
@$(REPO_ROOT)/hack/format.sh ./core ./validation
44+
45+
.PHONY: check
46+
check: $(GOLANGCI_LINT) $(GOIMPORTS) format
47+
@$(REPO_ROOT)/hack/check.sh --golangci-lint-config=../.golangci.yaml ./...

0 commit comments

Comments
 (0)