Skip to content

Fix macOS compatibility for operator-sdk binary download#99

Open
shreyabiradar07 wants to merge 2 commits into
kruize:mvp_demofrom
shreyabiradar07:fix_binary
Open

Fix macOS compatibility for operator-sdk binary download#99
shreyabiradar07 wants to merge 2 commits into
kruize:mvp_demofrom
shreyabiradar07:fix_binary

Conversation

@shreyabiradar07
Copy link
Copy Markdown
Contributor

@shreyabiradar07 shreyabiradar07 commented May 20, 2026

This PR has following Makefile changes for macOS/Linux compatibility:

  • Added host OS/arch detection for platform-specific downloads
  • Added a local operator-sdk target using $(HOST_OS)
  • Removed the conflicting system-wide fallback logic so the download path is deterministic

Summary by Sourcery

Ensure deterministic, platform-specific downloading of the operator-sdk binary based on the host OS and architecture.

New Features:

  • Detect host OS and architecture in the Makefile for platform-aware tooling configuration.

Bug Fixes:

  • Fix operator-sdk download behavior on macOS and other platforms by removing reliance on system-wide binaries and ad-hoc architecture mapping logic.

Enhancements:

  • Standardize the operator-sdk local binary path to include version, OS, and architecture, and wire it into the existing LOCALBIN tooling pattern.

Signed-off-by: Shreya Biradar <shbirada@ibm.com>
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 20, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This 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 platform

flowchart 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
Loading

File-Level Changes

Change Details Files
Introduce host OS and architecture detection to drive platform-specific downloads.
  • Add HOST_OS based on uname -s lowercased.
  • Add HOST_ARCH_RAW from uname -m and normalize common values (x86_64 → amd64, aarch64/arm64 → arm64).
  • Provide a generic fallback assigning HOST_ARCH to HOST_ARCH_RAW for unhandled architectures.
Makefile
Define a deterministic, platform-qualified local operator-sdk binary path and remove system-wide fallback resolution.
  • Set OPERATOR_SDK to $(LOCALBIN)/operator-sdk-$(OPERATOR_SDK_VERSION)-$(HOST_OS)-$(HOST_ARCH) so each platform/version gets its own binary.
  • Remove the which-based logic that preferred a system-wide operator-sdk over the local one, avoiding ambiguity about which binary is used.
Makefile
Refactor the operator-sdk Makefile target into a file-based rule that downloads the correct binary for the detected host platform.
  • Change the operator-sdk phony target to depend on $(OPERATOR_SDK), turning the download into a file target.
  • Add a rule for $(OPERATOR_SDK) that depends on $(LOCALBIN), echoes the platform being used, downloads the operator-sdk binary for HOST_OS/HOST_ARCH from GitHub, and marks it executable.
  • Remove the previous inline OS/ARCH detection and case-switch in the target body in favor of the centralized HOST_OS/HOST_ARCH variables.
Makefile

Possibly linked issues

  • #0: PR implements OS/arch-aware operator-sdk download in Makefile, directly addressing macOS incompatibility described in the issue.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 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.
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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread Makefile Outdated
Comment thread Makefile
…ations

Signed-off-by: Shreya Biradar <shbirada@ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant