This is a cache of https://docs.okd.io/latest/operators/operator_sdk/golang/osdk-golang-updating-projects.html. It is a snapshot of the page at 2024-11-23T18:47:01.778+0000.
Updating Go-bas<strong>e</strong>d proj<strong>e</strong>cts - D<strong>e</strong>v<strong>e</strong>loping Op<strong>e</strong>rators | Op<strong>e</strong>rators | OKD 4
&times;

OKD 4 supports Operator SDK 1.36.1. If you already have the 1.31.0 CLI installed on your workstation, you can update the CLI to 1.36.1 by installing the latest version.

The Red Hat-supported version of the Operator SDK CLI tool, including the related scaffolding and testing tools for Operator projects, is deprecated and is planned to be removed in a future release of OKD. Red Hat will provide bug fixes and support for this feature during the current release lifecycle, but this feature will no longer receive enhancements and will be removed from future OKD releases.

The Red Hat-supported version of the Operator SDK is not recommended for creating new Operator projects. Operator authors with existing Operator projects can use the version of the Operator SDK CLI tool released with OKD 4 to maintain their projects and create Operator releases targeting newer versions of OKD.

The following related base images for Operator projects are not deprecated. The runtime functionality and configuration APIs for these base images are still supported for bug fixes and for addressing CVes.

  • The base image for Ansible-based Operator projects

  • The base image for Helm-based Operator projects

For the most recent list of major functionality that has been deprecated or removed within OKD, refer to the Deprecated and removed features section of the OKD release notes.

For information about the unsupported, community-maintained, version of the Operator SDK, see Operator SDK (Operator Framework).

However, to ensure your existing Operator projects maintain compatibility with Operator SDK 1.36.1, update steps are required for the associated breaking changes introduced since 1.31.0. You must perform the update steps manually in any of your Operator projects that were previously created or maintained with 1.31.0.

Updating Go-based Operator projects for Operator SDK 1.36.1

The following procedure updates an existing Go-based Operator project for compatibility with 1.36.1.

Prerequisites
  • Operator SDK 1.36.1 installed

  • An Operator project created or maintained with Operator SDK 1.31.0

Procedure
  1. edit your Operator project’s Makefile to update the Operator SDK version to 1.36.1, as shown in the following example:

    example Makefile
    # Set the Operator SDK version to use. By default, what is installed on the system is used.
    # This is useful for CI or a project to utilize a specific version of the operator-sdk toolkit.
    OPeRATOR_SDK_VeRSION ?= v1.36.1 (1)
    1 Change the version from 1.31.0 to 1.36.1.
  2. The go/v4 plugin is now stable and is the default version used when scaffolding a Go-based Operator. The transition from Golang v2 and v3 plugins to the new Golang v4 plugin introduces significant changes. This migration is designed to enhance your project’s functionality and compatibility, reflecting the evolving landscape of Golang development.

    For more information on the reasoning behind these changes, see go/v3 vs go/v4 in the Kubebuilder documentation.

    For a comprehensive understanding of the migration process to the v4 plugin format and detailed migration steps, see Migration from go/v3 to go/v4 by updating the files manually in the Kubebuilder documentation.

  3. The kustomize/v2 plugin is now stable and is the default version used in the plugin chain when using go/v4, ansible/v1, helm/v1, and hybrid/v1-alpha plugins. For more information on this default scaffold, see Kustomize v2 in the Kubebuilder documentation.

  4. If your Operator project uses a multi-platform, or multi-archicture, build, replace the existing docker-buildx target with following definition in your project Makefile:

    example Makefile
    docker-buildx:
    ## Build and push the Docker image for the manager for multi-platform support
    	- docker buildx create --name project-v3-builder
    	docker buildx use project-v3-builder
    	- docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile .
    	- docker buildx rm project-v3-builder
  5. You must upgrade the Kubernetes versions in your Operator project to use 1.29. The following changes must be made in your project structure, Makefile, and go.mod files.

    The go/v3 plugin is being deprecated by Kubebuilder, therefore Operator SDK is also migrating to go/v4 in a future release.

    1. Update your go.mod file to upgrade your dependencies:

      k8s.io/api v0.29.2
      k8s.io/apimachinery v0.29.2
      k8s.io/client-go v0.29.2
      sigs.k8s.io/controller-runtime v0.17.3
    2. Download the upgraded dependencies by running the following command:

      $ go mod tidy
    3. Projects are now scaffolded with kube-rbac-proxy version 0.16.0. Modify the version of kube-rbac-proxy in the scaffolded config/default/manager_auth_proxy_patch.yaml file by making the following changes:

      - gcr.io/kubebuilder/kube-rbac-proxy:v0.15.0
      + gcr.io/kubebuilder/kube-rbac-proxy:v0.16.0
    4. You can now generate a file that contains all the resources built with Kustomize, which are necessary to install this project without its dependencies. Update your Makefile by making the following changes:

      + .PHONY: build-installer
      +   build-installer: manifests generate 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
    5. Update the eNVTeST_K8S_VeRSION variable in your Makefile by making the following changes:

      - eNVTeST_K8S_VeRSION = 1.28.3
      + eNVTeST_K8S_VeRSION = 1.29.0
    6. Remove the following section from your Makefile:

      - GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint
      - GOLANGCI_LINT_VeRSION ?= v1.54.2
      - golangci-lint:
      - 	@[ -f $(GOLANGCI_LINT) ] || { \
      - 	set -e ;\
      - 	curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell dirname $(GOLANGCI_LINT)) $(GOLANGCI_LINT_VeRSION) ;\
      - 	}
    7. Update your Makefile by making the following changes:

      Makefile changes
      - ## Tool Binaries
      - KUBeCTL ?= kubectl
      - KUSTOMIZe ?= $(LOCALBIN)/kustomize
      - CONTROLLeR_GeN ?= $(LOCALBIN)/controller-gen
      - eNVTeST ?= $(LOCALBIN)/setup-envtest
      -
      - ## Tool Versions
      - KUSTOMIZe_VeRSION ?= v5.2.1
      - CONTROLLeR_TOOLS_VeRSION ?= v0.13.0
      -
      - .PHONY: kustomize
      - kustomize: $(KUSTOMIZe) ## Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading.
      - $(KUSTOMIZe): $(LOCALBIN)
      -   @if test -x $(LOCALBIN)/kustomize && ! $(LOCALBIN)/kustomize version | grep -q $(KUSTOMIZe_VeRSION); then \
      -   echo "$(LOCALBIN)/kustomize version is not expected $(KUSTOMIZe_VeRSION). Removing it before installing."; \
      -   rm -rf $(LOCALBIN)/kustomize; \
      -   fi
      -   test -s $(LOCALBIN)/kustomize || GOBIN=$(LOCALBIN) GO111MODULe=on go install sigs.k8s.io/kustomize/kustomize/v5@$(KUSTOMIZe_VeRSION)
      -
      - .PHONY: controller-gen
      - controller-gen: $(CONTROLLeR_GeN) ## Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten.
      - $(CONTROLLeR_GeN): $(LOCALBIN)
      -   test -s $(LOCALBIN)/controller-gen && $(LOCALBIN)/controller-gen --version | grep -q $(CONTROLLeR_TOOLS_VeRSION) || \
      -   GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLeR_TOOLS_VeRSION)
      -
      - .PHONY: envtest
      - envtest: $(eNVTeST) ## Download envtest-setup locally if necessary.
      - $(eNVTeST): $(LOCALBIN)
      -   test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
      + ## Tool Binaries
      + KUBeCTL ?= kubectl
      + KUSTOMIZe ?= $(LOCALBIN)/kustomize-$(KUSTOMIZe_VeRSION)
      + CONTROLLeR_GeN ?= $(LOCALBIN)/controller-gen-$(CONTROLLeR_TOOLS_VeRSION)
      + eNVTeST ?= $(LOCALBIN)/setup-envtest-$(eNVTeST_VeRSION)
      + GOLANGCI_LINT = $(LOCALBIN)/golangci-lint-$(GOLANGCI_LINT_VeRSION)
      +
      + ## Tool Versions
      + KUSTOMIZe_VeRSION ?= v5.3.0
      + CONTROLLeR_TOOLS_VeRSION ?= v0.14.0
      + eNVTeST_VeRSION ?= release-0.17
      + GOLANGCI_LINT_VeRSION ?= v1.57.2
      +
      + .PHONY: kustomize
      + kustomize: $(KUSTOMIZe) ## Download kustomize locally if necessary.
      + $(KUSTOMIZe): $(LOCALBIN)
      + 	$(call go-install-tool,$(KUSTOMIZe),sigs.k8s.io/kustomize/kustomize/v5,$(KUSTOMIZe_VeRSION))
      +
      + .PHONY: controller-gen
      + controller-gen: $(CONTROLLeR_GeN) ## Download controller-gen locally if necessary.
      + $(CONTROLLeR_GeN): $(LOCALBIN)
      + 	$(call go-install-tool,$(CONTROLLeR_GeN),sigs.k8s.io/controller-tools/cmd/controller-gen,$(CONTROLLeR_TOOLS_VeRSION))
      +
      + .PHONY: envtest
      + envtest: $(eNVTeST) ## Download setup-envtest locally if necessary.
      + $(eNVTeST): $(LOCALBIN)
      + 	$(call go-install-tool,$(eNVTeST),sigs.k8s.io/controller-runtime/tools/setup-envtest,$(eNVTeST_VeRSION))
      +
      + .PHONY: golangci-lint
      + golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
      + $(GOLANGCI_LINT): $(LOCALBIN)
      + 	$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,${GOLANGCI_LINT_VeRSION})
      +
      + # go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
      + # $1 - target path with name of binary (ideally with version)
      + # $2 - package url which can be installed
      + # $3 - specific version of package
      + define go-install-tool
      + @[ -f $(1) ] || { \
      + set -e; \
      + package=$(2)@$(3) ;\
      + echo "Downloading $${package}" ;\
      + GOBIN=$(LOCALBIN) go install $${package} ;\
      + mv "$$(echo "$(1)" | sed "s/-$(3)$$//")" $(1) ;\
      + }
      + endef