Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Kubebuilder go install-able #4079

Closed
AndersBennedsgaard opened this issue Aug 14, 2024 · 2 comments
Closed

Make Kubebuilder go install-able #4079

AndersBennedsgaard opened this issue Aug 14, 2024 · 2 comments
Labels
kind/feature Categorizes issue or PR as related to a new feature.

Comments

@AndersBennedsgaard
Copy link

What do you want to happen?

(I couldn't find any mentions about this, but feel free to close this if it is a duplicate)

I would like to add a target in my Makefile to install kubebuilder locally, such that all developers of our operator uses the same version of it.
https://book.kubebuilder.io/quick-start#installation doesn't explain how to install a specific version of Kubebuilder (you actually can't just change the version from latest in https://go.kubebuilder.io/dl/latest/$(go env GOOS)/$(go env GOARCH)) so I use the Github releases directly: curl -L -o $(KUBEBUILDER) "https://github.com/kubernetes-sigs/kubebuilder/releases/download/$(KUBEBUILDER_VERSION)/kubebuilder_$(GOOS)_$(GOARCH)"

This does work, but I would really prefer to just use go install since that is much simpler (doesn't require setting GOOS and GOARCH), I can make use of the go-install-tool helper, and it works even when you don't have curl and chmod installed such as on Windows.

By making Kubebuilder go install-able the installation steps for all distributions could be changed to use this, since it would be better (in my opinion) than the existing steps. It would also fix the installation steps for Windows in #2940

Extra Labels

No response

@AndersBennedsgaard AndersBennedsgaard added the kind/feature Categorizes issue or PR as related to a new feature. label Aug 14, 2024
@camilamacedo86
Copy link
Member

Hi @AndersBennedsgaard

Thank you for raise this one. See that you can create a Makefile to download the binary as follows:

# Variables
KUBEBUILDER_VERSION ?= v4.1.1.  # Change to the desired version
KUBEBUILDER_BIN = $(HOME)/bin/kubebuilder
GOOS = $(shell go env GOOS)
GOARCH = $(shell go env GOARCH)
KUBEBUILDER_URL = https://github.com/kubernetes-sigs/kubebuilder/releases/download/$(KUBEBUILDER_VERSION)/kubebuilder_$(GOOS)_$(GOARCH).tar.gz

# Targets
.PHONY: all install-kubebuilder

all: install-kubebuilder

install-kubebuilder:
	@echo "Installing Kubebuilder version $(KUBEBUILDER_VERSION)..."
	@mkdir -p $(HOME)/bin
	@curl -L -o kubebuilder.tar.gz $(KUBEBUILDER_URL)
	@tar -xzf kubebuilder.tar.gz -C $(HOME)/bin/
	@rm kubebuilder.tar.gz
	@echo "Kubebuilder installed at $(KUBEBUILDER_BIN)"
	@$(KUBEBUILDER_BIN)/kubebuilder version

It I would really prefer to just use go install since that is much simpler (doesn't require setting GOOS and GOARCH), I can make use of the go-install-tool helper, and it works even when you don't have curl and chmod installed such as on Windows.

We would need to check what are the changes required to do so.
But if you do not want to use curl you can also git clone the project and run make install from the root dir
That will install the project from the source., In this case the Makefile would be something like

# Variables
KUBEBUILDER_VERSION ?= v4.1.1 # Change to the desired version
KUBEBUILDER_REPO = https://github.com/kubernetes-sigs/kubebuilder.git
KUBEBUILDER_DIR = kubebuilder
KUBEBUILDER_BIN = $(HOME)/bin/kubebuilder

# Targets
.PHONY: all install-kubebuilder clean

all: install-kubebuilder

install-kubebuilder:
	@echo "Installing Kubebuilder version $(KUBEBUILDER_VERSION)..."
	@mkdir -p $(HOME)/bin
	@if [ -d "$(KUBEBUILDER_DIR)" ]; then \
		cd $(KUBEBUILDER_DIR) && git fetch --tags && git checkout $(KUBEBUILDER_VERSION); \
	else \
		git clone $(KUBEBUILDER_REPO) $(KUBEBUILDER_DIR) && cd $(KUBEBUILDER_DIR) && git checkout $(KUBEBUILDER_VERSION); \
	fi
	@cd $(KUBEBUILDER_DIR) && make install
	@echo "Kubebuilder installed at $(KUBEBUILDER_BIN)"
	@$(KUBEBUILDER_BIN) version

However, we need to share that Windows is not an officially supported env.
You might able to use Kuebuilder using tools like Windows Subsystem for Linux (WSL). However, I do not know if all will work well. You might either want to just have a container and work on it.
See the PR: #4078

By last, if you want to push a PR with the required changes to allow go install we can review it and see if we can or not accepted the change.

@camilamacedo86
Copy link
Member

I am closing this one.

But if anyone have interest to propose a solution to attend this request please feel free to push a PR or a design doc(if that br too big). I am not sure as described above if it would be achievable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Categorizes issue or PR as related to a new feature.
Projects
None yet
Development

No branches or pull requests

2 participants