Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
198 changes: 120 additions & 78 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,31 +1,65 @@
# OPENSHIFT_GIMPORTS_VER defines which version of openshift-goimports to use
# for checking import statements.
OPENSHIFT_GOIMPORTS_VER := c72f1dc2e3aacfa00aece3391d938c9bc734e791
RECONCILER_GEN_VER := v0.5.0
## Tool Versions
# Copyright 2025 The KCP Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Setting SHELL to bash allows bash commands to be executed by recipes.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec

export CGO_ENABLED ?= 0
export GOFLAGS ?= -mod=readonly -trimpath
export GO111MODULE = on
GOBUILDFLAGS ?= -v
LDFLAGS += -extldflags '-static'
LDFLAGS_EXTRA ?= -w

ifdef DEBUG_BUILD
GOFLAGS = -mod=readonly
LDFLAGS_EXTRA =
GOTOOLFLAGS_EXTRA = -gcflags=all="-N -l"
endif

BUILD_DEST ?= _build
GOTOOLFLAGS ?= $(GOBUILDFLAGS) -ldflags '$(LDFLAGS) $(LDFLAGS_EXTRA)' $(GOTOOLFLAGS_EXTRA)

# Image URL to use all building/pushing image targets
IMG ?= ghcr.io/kcp-dev/kcp-operator

GOIMPORTS_VERSION ?= c72f1dc2e3aacfa00aece3391d938c9bc734e791
GOLANGCI_LINT_VERSION ?= 2.1.6
HELM_VERSION ?= 3.18.6
KUBECTL_VERSION ?= v1.32.0
KUSTOMIZE_VERSION ?= v5.4.3
CONTROLLER_TOOLS_VERSION ?= v0.16.1
GOLANGCI_LINT_VERSION ?= 2.1.6
PROTOKOL_VERSION ?= 0.7.2
HELM_VERSION ?= 3.18.6

# Image URL to use all building/pushing image targets
IMG ?= ghcr.io/kcp-dev/kcp-operator
# codegen tooling
APPLYCONFIGURATION_GEN_VERSION ?= v0.32.0
CLIENT_GEN_VERSION ?= v0.32.0
CONTROLLER_GEN_VERSION ?= v0.16.1
KCP_CODEGEN_VERSION ?= v2.3.1
RECONCILER_GEN_VERSION ?= v0.5.0

TOOLS_DIR = $(shell pwd)/_tools
export UGET_DIRECTORY ?= _tools
export UGET_CHECKSUMS ?= hack/tools.checksums
export UGET_VERSIONED_BINARIES = true

# CONTAINER_TOOL defines the container tool to be used for building images.
# Be aware that the target commands are only tested with Docker which is
# scaffolded by default. However, you might want to replace it to use other
# tools. (i.e. podman)
CONTAINER_TOOL ?= docker

# Setting SHELL to bash allows bash commands to be executed by recipes.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec

.PHONY: all
all: build

Expand All @@ -49,7 +83,7 @@ help: ## Display this help.
##@ Development

.PHONY: codegen
codegen: reconciler-gen openshift-goimports ## Generate manifest, code and the SDK.
codegen: ## Generate manifest, code and the SDK.
@hack/update-codegen.sh

.PHONY: fmt
Expand All @@ -62,35 +96,39 @@ vet: ## Run go vet against code.

.PHONY: test
test: fmt vet ## Run tests.
go test $$(go list ./... | grep -v /e2e) -coverprofile cover.out
go test ./... -coverprofile cover.out

# Utilize Kind or modify the e2e tests to load the image locally, enabling compatibility with other vendors.
.PHONY: test-e2e # Run the e2e tests against a kind k8s instance that is already spun up.
test-e2e:
go test ./test/e2e/ -v
go test -v -tags e2e ./test/e2e/...

# Creates a kind cluster and runs the e2e tests in them. The kind cluster is destroyed after the tests.
.PHONY: test-e2e-with-kind # Run the e2e tests against a temporary kind cluster.
test-e2e-with-kind: helm
@./hack/run-e2e-tests.sh
test-e2e-with-kind:
@hack/run-e2e-tests.sh

GOLANGCI_LINT = $(UGET_DIRECTORY)/golangci-lint-$(GOLANGCI_LINT_VERSION)

.PHONY: lint
lint: golangci-lint ## Run golangci-lint linter.
lint: install-golangci-lint ## Run golangci-lint linter.
$(GOLANGCI_LINT) run --timeout 10m
cd sdk && $(GOLANGCI_LINT) --config ../.golangci.yml run --timeout 10m
cd sdk && ../$(GOLANGCI_LINT) --config ../.golangci.yml run --timeout 10m

.PHONY: lint-fix
lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes.
lint-fix: install-golangci-lint ## Run golangci-lint linter and perform fixes.
$(GOLANGCI_LINT) run --timeout 10m --fix
cd sdk && $(GOLANGCI_LINT) --config ../.golangci.yml run --timeout 10m --fix
cd sdk && ../$(GOLANGCI_LINT) --config ../.golangci.yml run --timeout 10m --fix

.PHONY: modules
modules: ## Run go mod tidy to ensure modules are up to date.
hack/update-go-modules.sh

GOIMPORTS = $(UGET_DIRECTORY)/goimports-$(GOIMPORTS_VERSION)

.PHONY: imports
imports: openshift-goimports ## Re-order Go import statements.
$(OPENSHIFT_GOIMPORTS) -m github.com/kcp-dev/kcp-operator
imports: install-goimports ## Re-order Go import statements.
$(GOIMPORTS) -m github.com/kcp-dev/kcp-operator

.PHONY: verify
verify: codegen fmt vet modules imports ## Run all codegen and formatting targets and check if files have changed.
Expand All @@ -100,11 +138,15 @@ verify: codegen fmt vet modules imports ## Run all codegen and formatting target

.PHONY: clean
clean: ## Remove all built binaries.
rm -rf _build
rm -rf $(BUILD_DEST)

.PHONY: clean-tools
clean-tools: ## Remove all downloaded tools.
rm -rf $(UGET_DIRECTORY)

.PHONY: build
build: ## Build manager binary.
go build -o _build/manager cmd/main.go
go build $(GOTOOLFLAGS) -o $(BUILD_DEST)/manager cmd/main.go

.PHONY: run
run: fmt vet ## Run a controller from your host.
Expand All @@ -121,8 +163,11 @@ docker-build: ## Build docker image with the manager.
docker-push: ## Push docker image with the manager.
$(CONTAINER_TOOL) push ${IMG}

KUSTOMIZE = $(abspath .)/$(UGET_DIRECTORY)/kustommize-$(KUSTOMIZE_VERSION)
KUBECTL = $(abspath .)/$(UGET_DIRECTORY)/kubectl-$(KUBECTL_VERSION)

.PHONY: build-installer
build-installer: manifests generate kustomize ## Generate a consolidated YAML with CRDs and deployment.
build-installer: manifests generate install-kustomize ## Generate a consolidated YAML with CRDs and deployment.
mkdir -p dist
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/default > dist/install.yaml
Expand All @@ -134,81 +179,78 @@ ifndef ignore-not-found
endif

.PHONY: install
install: kubectl kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
install: kubectl install-kustomize install-kubectl ## Install CRDs into the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | $(KUBECTL) apply -f -

.PHONY: uninstall
uninstall: kubectl kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
uninstall: kubectl install-kustomize install-kubectl ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
$(KUSTOMIZE) build config/crd | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -

.PHONY: deploy
deploy: kubectl kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
deploy: kubectl install-kustomize install-kubectl ## Deploy controller to the K8s cluster specified in ~/.kube/config.
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/default | $(KUBECTL) apply -f -

.PHONY: undeploy
undeploy: kubectl kustomize ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
undeploy: kubectl install-kustomize install-kubectl ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
$(KUSTOMIZE) build config/default | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -

##@ Dependencies

## Tool Binaries
KUBECTL ?= $(TOOLS_DIR)/kubectl
KUSTOMIZE ?= $(TOOLS_DIR)/kustomize
GOLANGCI_LINT = $(TOOLS_DIR)/golangci-lint
PROTOKOL = $(TOOLS_DIR)/protokol
RECONCILER_GEN := $(TOOLS_DIR)/reconciler-gen
OPENSHIFT_GOIMPORTS := $(TOOLS_DIR)/openshift-goimports
HELM := $(TOOLS_DIR)/helm

.PHONY: kubectl
kubectl: $(KUBECTL) ## Download kubectl locally if necessary.
.PHONY: install-kubectl
install-kubectl: ## Download kubectl locally if necessary.
@UNCOMPRESSED=true hack/uget.sh https://dl.k8s.io/release/{VERSION}/bin/{GOOS}/{GOARCH}/kubectl kubectl $(KUBECTL_VERSION) kubectl

.PHONY: $(KUBECTL)
$(KUBECTL):
@UNCOMPRESSED=true hack/download-tool.sh https://dl.k8s.io/$(KUBECTL_VERSION)/bin/$(shell go env GOOS)/$(shell go env GOARCH)/kubectl kubectl $(KUBECTL_VERSION) kubectl
.PHONY: install-kustomize
install-kustomize: ## Download kustomize locally if necessary.
@GO_MODULE=true hack/uget.sh sigs.k8s.io/kustomize/kustomize/v5 kustomize $(KUSTOMIZE_VERSION)

.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
.PHONY: install-golangci-lint
install-golangci-lint: ## Download golangci-lint locally if necessary.
@hack/uget.sh https://github.com/golangci/golangci-lint/releases/download/v{VERSION}/golangci-lint-{VERSION}-{GOOS}-{GOARCH}.tar.gz golangci-lint $(GOLANGCI_LINT_VERSION)

.PHONY: $(KUSTOMIZE)
$(KUSTOMIZE):
@GO_MODULE=true hack/download-tool.sh sigs.k8s.io/kustomize/kustomize/v5 kustomize $(KUSTOMIZE_VERSION)
.PHONY: install-protokol
install-protokol: ## Download protokol locally if necessary.
@hack/uget.sh https://codeberg.org/xrstf/protokol/releases/download/v{VERSION}/protokol_{VERSION}_{GOOS}_{GOARCH}.tar.gz protokol $(PROTOKOL_VERSION)

.PHONY: golangci-lint
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
.PHONY: install-reconciler-gen
install-reconciler-gen: ## Download reconciler-gen locally if necessary.
@GO_MODULE=true hack/uget.sh k8c.io/reconciler/cmd/reconciler-gen reconciler-gen $(RECONCILER_GEN_VERSION)

.PHONY: $(GOLANGCI_LINT)
$(GOLANGCI_LINT):
@hack/download-tool.sh https://github.com/golangci/golangci-lint/releases/download/v${GOLANGCI_LINT_VERSION}/golangci-lint-${GOLANGCI_LINT_VERSION}-$(shell go env GOOS)-$(shell go env GOARCH).tar.gz golangci-lint $(GOLANGCI_LINT_VERSION)
.PHONY: install-applyconfiguration-gen
install-applyconfiguration-gen: ## Download applyconfiguration-gen locally if necessary.
@GO_MODULE=true hack/uget.sh k8s.io/code-generator/cmd/applyconfiguration-gen applyconfiguration-gen $(APPLYCONFIGURATION_GEN_VERSION)

.PHONY: protokol
protokol: $(PROTOKOL) ## Download protokol locally if necessary.
.PHONY: install-client-gen
install-client-gen: ## Download client-gen locally if necessary.
@GO_MODULE=true hack/uget.sh k8s.io/code-generator/cmd/client-gen client-gen $(CLIENT_GEN_VERSION)

.PHONY: $(PROTOKOL)
$(PROTOKOL):
@hack/download-tool.sh https://codeberg.org/xrstf/protokol/releases/download/v${PROTOKOL_VERSION}/protokol_${PROTOKOL_VERSION}_$(shell go env GOOS)_$(shell go env GOARCH).tar.gz protokol $(PROTOKOL_VERSION)
# make controller-gen and kcp-codegen compile on Go 1.25;
# this can be removed once they have been updated to more recent versions.
export GO_EXTRA_DEPS=golang.org/x/tools@v0.39.0

.PHONY: reconciler-gen
reconciler-gen: $(RECONCILER_GEN) ## Download reconciler-gen locally if necessary.
.PHONY: install-controller-gen
install-controller-gen: ## Download controller-gen locally if necessary.
@GO_MODULE=true hack/uget.sh sigs.k8s.io/controller-tools/cmd/controller-gen controller-gen $(CONTROLLER_GEN_VERSION)

.PHONY: $(RECONCILER_GEN)
$(RECONCILER_GEN):
@GO_MODULE=true hack/download-tool.sh k8c.io/reconciler/cmd/reconciler-gen reconciler-gen $(RECONCILER_GEN_VER)
.PHONY: install-kcp-codegen
install-kcp-codegen: ## Download kcp code-generator locally if necessary.
@GO_MODULE=true hack/uget.sh github.com/kcp-dev/code-generator/v2 kcp-code-generator $(KCP_CODEGEN_VERSION) code-generator

.PHONY: openshift-goimports
openshift-goimports: $(OPENSHIFT_GOIMPORTS) ## Download openshift-goimports locally if necessary.
.PHONY: install-goimports
install-goimports: ## Download openshift goimports locally if necessary.
@GO_MODULE=true hack/uget.sh github.com/openshift-eng/openshift-goimports goimports $(GOIMPORTS_VERSION)

.PHONY: $(OPENSHIFT_GOIMPORTS)
$(OPENSHIFT_GOIMPORTS):
@GO_MODULE=true hack/download-tool.sh github.com/openshift-eng/openshift-goimports openshift-goimports $(OPENSHIFT_GOIMPORTS_VER)
.PHONY: install-helm
install-helm: ## Download Helm locally if necessary.
@hack/uget.sh https://get.helm.sh/helm-v{VERSION}-{GOOS}-{GOARCH}.tar.gz helm $(HELM_VERSION)

.PHONY: helm
helm: $(HELM) ## Download Helm locally if necessary.
# This target can be used to conveniently update the checksums for all checksummed tools.
# Combine with GOARCH to update for other archs, like "GOARCH=arm64 make update-tools".

.PHONY: $(HELM)
$(HELM):
@hack/download-tool.sh https://get.helm.sh/helm-v${HELM_VERSION}-$(shell go env GOOS)-$(shell go env GOARCH).tar.gz helm $(HELM_VERSION)
.PHONY: update-tools
update-tools: UGET_UPDATE=true
update-tools: clean-tools install-kubectl install-golangci-lint install-protokol install-helm

##@ Documentation

Expand Down
11 changes: 0 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ require (
github.com/go-logr/logr v1.4.2
github.com/go-logr/zapr v1.3.0
github.com/go-test/deep v1.1.0
github.com/kcp-dev/code-generator/v2 v2.3.1
github.com/kcp-dev/kcp-operator/sdk v0.0.0-00010101000000-000000000000
github.com/kcp-dev/kcp/sdk v0.27.1
github.com/kcp-dev/logicalcluster/v3 v3.0.5
Expand All @@ -19,10 +18,8 @@ require (
k8s.io/api v0.32.0
k8s.io/apimachinery v0.32.0
k8s.io/client-go v0.32.0
k8s.io/code-generator v0.32.0
k8s.io/utils v0.0.0-20241210054802-24370beab758
sigs.k8s.io/controller-runtime v0.19.0
sigs.k8s.io/controller-tools v0.16.1
sigs.k8s.io/yaml v1.4.0
)

Expand All @@ -38,15 +35,13 @@ require (
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/emicklei/go-restful/v3 v3.12.1 // indirect
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
github.com/fatih/color v1.17.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.8.0 // indirect
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/gobuffalo/flect v1.0.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/cel-go v0.22.1 // indirect
Expand All @@ -60,8 +55,6 @@ require (
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.11 // indirect
github.com/mailru/easyjson v0.9.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
Expand All @@ -87,28 +80,24 @@ require (
go.opentelemetry.io/proto/otlp v1.4.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67 // indirect
golang.org/x/mod v0.24.0 // indirect
golang.org/x/net v0.40.0 // indirect
golang.org/x/oauth2 v0.28.0 // indirect
golang.org/x/sync v0.14.0 // indirect
golang.org/x/sys v0.33.0 // indirect
golang.org/x/term v0.32.0 // indirect
golang.org/x/text v0.25.0 // indirect
golang.org/x/time v0.8.0 // indirect
golang.org/x/tools v0.28.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20241219192143-6b3ec007d9bb // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241219192143-6b3ec007d9bb // indirect
google.golang.org/grpc v1.69.2 // indirect
google.golang.org/protobuf v1.36.0 // indirect
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.32.0 // indirect
k8s.io/apiserver v0.32.0 // indirect
k8s.io/component-base v0.32.0 // indirect
k8s.io/gengo/v2 v2.0.0-20240911193312-2b36238f13e9 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/kube-openapi v0.0.0-20241212222426-2c72e554b1e7 // indirect
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.31.1 // indirect
Expand Down
Loading