9da206dc7c
PVCs and CloudNativePG Clusters need S3 buckets and backup schedules
provisioned consistently. This operator watches the
backups.unkin.net/{schedule,destination} annotations on those objects and
provisions everything needed to back them up, with no new CRDs.
- Add a PVC controller that provisions cephrgw ObjectStoreUser/Bucket/BucketAccess,
auto-generates a restic repo-password Secret and creates a k8up Schedule scoped
to the PVC via spec.backup.volumes[].persistentVolumeClaim.claimName.
- Add a CNPG Cluster controller that provisions the same bucket stack, idempotently
patches spec.backup.barmanObjectStore (leaving a user-set destinationPath alone
with a Warning event) and creates a ScheduledBackup.
- Resolve destinations through a ConfigMap lookup table; requeue until the
BucketAccess is Ready before creating schedule resources; own-reference created
resources and retain bucket data by default.
- Add schedule-mapping helpers (k8up 5-field/shortcut pass-through, CNPG 6-field
seconds-first) and deterministic, length-bounded name derivation.
- Add unit tests (schedule mapping, name derivation, destination resolution) and
envtest controller tests for both paths, wiring the external CRDs into envtest.
- Add kubebuilder-generated RBAC, a Dockerfile (distroless/nonroot), Woodpecker
lint/test/build pipelines and a tag-triggered image push to the artifactapi
docker-internal registry, plus a version-bump Makefile and deploy manifests.
58 lines
1.9 KiB
Makefile
58 lines
1.9 KiB
Makefile
.PHONY: build test lint fmt generate docker-operator clean tidy envtest patch minor major
|
|
|
|
BINARY_OP := bin/autobackup-operator
|
|
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "0.0.0-dev")
|
|
|
|
ENVTEST_K8S_VERSION ?= 1.31.0
|
|
|
|
build: tidy
|
|
go build -ldflags="-s -w" -o $(BINARY_OP) ./cmd/operator
|
|
|
|
## envtest: fetch the envtest control-plane binaries and print KUBEBUILDER_ASSETS.
|
|
envtest:
|
|
go run sigs.k8s.io/controller-runtime/tools/setup-envtest@latest use $(ENVTEST_K8S_VERSION) -p path
|
|
|
|
## test: run unit + envtest controller tests. The controller tests skip
|
|
## gracefully when the envtest binaries cannot be fetched.
|
|
test:
|
|
KUBEBUILDER_ASSETS="$$(go run sigs.k8s.io/controller-runtime/tools/setup-envtest@latest use $(ENVTEST_K8S_VERSION) -p path 2>/dev/null)" \
|
|
go test -race -count=1 -mod=vendor ./...
|
|
|
|
lint:
|
|
go vet -mod=vendor ./...
|
|
|
|
fmt:
|
|
gofmt -w .
|
|
|
|
## generate: regenerate the RBAC ClusterRole from kubebuilder markers.
|
|
generate:
|
|
go run sigs.k8s.io/controller-tools/cmd/controller-gen@latest rbac:roleName=autobackup-operator \
|
|
paths="./internal/controller/..." output:rbac:dir=config/rbac
|
|
|
|
docker-operator:
|
|
docker build -t autobackup-operator:$(VERSION) -f Dockerfile.operator .
|
|
|
|
clean:
|
|
rm -rf bin/
|
|
|
|
tidy:
|
|
go mod tidy
|
|
|
|
_LATEST := $(shell git tag --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$$' | head -1)
|
|
_BASE := $(if $(_LATEST),$(_LATEST),v0.0.0)
|
|
_MAJ := $(shell echo $(_BASE) | sed 's/^v//' | cut -d. -f1)
|
|
_MIN := $(shell echo $(_BASE) | sed 's/^v//' | cut -d. -f2)
|
|
_PAT := $(shell echo $(_BASE) | sed 's/^v//' | cut -d. -f3)
|
|
|
|
patch:
|
|
@NEW=v$(_MAJ).$(_MIN).$(shell expr $(_PAT) + 1); \
|
|
git tag $$NEW && echo "Tagged $$NEW" && git push origin $$NEW
|
|
|
|
minor:
|
|
@NEW=v$(_MAJ).$(shell expr $(_MIN) + 1).0; \
|
|
git tag $$NEW && echo "Tagged $$NEW" && git push origin $$NEW
|
|
|
|
major:
|
|
@NEW=v$(shell expr $(_MAJ) + 1).0.0; \
|
|
git tag $$NEW && echo "Tagged $$NEW" && git push origin $$NEW
|