mirror of
https://github.com/hanzoai/kms-operator.git
synced 2026-10-30 18:32:57 +00:00
`make manifests` had been dead long enough that the generated install manifest
drifted to `ghcr.io/hanzoai/kms-operator:0.0.1` — a WORSE version than anything
running, so the documented install path would have downgraded a cluster. Three
faults, and the first two disguised each other.
**1. A stale go.work.sum entry, reported as a security error.**
controller-gen died on:
verifying github.com/luxfi/[email protected].2/go.mod: checksum mismatch
downloaded: h1:JJ7TxUmFCuH4/dJUmj9gDAKT2cJGL1v5g2pGyNPNJhU=
go.work.sum: h1:m4aMFbKYxwM2X4oPYRjq4LmDSShfCgAHnhmxIGKDyFU=
~/work/hanzo/go.work.sum held a hash recorded from a DIRECT fetch of a re-cut
tag. The public checksum database notarizes the other value:
sum.golang.org: github.com/luxfi/consensus v1.36.2/go.mod h1:JJ7TxUmFCuH4/…
and `luxfi` is not in GOPRIVATE, so that lookup is authoritative. Replacing the
workspace entry with the notarized pair is strictly MORE trustworthy, not a
bypass. Fixed in the workspace file, which unblocks the 12 member modules that
require this version — not just this repo.
**2. The real error was above 40 lines of marker help.**
With the checksum cleared, controller-gen still failed:
pattern ./...: directory prefix . does not contain modules listed in go.work
This repo sits under ~/work/hanzo but is NOT a member of its go.work, and Go
activates that workspace by proximity anyway, so `./...` matched nothing.
controller-gen prints that one line and then its full usage, so reading the tail
shows only help text and looks like a bad argument or a broken tool. It was
neither. `GOWORK=off` on both codegen targets.
**3. controller-tools was four years behind the runtime.**
`CONTROLLER_TOOLS_VERSION ?= v0.10.0` against controller-runtime v0.23.3 /
apimachinery v0.35.3. It cannot even be installed under Go 1.26 — it pulls
x/tools v0.16.1, which fails to compile with "invalid array length -delta *
delta". Moved to v0.20.1, the line that pulls apimachinery v0.35.
With those cleared, the generated tree changes as follows.
**CRD bases**: the group rename to `secrets.lux.network` had hit
config/crd/kustomization.yaml but never the files, which were still the
pre-rename `secrets.kms.com_*.yaml`, so `kustomize build config/default` failed
on missing resources. Regenerated correctly and the five stale bases deleted.
`secrets.lux.network` is right: api/v1alpha1/groupversion_info.go declares it
and all four clusters have exactly those CRDs.
**RBAC**: role.yaml shrinks by 57 lines, which is consolidation, NOT a
permission change — controller-gen merged rules with identical verb sets.
Verified by comparing effective (apiGroup, resource, verb) triples across the
diff: 60 before, 60 after, zero lost, zero gained.
**Password and UUID are now installed.** They are generator types consumed by a
KMSSecret's generatorRef rather than reconciled by their own controller, which
is presumably why they were never listed — but an uninstalled CRD is a KMSSecret
that fails at admission, and every cluster already has both. The install
manifest was describing a narrower operator than the one deployed.
The manifest now carries 5 CRDs against live's 6. The missing one,
`kmsdynamicsecrets`, has no Go type in this repo and is installed from some
other source; it is not something this Makefile can generate and is left alone
rather than hand-written.
Co-authored-by: Hanzo Dev <[email protected]>
222 lines
10 KiB
Makefile
222 lines
10 KiB
Makefile
|
|
# Image URL to use all building/pushing image targets.
|
|
#
|
|
# ⛔ This default was `:latest`, and that is not a cosmetic default — the
|
|
# `kubectl-install` target runs `kustomize edit set image controller=$(IMG)`,
|
|
# which REWRITES config/manager/kustomization.yaml. So any `make` run without an
|
|
# explicit IMG= silently un-pinned the checked-in version and wrote a floating
|
|
# tag back into git.
|
|
#
|
|
# That is how it actually played out: commit 9c864a6 ("deploy: pin :latest →
|
|
# semver across image refs") fixed the checked-in values, but left this line, so
|
|
# the next make run could put `:latest` straight back. Meanwhile three clusters
|
|
# — pars, bootnode and adnexus — were installed from a `:latest` build of this
|
|
# manifest and are still on it, on the SECRETS plane. Measured 2026-08-01: pars
|
|
# and adnexus run sha256:ae9242d5 while bootnode runs sha256:05e43c41, a build
|
|
# two days older. Same tag string, three clusters, two different binaries, and
|
|
# nothing in the manifest to reveal it.
|
|
#
|
|
# Deriving from the newest git tag means the default can never be a floating tag
|
|
# and there is no second version constant to drift from the one in `git tag`.
|
|
# Override for a scratch build with `make ... IMG=…` as before.
|
|
VERSION ?= $(shell git describe --tags --abbrev=0 2>/dev/null || echo v0.0.0)
|
|
IMG ?= ghcr.io/hanzoai/kms-operator:$(VERSION)
|
|
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
|
|
ENVTEST_K8S_VERSION = 1.25.0
|
|
|
|
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
|
|
ifeq (,$(shell go env GOBIN))
|
|
GOBIN=$(shell go env GOPATH)/bin
|
|
else
|
|
GOBIN=$(shell go env GOBIN)
|
|
endif
|
|
|
|
# Setting SHELL to bash allows bash commands to be executed by recipes.
|
|
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
|
|
SHELL = /usr/bin/env bash -o pipefail
|
|
.SHELLFLAGS = -ec
|
|
|
|
.PHONY: all
|
|
all: build
|
|
|
|
##@ General
|
|
|
|
# The help target prints out all targets with their descriptions organized
|
|
# beneath their categories. The categories are represented by '##@' and the
|
|
# target descriptions by '##'. The awk commands is responsible for reading the
|
|
# entire set of makefiles included in this invocation, looking for lines of the
|
|
# file as xyz: ## something, and then pretty-format the target and help. Then,
|
|
# if there's a line with ##@ something, that gets pretty-printed as a category.
|
|
# More info on the usage of ANSI control characters for terminal formatting:
|
|
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
|
|
# More info on the awk command:
|
|
# http://linuxcommand.org/lc3_adv_awk.php
|
|
|
|
.PHONY: help
|
|
help: ## Display this help.
|
|
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
|
|
|
|
|
|
# ## Chart - NOTE: change helper file to have 15 length for full name method
|
|
# helm-chart:
|
|
# $(KUSTOMIZE) build config/default | helmify ../helm-charts/secrets-operator
|
|
|
|
HELMIFY ?= $(LOCALBIN)/helmify
|
|
|
|
.PHONY: helmify
|
|
helmify: $(HELMIFY) ## Download helmify locally if necessary.
|
|
$(HELMIFY): $(LOCALBIN)
|
|
test -s $(LOCALBIN)/helmify || GOBIN=$(LOCALBIN) go install github.com/arttor/helmify/cmd/helmify@latest
|
|
|
|
legacy-helm: manifests kustomize helmify
|
|
$(KUSTOMIZE) build config/default | $(HELMIFY) ../helm-charts/secrets-operator
|
|
|
|
helm: manifests kustomize helmify
|
|
./scripts/generate-helm.sh
|
|
|
|
## Yaml for Kubectl
|
|
kubectl-install: manifests kustomize
|
|
mkdir -p kubectl-install
|
|
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
|
|
$(KUSTOMIZE) build config/default > kubectl-install/install-secrets-operator.yaml
|
|
|
|
##@ Development
|
|
|
|
# GOWORK=off on every codegen target.
|
|
#
|
|
# This repo lives under ~/work/hanzo, which carries a go.work that does NOT list
|
|
# it. Go still activates that workspace by proximity, so `paths="./..."` resolves
|
|
# against the workspace and matches nothing:
|
|
#
|
|
# pattern ./...: directory prefix . does not contain modules listed in
|
|
# go.work or their selected dependencies
|
|
#
|
|
# controller-gen prints that above ~40 lines of marker help, so reading the TAIL
|
|
# of the output shows only usage text and it looks like a bad argument or a
|
|
# broken tool. It is neither — the module graph simply excluded this package.
|
|
.PHONY: manifests
|
|
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
|
|
GOWORK=off $(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
|
|
|
|
.PHONY: generate
|
|
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
|
|
GOWORK=off $(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
|
|
|
|
.PHONY: fmt
|
|
fmt: ## Run go fmt against code.
|
|
go fmt ./...
|
|
|
|
.PHONY: vet
|
|
vet: ## Run go vet against code.
|
|
go vet ./...
|
|
|
|
.PHONY: test
|
|
test: manifests generate fmt vet envtest ## Run tests.
|
|
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out
|
|
|
|
##@ Build
|
|
|
|
.PHONY: build
|
|
build: manifests generate fmt vet ## Build manager binary.
|
|
go build -o bin/manager main.go
|
|
|
|
.PHONY: run
|
|
run: manifests generate fmt vet ## Run a controller from your host.
|
|
go run ./main.go
|
|
|
|
# If you wish built the manager image targeting other platforms you can use the --platform flag.
|
|
# (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it.
|
|
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
|
|
.PHONY: docker-build
|
|
docker-build: test ## Build docker image with the manager.
|
|
docker build -t ${IMG} .
|
|
|
|
.PHONY: docker-push
|
|
docker-push: ## Push docker image with the manager.
|
|
docker push ${IMG}
|
|
|
|
# PLATFORMS defines the target platforms for the manager image be build to provide support to multiple
|
|
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
|
|
# - able to use docker buildx . More info: https://docs.docker.com/build/buildx/
|
|
# - have enable BuildKit, More info: https://docs.docker.com/develop/develop-images/build_enhancements/
|
|
# - be able to push the image for your registry (i.e. if you do not inform a valid value via IMG=<myregistry/image:<tag>> then the export will fail)
|
|
# To properly provided solutions that supports more than one platform you should use this option.
|
|
PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
|
|
.PHONY: docker-buildx
|
|
docker-buildx: test ## Build and push docker image for the manager for cross-platform support
|
|
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
|
|
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
|
|
- docker buildx create --name project-v3-builder
|
|
docker buildx use project-v3-builder
|
|
- docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
|
|
- docker buildx rm project-v3-builder
|
|
rm Dockerfile.cross
|
|
|
|
##@ Deployment
|
|
|
|
ifndef ignore-not-found
|
|
ignore-not-found = false
|
|
endif
|
|
|
|
.PHONY: install
|
|
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
|
|
$(KUSTOMIZE) build config/crd | kubectl apply -f -
|
|
|
|
.PHONY: uninstall
|
|
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
|
|
$(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
|
|
|
|
.PHONY: deploy
|
|
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
|
|
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
|
|
$(KUSTOMIZE) build config/default | kubectl apply -f -
|
|
|
|
.PHONY: undeploy
|
|
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
|
|
$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
|
|
|
|
##@ Build Dependencies
|
|
|
|
## Location to install dependencies to
|
|
LOCALBIN ?= $(shell pwd)/bin
|
|
$(LOCALBIN):
|
|
mkdir -p $(LOCALBIN)
|
|
|
|
## Tool Binaries
|
|
KUSTOMIZE ?= $(LOCALBIN)/kustomize
|
|
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
|
|
ENVTEST ?= $(LOCALBIN)/setup-envtest
|
|
|
|
## Tool Versions
|
|
KUSTOMIZE_VERSION ?= v3.8.7
|
|
# controller-tools tracks a Kubernetes minor. v0.10.0 is from the
|
|
# controller-runtime v0.13 era, four years behind the v0.23.3 /
|
|
# apimachinery v0.35.3 this module actually builds against, and it cannot be
|
|
# installed here at all: `go install [email protected]` pulls golang.org/x/tools
|
|
# v0.16.1, which fails to compile under Go 1.26 with
|
|
# "invalid array length -delta * delta".
|
|
#
|
|
# v0.20.x is the line that pulls apimachinery v0.35, matching this go.mod.
|
|
CONTROLLER_TOOLS_VERSION ?= v0.20.1
|
|
|
|
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
|
|
.PHONY: kustomize
|
|
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading.
|
|
$(KUSTOMIZE): $(LOCALBIN)
|
|
@if test -x $(LOCALBIN)/kustomize && ! $(LOCALBIN)/kustomize version | grep -q $(KUSTOMIZE_VERSION); then \
|
|
echo "$(LOCALBIN)/kustomize version is not expected $(KUSTOMIZE_VERSION). Removing it before installing."; \
|
|
rm -rf $(LOCALBIN)/kustomize; \
|
|
fi
|
|
test -s $(LOCALBIN)/kustomize || { curl -Ss $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN); }
|
|
|
|
.PHONY: controller-gen
|
|
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten.
|
|
$(CONTROLLER_GEN): $(LOCALBIN)
|
|
test -s $(LOCALBIN)/controller-gen && $(LOCALBIN)/controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION) || \
|
|
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
|
|
|
|
.PHONY: envtest
|
|
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
|
|
$(ENVTEST): $(LOCALBIN)
|
|
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
|