diff --git a/.ci/minikube_integration.sh b/.ci/minikube_integration.sh index fd5f706c..e4c26255 100644 --- a/.ci/minikube_integration.sh +++ b/.ci/minikube_integration.sh @@ -62,8 +62,6 @@ kubectl wait deploy/registry-operator-controller-manager --namespace registry-op if [ $? -ne 0 ]; then echo "manager container logs:" kubectl logs -l app=devfileregistry-operator --namespace registry-operator-system --container manager - echo "kube-rbac-proxy container logs:" - kubectl logs -l app=devfileregistry-operator --namespace registry-operator-system --container kube-rbac-proxy # Return the description of every pod kubectl describe pods --namespace registry-operator-system diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 8d2944f5..e33c0c42 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -50,11 +50,8 @@ jobs: fi - name: Check format run: | - go get github.com/google/addlicense@v1.1.1 go install github.com/google/addlicense@v1.1.1 - go get golang.org/x/tools/cmd/goimports@v0.24.0 - go install golang.org/x/tools/cmd/goimports@v0.24.0 - git reset HEAD --hard + go install golang.org/x/tools/cmd/goimports@v0.52.0 make fmt if [[ ! -z $(git status -s) ]] @@ -80,7 +77,7 @@ jobs: - name: Run Gosec Security Scanner run: | - go install github.com/securego/gosec/v2/cmd/gosec@e0cca6fe95306b7e7790d6f1bf6a7bec6d622459 # v2.22.0 + go install github.com/securego/gosec/v2/cmd/gosec@v2.29.0 make gosec if [[ $? != 0 ]] then @@ -105,6 +102,11 @@ jobs: - name: Set up QEMU # Enables arm64 image building uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3.7.0 + - name: Set up Go 1.x + uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5.6.0 + with: + go-version-file: "go.mod" + - name: Check if operator docker build is working run: make docker-buildx-build diff --git a/.github/workflows/release-pr.yaml b/.github/workflows/release-pr.yaml index f71d4899..ef437568 100644 --- a/.github/workflows/release-pr.yaml +++ b/.github/workflows/release-pr.yaml @@ -73,7 +73,7 @@ jobs: - gosec runs-on: ubuntu-latest env: - OPERATOR_SDK_DL_URL: https://github.com/operator-framework/operator-sdk/releases/download/v1.28.0 + OPERATOR_SDK_DL_URL: https://github.com/operator-framework/operator-sdk/releases/download/v1.39.1 OPERATOR_SDK_CLI: ./operator-sdk steps: - name: Checkout registry-operator source code diff --git a/.gitignore b/.gitignore index b944d5c2..dc8e87c3 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,6 @@ bin # cache directory .cache/ + +# Consolidated installation manifests +dist/ diff --git a/CLUSTER_SUPPORT.md b/CLUSTER_SUPPORT.md index 092d7e18..6f273233 100644 --- a/CLUSTER_SUPPORT.md +++ b/CLUSTER_SUPPORT.md @@ -5,11 +5,11 @@ systems based on which Operator SDK version the registry operator is using as well as the API overlap between OpenShift and Kubernetes. -Operator currently targets [Kubernetes 1.29 API](https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG/CHANGELOG-1.29.md) and is tested on [OpenShift 4.18](https://docs.redhat.com/en/documentation/openshift_container_platform/4.18/html/release_notes/ocp-4-18-release-notes). +Operator currently targets [Kubernetes 1.31 API](https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG/CHANGELOG-1.31.md) and is tested on [OpenShift 4.18](https://docs.redhat.com/en/documentation/openshift_container_platform/4.18/html/release_notes/ocp-4-18-release-notes). ## Operator SDK -Current version in use by the Registry Operator is [Operator SDK v1.28.0](https://sdk.operatorframework.io/docs/upgrading-sdk-version/v1.28.0/), planned to use [Operator SDK v1.39.1](https://sdk.operatorframework.io/docs/upgrading-sdk-version/v1.39.1/) ([devfile/api#1626](https://github.com/devfile/api/issues/1626)) to be in sync with target OpenShift 4.18 version. +The Registry Operator uses [Operator SDK v1.39.1](https://sdk.operatorframework.io/docs/upgrading-sdk-version/v1.39.1/) and Kubernetes 1.31 APIs, completing the planned SDK alignment for OpenShift 4.18 ([devfile/api#1626](https://github.com/devfile/api/issues/1626)). To update the Operator SDK, refer to [Upgrade SDK Version](https://sdk.operatorframework.io/docs/upgrading-sdk-version/) and change the following diff --git a/Dockerfile b/Dockerfile index 41cf50bd..d2d693c6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,8 +14,9 @@ # limitations under the License. # Build the manager binary -FROM registry.access.redhat.com/ubi9/go-toolset:1.24.4-1754467841@sha256:3f552f246b4bd5bdfb4da0812085d381d00d3625769baecaed58c2667d344e5c as builder -ARG TARGETARCH=amd64 +FROM --platform=$BUILDPLATFORM registry.access.redhat.com/ubi9/go-toolset:1.26.7-1792425967@sha256:68d6b72cc3eb4c7975b2aca2451f6601c048c095d6b5fc2a310ce3df5ef2ada6 AS builder +ARG TARGETOS=linux +ARG TARGETARCH USER root WORKDIR /workspace @@ -27,13 +28,13 @@ COPY go.sum go.sum RUN go mod download # Copy the go source -COPY main.go main.go +COPY cmd/ cmd/ COPY api/ api/ -COPY controllers/ controllers/ +COPY internal/ internal/ COPY pkg/ pkg/ # Build -RUN CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} GO111MODULE=on go build -a -o manager main.go +RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} GO111MODULE=on go build -a -o manager cmd/main.go ARG ENABLE_WEBHOOKS=true ENV ENABLE_WEBHOOKS=${ENABLE_WEBHOOKS} diff --git a/Makefile b/Makefile index 5ae84806..9dd16626 100644 --- a/Makefile +++ b/Makefile @@ -33,13 +33,13 @@ BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL) # Image URL to use all building/pushing image targets IMG ?= quay.io/devfile/registry-operator:next # ENVTEST_VERSION refers to the version of the setup-envtest binary to use -ENVTEST_VERSION=v0.0.0-20240405143037-c25fe2f5ca0f +ENVTEST_VERSION ?= release-0.19 # ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary. -ENVTEST_K8S_VERSION = 1.26 +ENVTEST_K8S_VERSION ?= 1.31.0 # Controller tools version number -CONTROLLER_TOOLS_VERSION ?= v0.14.0 +CONTROLLER_TOOLS_VERSION ?= v0.23.0 # Kustomize version number -KUSTOMIZE_VERSION ?= v3.8.7 +KUSTOMIZE_VERSION ?= v5.4.3 # Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) ifeq (,$(shell go env GOBIN)) @@ -110,7 +110,9 @@ TARGET_ARCH ?= amd64 .PHONY: test test: manifests generate fmt vet envtest ## Run tests. - KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test -timeout=1h `go list ./... | grep -v /tests/` -coverprofile cover.out -v + KUBEBUILDER_ASSETS="$$( $(ENVTEST) use $(ENVTEST_K8S_VERSION) --use-deprecated-gcs=false -p path )"; \ + export KUBEBUILDER_ASSETS; \ + go test -timeout=1h `go list ./... | grep -v /tests/` -coverprofile cover.out -v ### test-integration: runs integration tests on the cluster set in context. .PHONY: test-integration @@ -123,12 +125,13 @@ test-integration: ##@ Build .PHONY: build manager +build: manager manager: manifests generate fmt vet ## Build manager binary. - GOOS=${TARGET_OS} GOARCH=${TARGET_ARCH} go build -o $(LOCALBIN)/manager ./main.go + GOOS=${TARGET_OS} GOARCH=${TARGET_ARCH} go build -o $(LOCALBIN)/manager ./cmd/main.go .PHONY: run run: manifests generate fmt vet ## Run a controller from your host. - $(LOCALBIN)/manager + go run ./cmd/main.go .PHONY: manifests manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects. @@ -197,19 +200,18 @@ PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le .PHONY: docker-buildx-build docker-buildx-build: test $(MAKE) docker-buildx-setup - - docker buildx build --platform=$(PLATFORMS) --tag ${IMG} --provenance=false -f Dockerfile.cross $(shell pwd) + docker buildx build --platform=$(PLATFORMS) --tag ${IMG} --provenance=false -f Dockerfile $(shell pwd) $(MAKE) docker-buildx-cleanup .PHONY: docker-buildx-push docker-buildx-push: test $(MAKE) docker-buildx-setup - - docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} --provenance=false -f Dockerfile.cross $(shell pwd) + docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} --provenance=false -f Dockerfile $(shell pwd) $(MAKE) docker-buildx-cleanup # INTERNAL: Used to setup the docker-buildx command, not to be called by users .PHONY: docker-buildx-setup docker-buildx-setup: - sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross - docker buildx create --name registry-operator-builder docker buildx use registry-operator-builder @@ -217,19 +219,18 @@ docker-buildx-setup: .PHONY: docker-buildx-cleanup docker-buildx-cleanup: - docker buildx rm registry-operator-builder - rm Dockerfile.cross # Build the bundle image. .PHONY: docker-bundle-buildx-build docker-bundle-buildx-build: $(MAKE) docker-bundle-buildx-setup - - docker buildx build --platform=${PLATFORMS} --tag ${BUNDLE_IMG} --provenance=false -f bundle.Dockerfile $(shell pwd) + docker buildx build --platform=${PLATFORMS} --tag ${BUNDLE_IMG} --provenance=false -f bundle.Dockerfile $(shell pwd) $(MAKE) docker-bundle-buildx-cleanup .PHONY: docker-bundle-buildx-push docker-bundle-buildx-push: $(MAKE) docker-bundle-buildx-setup - - docker buildx build --push --platform=${PLATFORMS} --tag ${BUNDLE_IMG} --provenance=false -f bundle.Dockerfile $(shell pwd) + docker buildx build --push --platform=${PLATFORMS} --tag ${BUNDLE_IMG} --provenance=false -f bundle.Dockerfile $(shell pwd) $(MAKE) docker-bundle-buildx-cleanup # INTERNAL: Used to setup the docker-bundle-buildx command, not to be called by users @@ -245,19 +246,17 @@ docker-bundle-buildx-cleanup: # Clone of docker-buildx command but redesigned to work with podman's workflow # Designed to build and push multi architecture images of the registry operator -# This utilizes a new Dockerfile to insert platform args to preserve the original Dockerfile +# The Dockerfile uses BUILDPLATFORM and TARGETARCH for cross-compilation. .PHONY: podman-buildx-build podman-buildx-build: test - sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross - podman manifest create ${IMG} - - podman build --platform=$(PLATFORMS) --manifest ${IMG} -f Dockerfile.cross $(shell pwd) + - podman build --platform=$(PLATFORMS) --manifest ${IMG} -f Dockerfile $(shell pwd) # Contains cleanup steps to remove files and manifests created during build .PHONY: podman-buildx-push podman-buildx-push: - podman manifest push ${IMG} - podman manifest rm ${IMG} - rm Dockerfile.cross # Build the podman image .PHONY: podman-build @@ -283,10 +282,8 @@ uninstall-cert: # find or download controller-gen # download controller-gen if necessary .PHONY: controller-gen -controller-gen: $(CONTROLLER_GEN) -$(CONTROLLER_GEN): $(LOCALBIN) - test -s $(LOCALBIN)/controller-gen && $(LOCALBIN)/controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION) || \ -GOBIN=$(LOCALBIN) GOFLAGS="" go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION) +controller-gen: $(LOCALBIN) + $(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen,$(CONTROLLER_TOOLS_VERSION)) ##@ Deployment @@ -307,20 +304,38 @@ deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in undeploy: ## 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 | $(K8S_CLI) delete -f - -KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" .PHONY: kustomize -kustomize: $(KUSTOMIZE) -$(KUSTOMIZE): $(LOCALBIN) - test -s $(LOCALBIN)/kustomize || { curl -s $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN); } +kustomize: $(LOCALBIN) ## Download the configured kustomize version. + $(call go-install-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v5,$(KUSTOMIZE_VERSION)) .PHONY: envtest -envtest: $(ENVTEST) ## Download envtest-setup locally if necessary. -$(ENVTEST): $(LOCALBIN) - test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) GOFLAGS="" go install sigs.k8s.io/controller-runtime/tools/setup-envtest@$(ENVTEST_VERSION) +envtest: $(LOCALBIN) ## Download the configured setup-envtest version. + $(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest,$(ENVTEST_VERSION)) + +# Keep versioned binaries and refresh the stable symlink on every invocation. +# Install into a temporary directory so an existing symlink cannot overwrite another version. +define go-install-tool + @set -e; \ + if [ ! -f "$(1)-$(3)" ]; then \ + tool_dir=$$(mktemp -d); \ + trap 'rm -rf "$$tool_dir"' EXIT; \ + GOBIN=$$tool_dir GOFLAGS="" go install $(2)@$(3); \ + tool_name=$$(basename $(2)); \ + case "$$tool_name" in v[0-9]*) tool_name=$$(basename $$(dirname $(2)));; esac; \ + mv "$$tool_dir/$$tool_name" "$(1)-$(3)"; \ + fi; \ + ln -sf "$(abspath $(1)-$(3))" "$(1)" +endef + +.PHONY: build-installer +build-installer: manifests generate kustomize ## Generate dist/install.yaml with CRDs and deployment. + mkdir -p dist + cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG) + $(KUSTOMIZE) build config/default > dist/install.yaml # Generate bundle manifests and metadata, then validate generated files. .PHONY: bundle -bundle: manifests +bundle: manifests kustomize $(OPERATOR_SDK_CLI) generate kustomize manifests -q cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG) $(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK_CLI) generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS) @@ -340,5 +355,5 @@ bundle-push: .PHONY: gosec gosec: # Run this command to install gosec, if not installed: - # go install github.com/securego/gosec/v2/cmd/gosec@v2.22.0 + # go install github.com/securego/gosec/v2/cmd/gosec@v2.29.0 gosec -no-fail -fmt=sarif -out=gosec.sarif -exclude-dir pkg/test -exclude-dir tests ./... diff --git a/PROJECT b/PROJECT index c94dfd4b..de8717b2 100644 --- a/PROJECT +++ b/PROJECT @@ -1,8 +1,7 @@ domain: devfile.io layout: -- go.kubebuilder.io/v3 +- go.kubebuilder.io/v4 plugins: - go.sdk.operatorframework.io/v2: {} manifests.sdk.operatorframework.io/v2: {} scorecard.sdk.operatorframework.io/v2: {} projectName: registry-operator diff --git a/README.md b/README.md index 040ff0a0..c99aa08b 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@