Skip to content

Commit 44b30bf

Browse files
Merge pull request #114 from numtide/webhook
feat(webhook): add mutating and validating admission webhooks
2 parents da9aa10 + 8f5b5da commit 44b30bf

Some content is hidden

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

63 files changed

+6676
-411
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ dist/
1212
go.work
1313
go.work.sum
1414
cover.out
15+
*cover.out
1516
cover.html
1617
coverage/
17-
1818
# kubebuilder
1919
bin/
2020

@@ -23,4 +23,4 @@ kubeconfig.yaml
2323

2424

2525
# MacOS
26-
.DS_Store
26+
.DS_Store

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ repos:
66
- id: trailing-whitespace
77
- id: end-of-file-fixer
88
- id: check-yaml
9+
args: [--allow-multiple-documents]
910
- id: check-added-large-files
1011

1112
- repo: local

Makefile

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ CONTROLLER_TOOLS_VERSION ?= v0.18.0
9999
# renovate: datasource=github-releases depName=golangci/golangci-lint
100100
GOLANGCI_LINT_VERSION ?= v2.3.0
101101

102+
CERT_MANAGER_VERSION ?= v1.19.2
103+
102104
## Envtest
103105
#ENVTEST_VERSION is the version of controller-runtime release branch to fetch the envtest setup script (i.e. release-0.20)
104106
ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-%d.%d", $$2, $$3}')
@@ -134,11 +136,10 @@ help: ## Display this help.
134136

135137
.PHONY: manifests
136138
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
137-
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./api/..." output:crd:artifacts:config=config/crd/bases output:rbac:artifacts:config=config/rbac
138-
139+
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./api/...;./pkg/webhook/..." output:crd:artifacts:config=config/crd/bases output:rbac:artifacts:config=config/rbac output:webhook:artifacts:config=config/webhook
139140
.PHONY: generate
140141
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
141-
$(CONTROLLER_GEN) object paths="./api/..."
142+
$(CONTROLLER_GEN) object paths="./api/...;./pkg/webhook/..."
142143
# $(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
143144

144145
.PHONY: fmt
@@ -427,6 +428,30 @@ kind-deploy: kind-up manifests kustomize kind-load ## Deploy operator to kind cl
427428
@echo "==> Deployment complete!"
428429
@echo "Check status: KUBECONFIG=$(KIND_KUBECONFIG) kubectl get pods -n multigres-operator"
429430

431+
.PHONY: kind-deploy-certmanager
432+
kind-deploy-certmanager: kind-up install-certmanager manifests kustomize kind-load
433+
@echo "==> Installing CRDs..."
434+
KUBECONFIG=$(KIND_KUBECONFIG) $(KUSTOMIZE) build config/crd | \
435+
KUBECONFIG=$(KIND_KUBECONFIG) $(KUBECTL) apply --server-side -f -
436+
@echo "==> Deploying operator (Cert-Manager Mode)..."
437+
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
438+
# POINT TO THE OVERLAY:
439+
KUBECONFIG=$(KIND_KUBECONFIG) $(KUSTOMIZE) build config/deploy-certmanager | \
440+
KUBECONFIG=$(KIND_KUBECONFIG) $(KUBECTL) apply --server-side -f -
441+
@echo "==> Deployment complete!"
442+
@echo "Check status: KUBECONFIG=$(KIND_KUBECONFIG) kubectl get pods -n multigres-operator"
443+
444+
.PHONY: kind-deploy-no-webhook
445+
kind-deploy-no-webhook: kind-up install-certmanager manifests kustomize kind-load ## Deploy controller to Kind without the webhook enabled.
446+
@echo "==> Installing CRDs..."
447+
KUBECONFIG=$(KIND_KUBECONFIG) $(KUSTOMIZE) build config/crd | KUBECONFIG=$(KIND_KUBECONFIG) $(KUBECTL) apply --server-side -f -
448+
@echo "==> Deploying operator..."
449+
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
450+
KUBECONFIG=$(KIND_KUBECONFIG) $(KUSTOMIZE) build config/no-webhook | KUBECONFIG=$(KIND_KUBECONFIG) $(KUBECTL) apply --server-side -f -
451+
@echo "==> Deployment complete!"
452+
@echo "Check status: KUBECONFIG=$(KIND_KUBECONFIG) kubectl get pods -n multigres-operator"
453+
454+
430455
.PHONY: kind-redeploy
431456
kind-redeploy: kind-load ## Rebuild image, reload to kind, and restart pods
432457
@echo "==> Restarting operator pods..."
@@ -469,6 +494,13 @@ golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
469494
$(GOLANGCI_LINT): $(LOCALBIN)
470495
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
471496

497+
.PHONY: install-certmanager
498+
install-certmanager: ## Install Cert-Manager into the cluster
499+
@echo "==> Installing Cert-Manager $(CERT_MANAGER_VERSION)..."
500+
$(KUBECTL) apply -f https://github.com/cert-manager/cert-manager/releases/download/$(CERT_MANAGER_VERSION)/cert-manager.yaml
501+
@echo "==> Waiting for Cert-Manager to be ready..."
502+
$(KUBECTL) wait --for=condition=Available deployment --all -n cert-manager --timeout=300s
503+
472504
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
473505
# $1 - target path with name of binary
474506
# $2 - package url which can be installed

api/v1alpha1/multigrescluster_types.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,22 @@ import (
2222
)
2323

2424
// ============================================================================
25-
// RBAC Markers (Temporary Location)
25+
// RBAC Markers
2626
// ============================================================================
27-
//
28-
// TODO: Move these RBAC markers to the controller implementation
29-
// (pkg/cluster-handler/controller/multigrescluster/multigrescluster_controller.go)
30-
// to follow kubebuilder conventions. They are temporarily placed here because
31-
// controller-gen cannot process files in go.work modules.
32-
//
27+
28+
// -- Standard CRD Permissions --
3329
// +kubebuilder:rbac:groups=multigres.com,resources=multigresclusters,verbs=get;list;watch;create;update;patch;delete
3430
// +kubebuilder:rbac:groups=multigres.com,resources=multigresclusters/status,verbs=get;update;patch
3531
// +kubebuilder:rbac:groups=multigres.com,resources=multigresclusters/finalizers,verbs=update
3632
// +kubebuilder:rbac:groups=multigres.com,resources=coretemplates;celltemplates;shardtemplates,verbs=get;list;watch
3733
// +kubebuilder:rbac:groups=multigres.com,resources=cells;tablegroups;toposervers,verbs=get;list;watch;create;update;patch;delete
38-
// +kubebuilder:rbac:groups=apps,resources=deployments,verbs=get;list;watch;create;update;patch;delete
34+
// +kubebuilder:rbac:groups="",resources=events,verbs=create;patch
35+
36+
// -- Certificate Manager Permissions (ADDED) --
37+
// +kubebuilder:rbac:groups="",resources=secrets,verbs=get;list;watch;create;update;patch;delete
38+
// +kubebuilder:rbac:groups="",resources=services,verbs=get;list;watch
39+
// +kubebuilder:rbac:groups=apps,resources=deployments,verbs=get;list;watch;update;patch
40+
// +kubebuilder:rbac:groups=admissionregistration.k8s.io,resources=mutatingwebhookconfigurations;validatingwebhookconfigurations,verbs=get;list;watch;update;patch
3941

4042
// ============================================================================
4143
// MultigresClusterSpec Spec (User-editable API)

0 commit comments

Comments
 (0)