Makefile: tidy kind, operator-sdk, and opm fetch rules#529
Merged
Conversation
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>
Contributor
Author
|
cc @alebedev87 |
alebedev87
approved these changes
May 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
While working on #528 I noticed three things in the Makefile's tool-fetching rules that compounded each other.
LOCALBIN ?= $(shell pwd)/binmade$(KIND)and$(OPERATOR_SDK)reachable only by absolute path --make bin/kindfailed with "no rule for target", and the.PHONY: kind/.PHONY: operator-sdkaliases 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; thetest -sguards inside the recipes were the only thing stopping an actual redownload. Andcurl -Lowithout-fwrites 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
LOCALBINto a relative path, drops the.PHONYaliases (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 issetup-envtest --bin-dir, because its output becomesKUBEBUILDER_ASSETSfor 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 aroundcurl -fLo $@.tmpfollowed bymv $@.tmp $@. The-fmakes curl exit non-zero on HTTP errors, the rename keeps the canonical$@path absent until the full chain succeeds, and thetest -sguards become redundant.Third commit applies the same pattern to the
opmrule, which was the most tangled of the three: a.PHONY: opmtarget whose recipe body was wrapped in nestedifeqblocks, plus a mid-rule reassignment whereOPM = ./bin/opmwas overwritten inside the else branch withOPM = $(shell which opm)-- so$(OPM)silently became whatever version happened to be in$PATHif the local download was missing, pinningv1.45.0in 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, andOPM_VERSIONlifted to the Tool Versions block alongsideKIND_VERSIONandOPERATOR_SDK_VERSION.catalog-builddepends on$(OPM)directly. The system-opm fallback is dropped: overrideOPMon the command line if you want to point at something specific.Test plan
make helpno longer lists the barekind,operator-sdk, oropmaliasesmake bin/kind,make bin/operator-sdk,make bin/opmtrigger their download recipesmake testruns withKUBEBUILDER_ASSETSresolved as an absolute pathmake setup-kind,make bundle-deploy,make catalog-buildetc. fire their tool prereqs