Fix macOS compatibility for operator-sdk binary download#99
Open
shreyabiradar07 wants to merge 2 commits into
Open
Fix macOS compatibility for operator-sdk binary download#99shreyabiradar07 wants to merge 2 commits into
shreyabiradar07 wants to merge 2 commits into
Conversation
Signed-off-by: Shreya Biradar <shbirada@ibm.com>
Reviewer's guide (collapsed on small PRs)Reviewer's GuideThis PR refactors the Makefile’s operator-sdk handling to use deterministic, host-specific binary downloads by introducing HOST_OS/HOST_ARCH detection, defining a platform-qualified local operator-sdk path, and converting the operator-sdk rule into a proper file target that always downloads the correct binary for the current machine without falling back to system-wide installations. Flow diagram for deterministic operator-sdk download per host platformflowchart LR
A[make operator-sdk] --> B[Evaluate HOST_OS and HOST_ARCH]
B --> C[Set OPERATOR_SDK = LOCALBIN/operator-sdk-<version>-<HOST_OS>-<HOST_ARCH>]
C --> D{File OPERATOR_SDK exists?}
D -- No --> E[Download operator-sdk_<HOST_OS>_<HOST_ARCH> via curl]
E --> F[chmod +x OPERATOR_SDK]
F --> G[operator-sdk ready at local path]
D -- Yes --> G
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 2 issues, and left some high level feedback:
- The new
$(OPERATOR_SDK): $(LOCALBIN)rule assumes$(LOCALBIN)already has a rule to create the directory; if not, you should add one (e.g.,$(LOCALBIN):; mkdir -p $@) since you removed the inlinemkdir -pfrom the previous implementation. - The HOST_ARCH mapping logic repeats the
arm64case; you can simplify by collapsing theaarch64andarm64branches into a single conditional (or a small case statement) to avoid duplication.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new `$(OPERATOR_SDK): $(LOCALBIN)` rule assumes `$(LOCALBIN)` already has a rule to create the directory; if not, you should add one (e.g., `$(LOCALBIN):; mkdir -p $@`) since you removed the inline `mkdir -p` from the previous implementation.
- The HOST_ARCH mapping logic repeats the `arm64` case; you can simplify by collapsing the `aarch64` and `arm64` branches into a single conditional (or a small case statement) to avoid duplication.
## Individual Comments
### Comment 1
<location path="Makefile" line_range="307-310" />
<code_context>
+
+$(OPERATOR_SDK): $(LOCALBIN)
+ @echo "Downloading operator-sdk $(OPERATOR_SDK_VERSION) for $(HOST_OS)/$(HOST_ARCH)..."
+ @curl -sSLo $(OPERATOR_SDK) https://github.com/operator-framework/operator-sdk/releases/download/$(OPERATOR_SDK_VERSION)/operator-sdk_$(HOST_OS)_$(HOST_ARCH) ;\
chmod +x $(OPERATOR_SDK) ;\
echo "operator-sdk downloaded to $(OPERATOR_SDK)" ;\
else \
</code_context>
<issue_to_address>
**issue (bug_risk):** The recipe still contains `else` (and the tail of the old `if`) without a matching `if`, which will break the shell command.
Since the `$(OPERATOR_SDK)` rule no longer uses a shell `if`, the leftover `chmod`, `echo`, and `else \` lines now form an invalid shell script: `curl` runs, then `chmod`, then `echo`, and finally a bare `else` with no matching `if`, causing a syntax error.
Please either remove the dangling `else`-related lines, or restore a complete `if`/`fi` block around the download if conditional behavior is still required, otherwise `make operator-sdk` will fail.
</issue_to_address>
### Comment 2
<location path="Makefile" line_range="260" />
<code_context>
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen-$(CONTROLLER_TOOLS_VERSION)
ENVTEST ?= $(LOCALBIN)/setup-envtest-$(ENVTEST_VERSION)
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint-$(GOLANGCI_LINT_VERSION)
+OPERATOR_SDK ?= $(LOCALBIN)/operator-sdk-$(OPERATOR_SDK_VERSION)-$(HOST_OS)-$(HOST_ARCH)
## Tool Versions
</code_context>
<issue_to_address>
**suggestion (bug_risk):** The new `operator-sdk` target always treats `OPERATOR_SDK` as a downloadable file, which may override a user-provided system path.
With the pattern rule `operator-sdk: $(OPERATOR_SDK)` and `$(OPERATOR_SDK): $(LOCALBIN)`, `make operator-sdk` will always create or update the `OPERATOR_SDK` path, even when it points to an existing system-wide binary. If you want to keep supporting a preinstalled `operator-sdk`, you could only define the `$(OPERATOR_SDK)` rule when it’s under `$(LOCALBIN)` (or behind a flag). Otherwise, it’d help to document that `OPERATOR_SDK` is now expected to be a managed file under `LOCALBIN`, not an arbitrary path.
Suggested implementation:
```
GOBIN=$(shell go env GOPATH)/bin
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen-$(CONTROLLER_TOOLS_VERSION)
ENVTEST ?= $(LOCALBIN)/setup-envtest-$(ENVTEST_VERSION)
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint-$(GOLANGCI_LINT_VERSION)
# OPERATOR_SDK is managed under $(LOCALBIN) and may be (re)downloaded by `make operator-sdk`.
# Overriding OPERATOR_SDK to a system-wide path can result in that path being overwritten.
OPERATOR_SDK ?= $(LOCALBIN)/operator-sdk-$(OPERATOR_SDK_VERSION)-$(HOST_OS)-$(HOST_ARCH)
## Tool Versions
KUSTOMIZE_VERSION ?= v5.3.0
```
If you want to also support a preinstalled `operator-sdk` without risk of overwriting it, you can:
1. Wrap the `$(OPERATOR_SDK): $(LOCALBIN)` download rule in a conditional that only applies when `$(OPERATOR_SDK)` starts with `$(LOCALBIN)`.
2. Alternatively, add a feature flag (e.g. `MANAGE_OPERATOR_SDK ?= 1`) and guard the download rule with `ifeq ($(MANAGE_OPERATOR_SDK),1)`.
These changes would go where the `operator-sdk` target and its dependency rule are defined elsewhere in the Makefile.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
…ations Signed-off-by: Shreya Biradar <shbirada@ibm.com>
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.
This PR has following Makefile changes for macOS/Linux compatibility:
Summary by Sourcery
Ensure deterministic, platform-specific downloading of the operator-sdk binary based on the host OS and architecture.
New Features:
Bug Fixes:
Enhancements: