Files
Miancheng Lin a83ace8713 refactor(controller): render the release CRDs from the controller chart (#2350)
* refactor(controller): render the release CRDs from the controller chart

The NVKE controller and management-engine no longer share CRDs, so the
nvke-crds subchart only added a helm dependency build step. Render the
three release CRDs from the controller chart's own files/crds and remove
the subchart, its Chart.lock and the build plumbing around it.

Signed-off-by: Miancheng Lin <mianchengl@nvidia.com>

* fix(controller): address review of the chart-owned release CRDs

Embed the controller chart file by file, so a stale charts/nvke-crds-*.tgz in
an existing checkout is not embedded and rendered a second time. Point the
generated-CRD check at the generator's fixed output path instead of the
overridable CHART. Keep the .gitignore entries for built chart dependencies and
dist/, which existing checkouts and the CLI build still use.

Signed-off-by: Miancheng Lin <mianchengl@nvidia.com>

---------

Signed-off-by: Miancheng Lin <mianchengl@nvidia.com>
2026-11-18 15:13:21 -05:00

579 lines
30 KiB
Makefile

# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
# strcase (vendored via teleport/api) asserts its Unicode tables match the
# stdlib's, so a toolchain newer than go.work's `go` directive panics at init.
# Pin every go invocation to it; an explicit GOTOOLCHAIN, as CI sets, still wins.
GOTOOLCHAIN ?= go$(shell awk '/^go /{print $$2; exit}' $(CURDIR)/../go.work)
export GOTOOLCHAIN
WORKER_BIN_NAME ?= controller
TEMPORAL_CLI_DOWNLOAD_DIR ?= $(CURDIR)/.go/temporal-cli
# The e2e-gofail settings are NVKE_CONTROLLER_GOFAIL_E2E_*. An empty value counts as unset.
gofail_e2e_worker_binary = $(or $(NVKE_CONTROLLER_GOFAIL_E2E_WORKER_BINARY),$(CURDIR)/.go/bin/cwe-worker-gofail)
GOFAIL ?= $(shell go env GOPATH)/bin/gofail
SETUP_ENVTEST ?= $(shell go env GOPATH)/bin/setup-envtest
# Explicit store, so CI can cache a known path instead of guessing setup-envtest's
# platform-dependent default.
ENVTEST_BIN_DIR ?= $(CURDIR)/.go/envtest
OIDC_LIVE_CAPD_NODE_IMAGE ?= cwe-capd-kindest-node:oidc-acceptance-jointoken
gofail_e2e_cluster_crds = $(or $(NVKE_CONTROLLER_GOFAIL_E2E_CLUSTER_CRDS),$(shell go env GOMODCACHE)/sigs.k8s.io/cluster-api@$(shell go list -m -f '{{.Version}}' sigs.k8s.io/cluster-api)/config/crd/bases)
gofail_e2e_capnico_crds = $(or $(NVKE_CONTROLLER_GOFAIL_E2E_CAPNICO_CRDS),$(shell go env GOMODCACHE)/github.com/dsx-ai-factory/cluster-api-provider-nico@$(shell go list -m -f '{{.Version}}' github.com/dsx-ai-factory/cluster-api-provider-nico)/config/crd/bases)
# The licence header template lives once, at the repository root.
REPO_ROOT ?= $(shell git rev-parse --show-toplevel)
# Go tool install location (GOPATH/bin, unless GOBIN is set); matches agent/Makefile.
GOBIN ?= $(shell go env GOBIN)
ifeq (,$(GOBIN))
GOBIN = $(shell go env GOPATH)/bin
endif
# golangci-lint pin and bootstrap, shared with every other module.
#
# Keep the workspace on so lint resolves the same module graph as builds.
GOLANGCI_LINT_GOWORK :=
include ../make/tool-versions.mk
include ../make/golangci.mk
include ../make/coverage.mk
# Image URL to use all building/pushing image targets
IMG_NAME ?= nvcr.io/j7sbcjl3qgta/nvke-controller
IMG_TAG ?= latest
IMG ?= ${IMG_NAME}:${IMG_TAG}
# The repository's bare vX.Y.Z tags version every component. Falls back to the
# commit before v0.0.0: a CI checkout is shallow and carries no tags, and
# without --always every binary CI built reported v0.0.0.
_BUILD_VERSION := $(shell git describe --tags --always --dirty --match 'v*' 2>/dev/null || echo "v0.0.0")
BUILD_VERSION ?= $(_BUILD_VERSION)
# Get the last git commit hash. If we are on CI depend on what it provides
# else use git describe.
ifdef CI
GIT_VERSION := $(CI_COMMIT_SHA)
else
GIT_VERSION ?= "$(shell git describe --always --dirty --match="" --abbrev=0)"
endif
# Include development environment targets
include Makefile.dev
.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)
##@ Build
.PHONY: lint
lint: ## Lint source files. (run by the merge gate)
@$(GOLANGCI_LINT_RUN) run --timeout 20m --concurrency 4 --max-same-issues 0 --max-issues-per-linter 0 ./...
##@ MachineImage and releases
# OS images and releases are MachineImage, ClusterRelease and NodePoolRelease
# custom resources. Argo CD applies the fleet's; the manifests under
# test/fixtures/releases are this repository's own set, maintained by hand.
RELEASE_CRD_DIR ?= $(REPO_ROOT)/controller/deploy/charts/controller/files/crds
RELEASE_CRD_NAMES ?= machineimages clusterreleases nodepoolreleases
RELEASES_DIR ?= $(CURDIR)/test/fixtures/releases
.PHONY: releases-install
releases-install: ## Install the release CRDs and apply RELEASES_DIR to the cluster in KUBECONFIG (for a controller run outside the chart).
@set -eu; \
for name in $(RELEASE_CRD_NAMES); do \
kubectl apply --server-side --field-manager=releases -f "$(RELEASE_CRD_DIR)/internal.nvke.nvidia.com_$$name.yaml"; \
kubectl wait --for=condition=Established --timeout=60s "crd/$$name.internal.nvke.nvidia.com"; \
done; \
kubectl apply --server-side --field-manager=releases -f "$(RELEASES_DIR)"
.PHONY: license
# Ignored on purpose: third-party text (nico-sim/ui/vendor, capnico-crds) and golden
# or chart files compared byte-for-byte or rendered by Helm (kubeadmconfig and tenantaccess
# testdata, deploy/charts). Templates and fixtures are not ignored.
license: ## Ensure license headers at code.
go run github.com/google/addlicense@$(ADDLICENSE_VERSION) -f $(REPO_ROOT)/hack/license-header.tmpl -c "NVIDIA CORPORATION & AFFILIATES" -ignore '.local/**' -ignore 'hack/**' -ignore 'test/fixtures/capnico-crds/**' -ignore '**/testUserData.yaml' -ignore 'internal/kubeadmconfig/testdata/**' -ignore 'internal/controllers/tenantaccess/testdata/**' -ignore 'nico-sim/ui/vendor/**' -ignore 'nico-sim/.dev/**' -ignore 'deploy/charts/**' .
# Expected to be run on clean working directory.
.PHONY: file-license-check
file-license-check: license ## Verify all files have license headers.
@if ! git diff --exit-code -- . ':!.go/' > /dev/null 2>&1; then \
echo "License headers are missing or outdated. Please run 'make license' locally and commit the changes."; \
echo "Files with missing/outdated license headers:"; \
git diff --name-only -- . ':!.go/'; \
exit 1; \
fi
.PHONY: generate
generate: ## Run every generator in this module and in api/.
go generate ./...
$(MAKE) generate-api
# Split out from `generate` so it can run without the rest of the module.
# Every //go:generate directive in the controller currently lives in
# api/generate.go, but `go generate ./...` above still has to load this
# module's package graph -- which may need public module downloads. The api
# module has neither problem: it is self-contained, so this target is the half
# that CI can run.
# GOWORK=off, so the self-contained api module is resolved on its own, and
# GOTOOLCHAIN pinned to the Go version api/go.mod declares, which is the version
# generate-check.yml installs. The embedded copy of openapi.yaml in server.gen.go
# is gzip-compressed and compress/flate output differs between Go releases, so a
# newer toolchain (go.work asks for one) regenerates a different blob and the
# gate rejects it.
.PHONY: generate-api
generate-api: ## Regenerate the OpenAPI client, server and models.
cd api && GOWORK=off GOTOOLCHAIN=go$$(awk '/^go /{print $$2; exit}' go.mod) go generate ./...
# Verify the committed oapi-codegen output is reproducible with the pinned
# generator (api/oapi-codegen.mod) and in sync with api/openapi.yaml. Catches an
# un-pinned/wrong generator or an openapi.yaml edit that was not regenerated.
# Expected to be run on a clean working directory.
.PHONY: generate-check
generate-check: generate-api ## Verify generated API code is up to date. (run by the merge gate)
@if ! git diff --exit-code -- api/models.gen.go api/server.gen.go api/client.gen.go > /dev/null 2>&1; then \
echo "Generated API code is out of date. Please run 'make generate' locally and commit the changes."; \
echo "Out-of-date files:"; \
git diff --name-only -- api/models.gen.go api/server.gen.go api/client.gen.go; \
exit 1; \
fi
@# git diff says nothing about a path git is not tracking, so a newly
@# generated file would otherwise pass while never being committed. Same
@# guard as Makefile's licences-check.
@untracked=$$(git ls-files --others --exclude-standard -- api/models.gen.go api/server.gen.go api/client.gen.go); \
[ -z "$$untracked" ] \
|| { echo "ERROR: generated API files are not tracked. Run 'make generate' and commit them:"; printf '%s\n' "$$untracked" | sed 's/^/ /'; exit 1; }
# The layer above generate-check. That target proves the committed Go matches
# api/openapi.yaml; it says nothing about whether the specification change is
# safe for an existing client. A removed field or a newly required property
# regenerates perfectly and breaks every one of them.
#
# The baseline is the newest published controller/api version tag, not the merge
# base: the tag is what a consumer can pin, so it is the only ref against which
# "backward compatible" means anything to them. Override it with
# API_COMPAT_BASELINE=<ref> to compare against something else.
#
# It needs tags. A shallow CI checkout has none, and the target fails rather
# than silently comparing against nothing -- see hack/openapi-compat/README.md.
API_COMPAT_BASELINE ?=
API_COMPAT_REPORT ?=
.PHONY: api-compat-check
api-compat-check: ## Verify api/openapi.yaml is backward compatible with the newest published controller/api tag. (run by the merge gate)
go run ./hack/openapi-compat \
--differ-version $(OPENAPI_CHANGES_VERSION) \
$(if $(API_COMPAT_BASELINE),--baseline $(API_COMPAT_BASELINE),) \
$(if $(API_COMPAT_REPORT),--report-out $(API_COMPAT_REPORT),)
RELEASE_LDFLAGS ?= -s -w -buildid= -extldflags -static
# Read one variable, so a caller that needs the same value this Makefile computes
# does not recompute it. `make print-BUILD_VERSION` is the one the E2E uses.
.PHONY: print-%
print-%:
@echo '$($*)'
.PHONY: build
# -buildvcs=false because the version comes from the -X ldflag below.
build: ## Build controller into bin/.
CGO_ENABLED=0 go build -buildvcs=false -trimpath -ldflags "-X github.com/dsx-ai-factory/nvke/controller/internal/version.Version=${BUILD_VERSION} $(RELEASE_LDFLAGS)" -o ./bin/$(WORKER_BIN_NAME) ./cmd/worker/
.PHONY: fmt
fmt: ## Format code (gofumpt + goimports; matches .golangci.yml formatters).
go run mvdan.cc/gofumpt@$(GOFUMPT_VERSION) -w -extra .
go run golang.org/x/tools/cmd/goimports@$(GOIMPORTS_VERSION) -w -local github.com/dsx-ai-factory/nvke/controller .
# GO_TEST_FLAGS lets CI add -race without the workflow having to restate the
# test command, so `make test` stays the one definition of what "the tests" are.
GO_TEST_FLAGS ?=
.PHONY: test
test: ## Execute unit tests (excludes integration tests). (run by the merge gate)
# The profile lands in the repository-root coverage/ directory now, not in
# coverage.txt beside this Makefile. make/coverage.mk owns the path and the
# mode for every module, and hack/coverage.sh reads that one directory.
# What has not changed: no threshold gates on the number it holds. See
# docs/coverage-policy.md for why a percentage is not test adequacy.
#
# The cobertura.xml conversion that used to follow is gone. It existed for
# GitLab's coverage visualisation, and that pipeline is gone -- no
# .gitlab-ci.yml, no workflow reading either file, and both are gitignored.
# It cost about 9 seconds of download and compile per run on a cold cache,
# and pulled golang.org/x/tools, 15 MB, to convert one file to XML.
#
# integration-test/ is behind the `integration_test` build tag, so
# `go list ./...` no longer needs filtering here. The old grep matched
# by accident anyway: `.` is a regex wildcard, not a path prefix.
@$(COVERAGE_MKDIR)
go test $(GO_TEST_FLAGS) $(GO_COVER_FLAGS) ./...
# The `integration` build tag covers two packages here, and neither needs a
# service to be running. internal/agent binds a loopback socket and mints its
# own certificates; internal/teleport skips every tagged test unless
# TELEPORT_ENABLED is set. Kept out of `test` above so a developer with
# TELEPORT_ENABLED exported does not reach a live Teleport from a unit run.
.PHONY: test-integration-local
test-integration-local: ## Execute the `integration`-tagged tests that need no external service. (run by the merge gate)
go test $(GO_TEST_FLAGS) -tags=integration -count=1 ./internal/agent/... ./internal/teleport/...
.PHONY: test-integration
test-integration: ## Execute tests against a running controller deployment.
@echo "Running integration tests..."
cd integration-test && go test -tags integration_test -timeout=3h
.PHONY: test-health
test-health: ## Run the health-labeled subset of the test/e2e suite against the cluster in KUBECONFIG.
$(MAKE) test-e2e E2E_TIMEOUT=10m ARGS='--label-filter=health'
# The authentication specs. Both need deploy/k8s/nvke-auth-dev.yaml applied and
# an enforcing NVKE; the chart binds the JWKS read permission.
#
# The SPIRE spec carries both labels, so test-authn runs it too; it skips itself
# with a message naming deploy/k8s/nvke-spire-client.yaml when that scaffolding
# is absent. test-authn-spire is the way to run only that one.
#
# The permissive specs have no target: they need an NVKE deployed with
# apiAuth.permissive: true, which is a different deployment. Run them against one
# with `make test-e2e ARGS='--label-filter=authn-permissive'`.
.PHONY: test-authn
test-authn: ## Run the authn-labeled subset of the test/e2e suite against the cluster in KUBECONFIG.
$(MAKE) test-e2e E2E_TIMEOUT=20m ARGS='--label-filter=authn'
.PHONY: test-authn-spire
test-authn-spire: ## Run the SPIRE JWT-SVID authentication spec against the cluster in KUBECONFIG.
$(MAKE) test-e2e E2E_TIMEOUT=20m ARGS='--label-filter=authn-spire'
.PHONY: test-integration-teleport
test-integration-teleport: ## Execute Teleport client integration tests (requires valid credentials).
@bash -c '[ -f .env.local ] && set -a && source .env.local && set +a; \
go test -tags=integration -timeout=2m ./internal/teleport/...'
E2E_DIR := test/e2e
E2E_TIMEOUT ?= 2h
OIDC_ACCEPTANCE_LABEL_FILTER ?= oidc-acceptance
# Ginkgo CLI flags, e.g. ARGS='--label-filter="nico-vms && happy-path"'
ARGS ?=
.PHONY: test-e2e
test-e2e: ## Run all NVKE e2e tests; optional ARGS forwards ginkgo flags Example: make test-e2e ARGS='--label-filter="nico-vms && happy-path"'
cd $(E2E_DIR) && go run github.com/onsi/ginkgo/v2/ginkgo@$(GINKGO_VERSION) run -v --timeout=$(E2E_TIMEOUT) $(ARGS) .
.PHONY: test-e2e-core-capd test-e2e-core-nico-containers test-e2e-happy-path
test-e2e-core-capd: ## Run the bounded CAPD create, readiness, and delete lifecycle.
make test-e2e ARGS='--fail-on-empty --label-filter="core-docker"'
test-e2e-core-nico-containers: ## Run the bounded NICo containers create, readiness, and delete lifecycle.
make test-e2e ARGS='--fail-on-empty --label-filter="core-nico"'
test-e2e-happy-path: ## Run CAPD and NICo VMs happy-path e2e tests
make test-e2e ARGS='--label-filter="happy-path && (lifecycle || readiness) && !scale && !upgrade && !reboot"'
.PHONY: test-e2e-capd
test-e2e-capd: ## Run CAPD happy-path e2e tests
make test-e2e ARGS='--label-filter="capd && happy-path && (lifecycle || readiness) && !scale && !upgrade && !reboot"'
.PHONY: test-e2e-capd-local
test-e2e-capd-local: ## Run all CAPD e2e tests with local controller and agent source. macOS bootstraps Colima; Linux uses the host Docker daemon.
./hack/local-backend-e2e.sh
.PHONY: oidc-envtest-assets test-oidc-reference test-oidc-acceptance-live
oidc-envtest-assets: ## Install the pinned setup-envtest and resolve the pinned Kubernetes assets.
@mkdir -p "$(dir $(SETUP_ENVTEST))" "$(ENVTEST_BIN_DIR)"
@GOBIN="$(dir $(SETUP_ENVTEST))" go install sigs.k8s.io/controller-runtime/tools/setup-envtest@$(SETUP_ENVTEST_VERSION)
@"$(SETUP_ENVTEST)" use $(ENVTEST_K8S_VERSION) --bin-dir "$(ENVTEST_BIN_DIR)" -p path
test-oidc-reference: oidc-envtest-assets ## Run the production-rendered OIDC config against envtest.
@set -euo pipefail; \
KUBEBUILDER_ASSETS="$$($(SETUP_ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir "$(ENVTEST_BIN_DIR)" -p path)"; \
test -n "$$KUBEBUILDER_ASSETS" || { echo "setup-envtest selected no Kubernetes $(ENVTEST_K8S_VERSION) assets" >&2; exit 1; }; \
output_file="$$(mktemp)"; \
trap 'rm -f "$$output_file"' EXIT; \
status=0; \
ENVTEST_K8S_VERSION="$(ENVTEST_K8S_VERSION)" KUBEBUILDER_ASSETS="$$KUBEBUILDER_ASSETS" go test -v -tags=oidc_integration -count=1 ./test/oidctest/... 2>&1 | tee "$$output_file" || status=$$?; \
test "$$status" -eq 0 || exit "$$status"; \
grep -Fq -- "--- PASS: TestReferenceOIDCAuthenticationMatrix (" "$$output_file" && \
grep -Eq -- "--- PASS: TestReferenceOIDCAuthenticationMatrix/[^/]+/[^/]+ [(]" "$$output_file" || \
{ echo "OIDC reference matrix and its cases must run and pass" >&2; exit 1; }
test-oidc-acceptance-live: ## Run the tagged OIDC lifecycle on a fresh local CAPD management cluster.
@set -eu; \
if [ "$$(uname -s)" = Darwin ]; then \
export COLIMA_CPUS="$${COLIMA_CPUS:-10}" COLIMA_MEMORY_GIB="$${COLIMA_MEMORY_GIB:-24}" COLIMA_DISK_GIB="$${COLIMA_DISK_GIB:-150}"; \
export DOCKER_HOST="$${DOCKER_HOST:-$(COLIMA_DOCKER_HOST)}"; \
export COLIMA_DOCKER_HOST="$$DOCKER_HOST"; \
$(MAKE) host-up; \
fi; \
if ! docker image inspect "$(OIDC_LIVE_CAPD_NODE_IMAGE)" >/dev/null 2>&1; then \
$(MAKE) capd-image \
COLIMA_DOCKER_HOST="$${DOCKER_HOST:-$(COLIMA_DOCKER_HOST)}" \
CAPD_KINDEST_NODE_IMAGE="$(OIDC_LIVE_CAPD_NODE_IMAGE)" \
CAPD_SPIRE_ATTESTATION_METHOD=joinToken \
INSTALL_CNI_AFTER_INIT=true; \
fi; \
run_id="$$(date +%s)-$$$$"; \
kind_cluster_name="nke-oidc-live-$$run_id"; \
providers="$${LOCAL_NKE_E2E_PROVIDERS:-}"; \
if test -z "$$providers" && \
test "$$(docker inspect --format '{{.State.Running}}' "$${BGP_CONTAINER_NAME:-bgp-containers}" 2>/dev/null || true)" = true; then \
providers='["capi_core","capd","capd-reboot-controller"]'; \
fi; \
KIND_CLUSTER_NAME="$$kind_cluster_name" \
CAPD_KINDEST_NODE_IMAGE="$(OIDC_LIVE_CAPD_NODE_IMAGE)" \
CAPD_NODE_IMAGE="$(OIDC_LIVE_CAPD_NODE_IMAGE)" \
CAPD_SPIRE_ATTESTATION_METHOD=joinToken \
LOCAL_NKE_E2E_REUSE_CAPD_NODE_IMAGE=true \
LOCAL_NKE_E2E_STATE_DIR="$(CURDIR)/.local/nke-oidc-live-$$run_id" \
LOCAL_NKE_E2E_KUBECONFIG="$(CURDIR)/.local/nke-oidc-live-$$run_id/management.kubeconfig" \
LOCAL_NKE_E2E_BUILD_TAGS=oidc_acceptance \
LOCAL_NKE_E2E_LABEL_FILTER="$(OIDC_ACCEPTANCE_LABEL_FILTER)" \
LOCAL_NKE_E2E_PROVIDERS="$$providers" \
INSTALL_CNI_AFTER_INIT=true \
./hack/local-backend-e2e.sh; \
kind delete cluster --name "$$kind_cluster_name"
.PHONY: test-e2e-nico-vms
test-e2e-nico-vms: ## Run NICo VMs happy-path e2e tests
make test-e2e ARGS='--label-filter="nico-vms && happy-path && (lifecycle || readiness) && !scale && !upgrade && !reboot"'
.PHONY: test-e2e-nico-vms-releases
test-e2e-nico-vms-releases: ## Run the opt-in NICo VMs release provisioning matrix
$(MAKE) test-e2e E2E_TIMEOUT=6h ARGS='--label-filter="nico-vms && releases"'
.PHONY: e2e-gofail
e2e-gofail: ## Execute gofail e2e tests against a local Temporal dev server.
@bash -euo pipefail -c '\
start=$$SECONDS; last=$$start; \
phase() { \
now=$$SECONDS; \
printf "[gofail] %-22s %4ds (total %4ds)\n" "$$1" "$$((now - last))" "$$((now - start))"; \
last=$$now; \
}; \
mkdir -p "$(TEMPORAL_CLI_DOWNLOAD_DIR)" "$$(dirname "$(gofail_e2e_worker_binary)")"; \
go install go.etcd.io/gofail@$(GOFAIL_VERSION); \
go install sigs.k8s.io/controller-runtime/tools/setup-envtest@$(SETUP_ENVTEST_VERSION); \
phase "install-tools"; \
KUBEBUILDER_ASSETS="$$("$(SETUP_ENVTEST)" use $(ENVTEST_K8S_VERSION) --bin-dir "$(ENVTEST_BIN_DIR)" -p path)"; \
export KUBEBUILDER_ASSETS; \
phase "envtest-assets"; \
"$(GOFAIL)" enable internal/temporal/activities; \
cleanup() { \
"$(GOFAIL)" disable internal/temporal/activities; \
}; \
trap cleanup EXIT; \
phase "gofail-enable"; \
go build -tags gofail -o "$(gofail_e2e_worker_binary)" ./cmd/worker; \
phase "build-worker"; \
TEMPORAL_CLI_DOWNLOAD_DIR="$(TEMPORAL_CLI_DOWNLOAD_DIR)" \
NVKE_CONTROLLER_GOFAIL_E2E_WORKER_BINARY="$(gofail_e2e_worker_binary)" \
NVKE_CONTROLLER_GOFAIL_E2E_CLUSTER_CRDS="$(gofail_e2e_cluster_crds)" \
NVKE_CONTROLLER_GOFAIL_E2E_CAPNICO_CRDS="$(gofail_e2e_capnico_crds)" \
go test -v -tags gofail ./e2e/gofail ./e2e/tracing -timeout 30m -count=1; \
phase "run-tests"; \
cleanup; \
trap - EXIT; \
test -z "$$(find . -name "*.fail.go" -print)" \
'
.PHONY: e2e-tracing
e2e-tracing: ## Execute the tracing e2e test against a local Temporal dev server and PostgreSQL (initdb and postgres on PATH, or set NVKE_CONTROLLER_GOFAIL_E2E_DB_CONNECTION_STRING).
mkdir -p "$(TEMPORAL_CLI_DOWNLOAD_DIR)"
TEMPORAL_CLI_DOWNLOAD_DIR="$(TEMPORAL_CLI_DOWNLOAD_DIR)" go test -v -tags gofail ./e2e/tracing -timeout 10m -count=1
LOCAL_PLATFORM ?= linux/amd64
.PHONY: docker-build-local
docker-build-local: ## Build the controller image for LOCAL_PLATFORM (default linux/amd64) and load it into the local daemon
@# The build context is the repository root: the controller is a member of
@# the root Go workspace, and the image build needs go.work and sibling
@# modules. Go downloads public dependencies into the builder cache.
@# One platform because --load does not support multi-platform images.
@# Use docker-build-multiarch to build both architectures.
DOCKER_BUILDKIT=1 docker build -f Dockerfile --platform $(LOCAL_PLATFORM) \
--progress=plain \
--tag $(IMG_NAME):$(GIT_VERSION) \
--tag $(IMG_NAME):$(BUILD_VERSION) \
--tag $(IMG) \
--build-arg BUILD_VERSION=${BUILD_VERSION} \
--build-arg GIT_VERSION=${GIT_VERSION} \
..
.PHONY: docker-build-multiarch
docker-build-multiarch: ## Build the controller image for linux/amd64 and linux/arm64 (requires --push or --output)
@# Builds both architectures but does not load them into the local daemon.
@# To push: add --push and set IMG. To export: add --output type=oci,dest=controller.tar.
docker buildx build -f Dockerfile \
--platform linux/amd64,linux/arm64 \
--progress=plain \
--tag $(IMG_NAME):$(GIT_VERSION) \
--tag $(IMG_NAME):$(BUILD_VERSION) \
--tag $(IMG) \
--build-arg BUILD_VERSION=${BUILD_VERSION} \
--build-arg GIT_VERSION=${GIT_VERSION} \
..
# Publish targets for pushing to an explicit registry (used by CI's
# image-nvcr.yml). These deliberately do NOT use IMG_NAME/IMG: this OSS repo
# must never default-push to the internal production image
# (nvcr.io/j7sbcjl3qgta/nvke-controller, IMG_NAME above). The destination
# has no default and must be passed explicitly via IMG_REPO, guarded by
# check-img-repo below, so a bare invocation cannot clobber it.
#
# Local usage (push to a scratch repo you own):
# docker login nvcr.io
# make docker-push-arch IMG_REPO=nvcr.io/<org>/<team>/scratch PUSH_TAGS=dev-me ARCH=amd64
IMG_REPO ?=
PUSH_TAGS ?=
ARCH ?= amd64
BUILDX_EXTRA_ARGS ?=
# Every stage after the push used to re-resolve a mutable tag: the manifest
# stitched <t>-amd64 and <t>-arm64, the SBOM re-pulled sha-<sha>-<arch>, and the
# promotion resolved the version tag again. Each could read a newer push than
# the one that run made. These files carry the digest forward instead. Under
# bin/, which is already gitignored.
DIGEST_FILE ?= $(CURDIR)/bin/image-digest-$(ARCH).txt
INDEX_DIGEST_FILE ?= $(CURDIR)/bin/image-digest-index.txt
# The per-arch sources docker-manifest stitches. Empty means the mutable
# per-arch tags, which is what a local run wants. CI passes the digests
# docker-push-arch recorded, so the index holds exactly what this run pushed.
ARCH_DIGESTS ?=
.PHONY: check-img-repo
check-img-repo:
@test -n "$(IMG_REPO)" || { echo "ERROR: IMG_REPO must be set explicitly"; exit 1; }
@test -n "$(PUSH_TAGS)" || { echo "ERROR: PUSH_TAGS must be set"; exit 1; }
.PHONY: docker-push-arch
docker-push-arch: check-img-repo ## Build+push one arch to IMG_REPO, tags <t>-$(ARCH)
@mkdir -p $(dir $(DIGEST_FILE))
@# --provenance=false: the default provenance turns a single-arch push into an
@# OCI index, which breaks docker-manifest's imagetools create and the NGC UI.
docker buildx build -f Dockerfile \
--platform linux/$(ARCH) --push --provenance=false --progress=plain \
$(foreach t,$(PUSH_TAGS),--tag $(IMG_REPO):$(t)-$(ARCH)) \
--build-arg BUILD_VERSION=${BUILD_VERSION} \
--build-arg GIT_VERSION=${GIT_VERSION} \
$(BUILDX_EXTRA_ARGS) \
--metadata-file $(DIGEST_FILE).json \
..
@# containerimage.digest is the manifest buildx just pushed. Read with sed
@# rather than jq, which the self-hosted runners do not all carry.
@sed -n 's/.*"containerimage\.digest": *"\([^"]*\)".*/\1/p' $(DIGEST_FILE).json > $(DIGEST_FILE)
@test -s $(DIGEST_FILE) || { echo "ERROR: no containerimage.digest in $(DIGEST_FILE).json"; exit 1; }
@echo "pushed $(IMG_REPO)@$$(cat $(DIGEST_FILE))"
.PHONY: docker-manifest
docker-manifest: check-img-repo ## Stitch <t>-amd64 + <t>-arm64 into <t> under IMG_REPO
@mkdir -p $(dir $(INDEX_DIGEST_FILE))
@set -e; for t in $(PUSH_TAGS); do \
if [ -n "$(ARCH_DIGESTS)" ]; then \
srcs=""; for d in $(ARCH_DIGESTS); do srcs="$$srcs $(IMG_REPO)@$$d"; done; \
else \
srcs="$(IMG_REPO):$$t-amd64 $(IMG_REPO):$$t-arm64"; \
fi; \
docker buildx imagetools create -t "$(IMG_REPO):$$t" $$srcs; \
done
@# One inspect, not one per stage: every tag above points at the same index,
@# and everything downstream reads this digest rather than a tag.
@docker buildx imagetools inspect "$(IMG_REPO):$(firstword $(PUSH_TAGS))" \
--format '{{.Manifest.Digest}}' > $(INDEX_DIGEST_FILE)
@echo "index $(IMG_REPO)@$$(cat $(INDEX_DIGEST_FILE))"
##@ Run
.PHONY: run
# Host-local runs read nvke-controller-config from this file unless
# CONTROLLER_CONFIG_PATH names another.
LOCAL_CONTROLLER_CONFIG ?= $(CURDIR)/hack/local-controller-config.yaml
run debug run-local: export CONTROLLER_CONFIG_PATH ?= $(LOCAL_CONTROLLER_CONFIG)
run: ## Runs the worker.
go run cmd/worker/main.go
.PHONY: debug
debug: ## Runs the worker with the delve debugger (attach on :12345).
dlv debug --headless --listen=:12345 ./cmd/worker/main.go
# Installed into ./bin rather than the shared GOBIN so a stale global binary
# cannot leak in — see the toolchain note below for why that matters.
GO_LICENSES ?= $(CURDIR)/bin/go-licenses
# go-licenses embeds golang.org/x/tools/go/packages and must be built with the
# SAME toolchain that `go list` runs inside this module. A module's `go`
# directive can make Go switch toolchains (GOTOOLCHAIN=auto), and on a mismatch
# go-licenses reports every stdlib package as "does not have module info" and
# produces nothing at all — a failure that reads like a broken generator rather
# than a stale binary. `go install pkg@version` deliberately ignores the current
# module, so the toolchain has to be pinned explicitly rather than inherited.
GO_TOOLCHAIN := $(shell go version | awk '{print $$3}')
$(GO_LICENSES):
@echo "Installing go-licenses $(GO_LICENSES_VERSION) (toolchain $(GO_TOOLCHAIN))..."
@GOTOOLCHAIN=$(GO_TOOLCHAIN) GOBIN=$(CURDIR)/bin \
go install github.com/google/go-licenses/v2@$(GO_LICENSES_VERSION)
# A named alias for the rule above, so another module can ask for the binary by
# name. GO_LICENSES is an absolute path, which means the real rule's target is
# also absolute and `make -C .. bin/go-licenses` does not match it -- it fails
# with "No rule to make target 'bin/go-licenses'". nvkectl's notices target hit
# exactly that, and it was masked in CI because the controller step runs first
# and leaves the binary behind.
.PHONY: go-licenses
go-licenses: $(GO_LICENSES) ## Build the pinned go-licenses into ./bin.
# Permissive licenses approved for redistribution. Matches the allowlist used by
# NVIDIA/aicr. A dependency introducing anything else - copyleft in particular -
# fails the check and needs a conscious decision rather than silent acceptance.
#
# This is a local pre-flight, not the gate of record. CI enforces dependency
# licenses in the security stage via the shared go-license-checks job
# (nke/gitlab-ci-cd, templates/security/go-license-checks.gitlab-ci.yml), which
# runs over ./... rather than just the shipped binary. The two differ in shape:
# CI denies by license *type* (restricted, reciprocal, forbidden, unknown) while
# this allows by license *name*, which is the stricter test on the packages it
# covers. Both pass on the current dependency set. Run this before pushing to
# catch a bad dependency without waiting for the pipeline.
ALLOWED_LICENSES ?= MIT,BSD-2-Clause,BSD-3-Clause,Apache-2.0,ISC,Zlib
.PHONY: license-policy-check
license-policy-check: $(GO_LICENSES) ## Verify every third-party dependency uses an approved license.
@echo "Checking dependency licenses against $(ALLOWED_LICENSES)..."
@# GOWORK=off and the quotes both matter. Under the workspace, `go list -m`
@# prints all eight member modules, so unquoted it word-splits into one
@# --ignore= plus seven stray positional arguments that go-licenses reads as
@# package patterns. GOWORK=off narrows it to this module, and the siblings
@# that genuinely need ignoring are named explicitly.
@GOOS=linux GOARCH=amd64 CGO_ENABLED=0 $(GO_LICENSES) check ./cmd/worker ../cluster-api-provider-provisioned/cmd/manager \
--allowed_licenses=$(ALLOWED_LICENSES) \
--ignore="$$(GOWORK=off go list -m),github.com/dsx-ai-factory/nvke/agent,github.com/dsx-ai-factory/nvke/auth,github.com/dsx-ai-factory/nvke/controller/k8s-apis,github.com/dsx-ai-factory/nvke/cluster-api-provider-provisioned,github.com/dsx-ai-factory/cluster-api-provider-nico"
.PHONY: notices
notices: $(GO_LICENSES) ## Regenerate THIRD_PARTY_NOTICES.md for the released worker and provider manager binaries.
@GO_LICENSES="$(GO_LICENSES)" ./hack/generate-notices
# Not declared as depending on `notices`: the tracked-file gate below is cheap
# and must run before spending minutes regenerating.
.PHONY: notices-check
notices-check: ## Verify THIRD_PARTY_NOTICES.md is up to date. (advisory; not in the merge gate)
@# git diff reports nothing for an untracked path, so without this an
@# uncommitted or accidentally-removed notices file would pass silently.
@git ls-files --error-unmatch THIRD_PARTY_NOTICES.md > /dev/null 2>&1 \
|| { echo "THIRD_PARTY_NOTICES.md is not tracked by git. Run 'make notices' and commit it."; exit 1; }
@$(MAKE) --no-print-directory notices
@if ! git diff --exit-code -- THIRD_PARTY_NOTICES.md > /dev/null 2>&1; then \
echo "THIRD_PARTY_NOTICES.md is out of date. Please run 'make notices' locally and commit the changes."; \
git diff --name-only -- THIRD_PARTY_NOTICES.md; \
exit 1; \
fi
##@ Credential monitoring
.PHONY: credential-alerts-check
credential-alerts-check: ## Validate credential rules, fixtures and chart render with the repository-pinned tools.
$(MAKE) -C .. credential-alerts-check