Skip to content

Commit 79621d0

Browse files
committed
Tidy up the build, standardize domains used for labels etc, fix tests and linting, add kustomize overlays for different environments
Signed-off-by: Kevin Conner <[email protected]>
1 parent f955721 commit 79621d0

Some content is hidden

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

59 files changed

+1383
-635
lines changed

.github/workflows/lint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ jobs:
1818
go-version-file: go.mod
1919

2020
- name: Run linter
21-
uses: golangci/golangci-lint-action@v6
21+
uses: golangci/golangci-lint-action@v8
2222
with:
23-
version: v1.63.4
23+
version: v2.3.0

.github/workflows/test-e2e.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,25 @@ jobs:
2626
- name: Verify kind installation
2727
run: kind version
2828

29+
- name: Install kubectl
30+
run: |
31+
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
32+
chmod +x kubectl
33+
sudo mv kubectl /usr/local/bin/kubectl
34+
35+
- name: Verify kubectl installation
36+
run: kubectl version --client
37+
2938
- name: Create kind cluster
3039
run: kind create cluster
3140

41+
- name: Wait for cluster to be ready
42+
run: |
43+
echo "Waiting for cluster to be ready..."
44+
kubectl wait --for=condition=Ready nodes --all --timeout=300s
45+
kubectl wait --for=condition=Ready --namespace=kube-system pod --all --timeout=300s
46+
echo "Cluster is ready"
47+
3248
- name: Running Test e2e
3349
run: |
3450
go mod tidy

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ cover.out
1111
*~
1212
.DS_Store
1313
*.iml
14+
# Don't include generated manifests
15+
manifests/*.yaml
16+
# Don't include generated bundles (will be built in CI/CD at some point)
17+
bundle/

.golangci.yml

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,17 @@
1+
version: "2"
2+
13
run:
24
timeout: 5m
35
allow-parallel-runners: true
46

5-
issues:
6-
# don't skip warning about doc comments
7-
# don't exclude the default set of lint
8-
exclude-use-default: false
9-
# restore some of the defaults
10-
# (fill in the rest as needed)
11-
exclude-rules:
12-
- path: "api/*"
13-
linters:
14-
- lll
15-
- path: "internal/*"
16-
linters:
17-
- dupl
18-
- lll
197
linters:
20-
disable-all: true
218
enable:
229
- dupl
2310
- errcheck
2411
- copyloopvar
2512
- ginkgolinter
2613
- goconst
2714
- gocyclo
28-
- gofmt
29-
- goimports
30-
- gosimple
3115
- govet
3216
- ineffassign
3317
- lll
@@ -36,12 +20,11 @@ linters:
3620
- prealloc
3721
- revive
3822
- staticcheck
39-
- typecheck
4023
- unconvert
4124
- unparam
4225
- unused
4326

44-
linters-settings:
45-
revive:
46-
rules:
47-
- name: comment-spacings
27+
formatters:
28+
enable:
29+
- gofmt
30+
- goimports
File renamed without changes.

Makefile

Lines changed: 110 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
2828
# This variable is used to construct full image tags for bundle and catalog images.
2929
#
3030
# For example, running 'make bundle-build bundle-push catalog-build catalog-push' will build and push both
31-
# sigstore.dev/model-validation-operator-bundle:$VERSION and sigstore.dev/model-validation-operator-catalog:$VERSION.
32-
IMAGE_TAG_BASE ?= sigstore.dev/model-validation-operator
31+
# ghcr.io/sigstore/model-validation-operator-bundle:$VERSION and ghcr.io/sigstore/model-validation-operator-catalog:$VERSION.
32+
IMAGE_TAG_BASE ?= ghcr.io/sigstore/model-validation-operator
3333

3434
# BUNDLE_IMG defines the image:tag used for the bundle.
3535
# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>)
@@ -38,6 +38,9 @@ BUNDLE_IMG ?= $(IMAGE_TAG_BASE)-bundle:v$(VERSION)
3838
# BUNDLE_GEN_FLAGS are the flags passed to the operator-sdk generate bundle command
3939
BUNDLE_GEN_FLAGS ?= -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
4040

41+
# BUNDLE_OVERLAY defines which overlay to use for bundle generation (e.g. make bundle BUNDLE_OVERLAY=production)
42+
BUNDLE_OVERLAY ?= olm
43+
4144
# USE_IMAGE_DIGESTS defines if images are resolved via tags or digests
4245
# You can enable this value if you would like to use SHA Based Digests
4346
# To enable set flag to true
@@ -48,7 +51,7 @@ endif
4851

4952
# Set the Operator SDK version to use. By default, what is installed on the system is used.
5053
# This is useful for CI or a project to utilize a specific version of the operator-sdk toolkit.
51-
OPERATOR_SDK_VERSION ?= v1.40.0
54+
OPERATOR_SDK_VERSION ?= v1.41.1
5255
# Image URL to use all building/pushing image targets
5356
IMG ?= controller:latest
5457

@@ -64,6 +67,9 @@ endif
6467
# scaffolded by default. However, you might want to replace it to use other
6568
# tools. (i.e. podman)
6669
CONTAINER_TOOL ?= docker
70+
# Dockerfile was renamed to Containerfile, presumably for podman support, however
71+
# this makefile explicitly mentions Dockerfile, so we parameterize it
72+
CONTAINER_FILE ?= Dockerfile
6773

6874
# Setting SHELL to bash allows bash commands to be executed by recipes.
6975
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
@@ -139,15 +145,44 @@ build: manifests generate fmt vet ## Build manager binary.
139145
go build -o bin/manager cmd/main.go
140146

141147
.PHONY: run
142-
run: manifests generate fmt vet ## Run a controller from your host.
148+
run: manifests generate fmt vet generate-local-certs ## Run a controller from your host.
143149
go run ./cmd/main.go
144150

151+
.PHONY: generate-certs
152+
generate-certs: ## Generate TLS certificates to specified directory (use CERT_DIR=path)
153+
@if [ -z "$(CERT_DIR)" ]; then \
154+
echo "Error: CERT_DIR must be specified. Usage: make generate-certs CERT_DIR=/path/to/certs"; \
155+
exit 1; \
156+
fi
157+
@echo "Generating TLS certificates in $(CERT_DIR)..."
158+
@if command -v cfssl &> /dev/null && [[ -f "generate-tls.sh" ]]; then \
159+
echo "Using cfssl-based certificate generation"; \
160+
./generate-tls.sh $(CERT_DIR); \
161+
elif [[ -f "generate-tls-openssl.sh" ]]; then \
162+
echo "Using OpenSSL-based certificate generation"; \
163+
./generate-tls-openssl.sh $(CERT_DIR); \
164+
else \
165+
echo "Error: No TLS generation script found. Either install cfssl or ensure generate-tls-openssl.sh exists."; \
166+
exit 1; \
167+
fi
168+
169+
.PHONY: generate-local-certs
170+
generate-local-certs: ## Generate TLS certificates for local development
171+
@echo "Generating local webhook certificates..."
172+
@CERT_DIR=$$(mktemp -d) && \
173+
$(MAKE) generate-certs CERT_DIR=$$CERT_DIR && \
174+
mkdir -p "$$TMPDIR/k8s-webhook-server/serving-certs" && \
175+
cp $$CERT_DIR/tls.crt "$$TMPDIR/k8s-webhook-server/serving-certs/" && \
176+
cp $$CERT_DIR/tls.key "$$TMPDIR/k8s-webhook-server/serving-certs/" && \
177+
echo "Certificates generated and placed in $$TMPDIR/k8s-webhook-server/serving-certs/" && \
178+
echo "You can now run 'make run' to start the controller with webhook support"
179+
145180
# If you wish to build the manager image targeting other platforms you can use the --platform flag.
146181
# (i.e. docker build --platform linux/arm64). However, you must enable docker buildKit for it.
147182
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
148183
.PHONY: docker-build
149-
docker-build: ## Build docker image with the manager.
150-
$(CONTAINER_TOOL) build -f Containerfile -t ${IMG} .
184+
docker-build: test ## Build docker image with the manager.
185+
$(CONTAINER_TOOL) build -t ${IMG} -f ${CONTAINER_FILE} .
151186

152187
.PHONY: docker-push
153188
docker-push: ## Push docker image with the manager.
@@ -163,18 +198,17 @@ PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
163198
.PHONY: docker-buildx
164199
docker-buildx: ## Build and push docker image for the manager for cross-platform support
165200
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
166-
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
201+
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' ${CONTAINER_FILE} > ${CONTAINER_FILE}.cross
167202
- $(CONTAINER_TOOL) buildx create --name model-validation-operator-builder
168203
$(CONTAINER_TOOL) buildx use model-validation-operator-builder
169-
- $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
204+
- $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f ${CONTAINER_FILE}.cross .
170205
- $(CONTAINER_TOOL) buildx rm model-validation-operator-builder
171-
rm Dockerfile.cross
206+
rm ${CONTAINER_FILE}.cross
172207

173208
.PHONY: build-installer
174-
build-installer: manifests generate kustomize ## Generate a consolidated YAML with CRDs and deployment.
175-
mkdir -p dist
176-
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
177-
$(KUSTOMIZE) build config/default > dist/install.yaml
209+
build-installer: manifests ## Generate a consolidated YAML with CRDs and deployment.
210+
./scripts/generate-manifests.sh production dist
211+
mv dist/production.yaml dist/install.yaml
178212

179213
##@ Deployment
180214

@@ -192,12 +226,13 @@ uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified
192226

193227
.PHONY: deploy
194228
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
195-
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
196-
$(KUSTOMIZE) build config/default | $(KUBECTL) apply -f -
229+
cd config/overlays/production && $(KUSTOMIZE) edit set image controller=${IMG}
230+
cd config/overlays/production && $(KUSTOMIZE) edit set replicas controller-manager=1
231+
$(KUSTOMIZE) build config/overlays/production | $(KUBECTL) apply -f -
197232

198233
.PHONY: undeploy
199234
undeploy: kustomize ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
200-
$(KUSTOMIZE) build config/default | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
235+
$(KUSTOMIZE) build config/overlays/production | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
201236

202237
##@ Dependencies
203238

@@ -215,13 +250,12 @@ ENVTEST ?= $(LOCALBIN)/setup-envtest
215250
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
216251

217252
## Tool Versions
218-
KUSTOMIZE_VERSION ?= v5.6.0
219-
CONTROLLER_TOOLS_VERSION ?= v0.17.2
220-
#ENVTEST_VERSION is the version of controller-runtime release branch to fetch the envtest setup script (i.e. release-0.20)
253+
KUSTOMIZE_VERSION ?= v5.7.0
254+
CONTROLLER_TOOLS_VERSION ?= v0.18.0
221255
ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-%d.%d", $$2, $$3}')
222256
#ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31)
223257
ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}')
224-
GOLANGCI_LINT_VERSION ?= v1.63.4
258+
GOLANGCI_LINT_VERSION ?= v2.3.0
225259

226260
.PHONY: kustomize
227261
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
@@ -239,7 +273,7 @@ setup-envtest: envtest ## Download the binaries required for ENVTEST in the loca
239273
@$(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path || { \
240274
echo "Error: Failed to set up envtest binaries for version $(ENVTEST_K8S_VERSION)."; \
241275
exit 1; \
242-
}
276+
} ; echo
243277

244278
.PHONY: envtest
245279
envtest: $(ENVTEST) ## Download setup-envtest locally if necessary.
@@ -249,7 +283,7 @@ $(ENVTEST): $(LOCALBIN)
249283
.PHONY: golangci-lint
250284
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
251285
$(GOLANGCI_LINT): $(LOCALBIN)
252-
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
286+
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
253287

254288
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
255289
# $1 - target path with name of binary
@@ -285,42 +319,49 @@ endif
285319
endif
286320

287321
.PHONY: bundle
288-
bundle: manifests kustomize operator-sdk ## Generate bundle manifests and metadata, then validate generated files.
322+
bundle: manifests kustomize operator-sdk ## Generate bundle manifests and metadata from $(BUNDLE_OVERLAY) overlay, then validate generated files.
289323
$(OPERATOR_SDK) generate kustomize manifests -q
290-
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
291-
$(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle $(BUNDLE_GEN_FLAGS)
324+
cd config/overlays/$(BUNDLE_OVERLAY) && $(KUSTOMIZE) edit set image controller=$(IMG)
325+
$(KUSTOMIZE) build config/overlays/$(BUNDLE_OVERLAY) | $(OPERATOR_SDK) generate bundle $(BUNDLE_GEN_FLAGS)
326+
# Fix webhook configuration in CSV
327+
@if [ -f bundle/manifests/model-validation-operator.clusterserviceversion.yaml ]; then \
328+
sed -i.bak 's/deploymentName: webhook/deploymentName: model-validation-controller-manager/' bundle/manifests/model-validation-operator.clusterserviceversion.yaml && \
329+
sed -i.bak2 's/deploymentName: model-validation-controller-manager/deploymentName: model-validation-controller-manager\n serviceName: model-validation-webhook/' bundle/manifests/model-validation-operator.clusterserviceversion.yaml && \
330+
rm -f bundle/manifests/model-validation-operator.clusterserviceversion.yaml.bak bundle/manifests/model-validation-operator.clusterserviceversion.yaml.bak2; \
331+
fi
292332
$(OPERATOR_SDK) bundle validate ./bundle
293333

294334
.PHONY: bundle-build
295335
bundle-build: ## Build the bundle image.
296-
$(CONTAINER_TOOL) build -f bundle.Dockerfile -t $(BUNDLE_IMG) .
336+
$(CONTAINER_TOOL) build -f bundle.${CONTAINER_FILE} -t $(BUNDLE_IMG) .
297337

298338
.PHONY: bundle-push
299339
bundle-push: ## Push the bundle image.
300340
$(MAKE) docker-push IMG=$(BUNDLE_IMG)
301341

302342
.PHONY: opm
303343
OPM = $(LOCALBIN)/opm
344+
OPM_VERSION=v1.56.0
304345
opm: ## Download opm locally if necessary.
305346
ifeq (,$(wildcard $(OPM)))
306347
ifeq (,$(shell which opm 2>/dev/null))
307348
@{ \
308349
set -e ;\
309350
mkdir -p $(dir $(OPM)) ;\
310351
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
311-
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.55.0/$${OS}-$${ARCH}-opm ;\
352+
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/${OPM_VERSION}/$${OS}-$${ARCH}-opm ;\
312353
chmod +x $(OPM) ;\
313354
}
314355
else
315356
OPM = $(shell which opm)
316357
endif
317358
endif
318359

319-
# A comma-separated list of bundle images (e.g. make catalog-build BUNDLE_IMGS=example.com/operator-bundle:v0.1.0,example.com/operator-bundle:v0.2.0).
360+
# A comma-separated list of bundle images (e.g. make catalog-build BUNDLE_IMGS=ghcr.io/sigstore/model-validation-operator-bundle:v0.1.0,ghcr.io/sigstore/model-validation-operator-bundle:v0.2.0).
320361
# These images MUST exist in a registry and be pull-able.
321362
BUNDLE_IMGS ?= $(BUNDLE_IMG)
322363

323-
# The image tag given to the resulting catalog image (e.g. make catalog-build CATALOG_IMG=example.com/operator-catalog:v0.2.0).
364+
# The image tag given to the resulting catalog image (e.g. make catalog-build CATALOG_IMG=ghcr.io/sigstore/model-validation-operator-catalog:v0.2.0).
324365
CATALOG_IMG ?= $(IMAGE_TAG_BASE)-catalog:v$(VERSION)
325366

326367
# Set CATALOG_BASE_IMG to an existing catalog image tag to add $BUNDLE_IMGS to that image.
@@ -333,9 +374,48 @@ endif
333374
# https://github.com/operator-framework/community-operators/blob/7f1438c/docs/packaging-operator.md#updating-your-existing-operator
334375
.PHONY: catalog-build
335376
catalog-build: opm ## Build a catalog image.
336-
$(OPM) index add --container-tool $(CONTAINER_TOOL) --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT)
377+
$(OPM) index add --container-tool ${CONTAINER_TOOL} --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT)
337378

338379
# Push the catalog image.
339380
.PHONY: catalog-push
340381
catalog-push: ## Push a catalog image.
341382
$(MAKE) docker-push IMG=$(CATALOG_IMG)
383+
384+
##@ Overlay Deployment
385+
386+
# Define available environments
387+
ENVIRONMENTS := testing production development olm
388+
389+
# Generic deployment target using generate-manifests script
390+
define deploy-environment
391+
.PHONY: deploy-$(1)
392+
deploy-$(1): manifests ## Deploy to $(1) environment
393+
./scripts/generate-manifests.sh $(1) manifests
394+
kubectl apply -f manifests/$(1).yaml
395+
endef
396+
397+
# Generic undeployment target
398+
define undeploy-environment
399+
.PHONY: undeploy-$(1)
400+
undeploy-$(1): ## Undeploy from $(1) environment
401+
kubectl delete -f manifests/$(1).yaml --ignore-not-found=true
402+
endef
403+
404+
# Generate targets for all environments
405+
$(foreach env,$(ENVIRONMENTS),$(eval $(call deploy-environment,$(env))))
406+
$(foreach env,$(ENVIRONMENTS),$(eval $(call undeploy-environment,$(env))))
407+
408+
# Convenience targets for all environments
409+
.PHONY: deploy-all
410+
deploy-all: $(addprefix deploy-,$(ENVIRONMENTS)) ## Deploy to all environments (use with caution)
411+
412+
.PHONY: undeploy-all
413+
undeploy-all: $(addprefix undeploy-,$(ENVIRONMENTS)) ## Undeploy from all environments
414+
415+
# Generate manifests using script (replaces removed render targets)
416+
.PHONY: generate-manifests
417+
generate-manifests: manifests ## Generate manifests for all environments using generate-manifests script
418+
@for env in $(ENVIRONMENTS); do \
419+
echo "Generating manifests for $$env environment..."; \
420+
./scripts/generate-manifests.sh $$env manifests; \
421+
done

0 commit comments

Comments
 (0)