Skip to content

Makefile: tidy kind, operator-sdk, and opm fetch rules#529

Merged
frobware merged 3 commits into
bpfman:mainfrom
frobware:makefile-kind-phony-cleanup
May 19, 2026
Merged

Makefile: tidy kind, operator-sdk, and opm fetch rules#529
frobware merged 3 commits into
bpfman:mainfrom
frobware:makefile-kind-phony-cleanup

Conversation

@frobware
Copy link
Copy Markdown
Contributor

@frobware frobware commented May 18, 2026

While working on #528 I noticed three things in the Makefile's tool-fetching rules that compounded each other. LOCALBIN ?= $(shell pwd)/bin made $(KIND) and $(OPERATOR_SDK) reachable only by absolute path -- make bin/kind failed with "no rule for target", and the .PHONY: kind / .PHONY: operator-sdk aliases existed only to give those targets a typeable name. Regular prerequisites on $(LOCALBIN) meant Make considered the binaries stale whenever the directory's mtime moved; the test -s guards inside the recipes were the only thing stopping an actual redownload. And curl -Lo without -f writes HTTP error bodies straight to the output path, so a 404 leaves a non-empty file the next run treats as already installed.

First commit switches LOCALBIN to a relative path, drops the .PHONY aliases (their job is now done by typing the file target directly), and updates the dependents (load-images-kind, setup-kind, setup-kind-registry, destroy-kind, bundle, bundle-deploy, bundle-deploy-openshift, bundle-undeploy) to depend on $(KIND) / $(OPERATOR_SDK) instead of the dropped aliases. The one consumer that still needs an absolute path is setup-envtest --bin-dir, because its output becomes KUBEBUILDER_ASSETS for per-package test binaries whose cwd changes; that single call site is wrapped with $(abspath $(LOCALBIN)).

Second commit switches both download rules to an order-only prerequisite on $(LOCALBIN) (so directory mtime no longer triggers rebuilds) and reshapes the recipes around curl -fLo $@.tmp followed by mv $@.tmp $@. The -f makes curl exit non-zero on HTTP errors, the rename keeps the canonical $@ path absent until the full chain succeeds, and the test -s guards become redundant.

Third commit applies the same pattern to the opm rule, which was the most tangled of the three: a .PHONY: opm target whose recipe body was wrapped in nested ifeq blocks, plus a mid-rule reassignment where OPM = ./bin/opm was overwritten inside the else branch with OPM = $(shell which opm) -- so $(OPM) silently became whatever version happened to be in $PATH if the local download was missing, pinning v1.45.0 in the URL while accepting whatever opm the user had installed. The rule now matches $(KIND) and $(OPERATOR_SDK) exactly: an $(OPM) file target with order-only $(LOCALBIN) prereq, atomic download, and OPM_VERSION lifted to the Tool Versions block alongside KIND_VERSION and OPERATOR_SDK_VERSION. catalog-build depends on $(OPM) directly. The system-opm fallback is dropped: override OPM on the command line if you want to point at something specific.

Test plan

  • make help no longer lists the bare kind, operator-sdk, or opm aliases
  • make bin/kind, make bin/operator-sdk, make bin/opm trigger their download recipes
  • make test runs with KUBEBUILDER_ASSETS resolved as an absolute path
  • make setup-kind, make bundle-deploy, make catalog-build etc. fire their tool prereqs

frobware added 3 commits May 18, 2026 16:52
LOCALBIN was set to $(shell pwd)/bin, which made the file targets
$(LOCALBIN)/kind and $(LOCALBIN)/operator-sdk addressable only by
absolute path. The two .PHONY aliases (kind: $(KIND) and
operator-sdk: $(OPERATOR_SDK)) existed solely so users could type
'make kind' instead of 'make /full/path/to/bin/kind'.

Switch LOCALBIN to 'bin'. The tools' file targets are now bin/kind
and bin/operator-sdk, typeable on the command line as plain relative
paths. Drop the phony aliases and switch their dependents
(load-images-kind, setup-kind, setup-kind-registry, destroy-kind,
bundle, bundle-deploy, bundle-deploy-openshift, bundle-undeploy) to
depend on the file targets via the $(KIND) and $(OPERATOR_SDK)
variables.

The one consumer that requires an absolute path is the setup-envtest
call in the test recipe: KUBEBUILDER_ASSETS is read by per-package
test binaries whose cwd changes per Go subpackage, so a relative
asset path would not resolve. Wrap that single call site with
$(abspath $(LOCALBIN)).

Signed-off-by: Andrew McDermott <amcdermo@redhat.com>
The kind and operator-sdk file rules depended on $(LOCALBIN) as a
regular prerequisite, so any change to bin/'s mtime (adding another
tool, extracting an archive) made Make consider the binaries stale and
re-fire their download recipes. The test -s guard inside each recipe
was the only thing preventing an actual redownload.

Switch both rules to an order-only prerequisite (| $(LOCALBIN)): Make
ensures bin/ exists before running the recipe but ignores its mtime,
so the recipe only fires when the binary file itself is missing. The
test -s guard is no longer needed.

While simplifying the recipes, harden the downloads. curl -Lo
(without -f): silently saves an HTTP error body to the output path, so
a 404 or server error produces a non-empty file that future runs treat
as already-installed; the binary fails later with an obscure parse
error. Switch to curl -fLo (-f exits non-zero on HTTP errors) and
download to $@.tmp followed by an mv-rename, so the canonical $@ path
is never present unless the full sequence succeeded.

Use $@ throughout the recipes to avoid repeating $(KIND) /
$(OPERATOR_SDK) and to keep the two rules structurally identical.

Signed-off-by: Andrew McDermott <amcdermo@redhat.com>
The opm rule was a tangle of parse-time conditionals: a .PHONY
target whose recipe was wrapped in nested ifeq blocks, plus a
mid-rule reassignment of OPM where 'OPM = ./bin/opm' was
overwritten inside the else branch with 'OPM = $(shell which opm)'.
The result was that $(OPM) silently became whatever version
happened to be in $PATH if the local download was missing --
pinning v1.45.0 in the URL while accepting whatever opm the user
had installed.

Rework the rule to match the kind and operator-sdk pattern: an
$(OPM) file target depending on $(LOCALBIN) order-only, downloading
to $@.tmp and renaming on success, with OPM_VERSION lifted to the
Tool Versions block alongside KIND_VERSION and OPERATOR_SDK_VERSION.
The .PHONY: opm alias goes away and catalog-build depends on $(OPM)
directly.

The system-opm fallback is dropped: override OPM on the command
line if you want to point at something specific (e.g.
'make OPM=/usr/local/bin/opm catalog-build'). The pinned version
now actually controls what gets used.

Signed-off-by: Andrew McDermott <amcdermo@redhat.com>
@frobware frobware changed the title Makefile: tidy kind and operator-sdk fetch rules Makefile: tidy kind, operator-sdk, and opm fetch rules May 18, 2026
@frobware
Copy link
Copy Markdown
Contributor Author

cc @alebedev87

@frobware frobware merged commit c9a3f5b into bpfman:main May 19, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants