×

OpenShift Container Platform 4.11 supports Operator SDK 1.22.0. If you already have the 1.16.0 CLI installed on your workstation, you can update the CLI to 1.22.0 by installing the latest version.

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

Updating Go-based Operator projects for Operator SDK 1.22.0

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

Prerequisites
  • Operator SDK 1.22.0 installed.

  • An Operator project created or maintained with Operator SDK 1.16.0.

Procedure
  1. Make the following changes to the config/default/manager_auth_proxy_patch.yaml file:

    ...
    spec:
      template:
        spec:
          containers:
          - name: kube-rbac-proxy
            image: registry.redhat.io/openshift4/ose-kube-rbac-proxy:v4.11 (1)
            args:
            - "--secure-listen-address=0.0.0.0:8443"
            - "--upstream=http://127.0.0.1:8080/"
            - "--logtostderr=true"
            - "--v=0" (2)
    ...
    resources:
      limits:
        cpu: 500m
        memory: 128Mi
      requests:
        cpu: 5m
        memory: 64Mi (3)
    1 Update the tag version from v4.10 to v4.11.
    2 Reduce the debugging log level from --v=10 to --v=0.
    3 Add resource requests and limits.
  2. Make the following changes to your Makefile:

    1. Enable support for image digests by adding the following environment variables to your Makefile:

      Old Makefile
      BUNDLE_IMG ?= $(IMAGE_TAG_BASE)-bundle:v$(VERSION)
      ...
      New Makefile
      BUNDLE_IMG ?= $(IMAGE_TAG_BASE)-bundle:v$(VERSION)
      
      # BUNDLE_GEN_FLAGS are the flags passed to the operator-sdk generate bundle command
      BUNDLE_GEN_FLAGS ?= -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
      
      # USE_IMAGE_DIGESTS defines if images are resolved via tags or digests
      # You can enable this value if you would like to use SHA Based Digests
      # To enable set flag to true
      USE_IMAGE_DIGESTS ?= false
      ifeq ($(USE_IMAGE_DIGESTS), true)
      	BUNDLE_GEN_FLAGS += --use-image-digests
      endif
    2. Edit your Makefile to replace the bundle target with the BUNDLE_GEN_FLAGS environment variable:

      Old Makefile
      $(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
      New Makefile
      $(KUSTOMIZE) build config/manifests | operator-sdk generate bundle $(BUNDLE_GEN_FLAGS)
    3. Edit your Makefile to update opm to version 1.23.0:

      .PHONY: opm
      OPM = ./bin/opm
      opm: ## Download opm locally if necessary.
      ifeq (,$(wildcard $(OPM)))
      ifeq (,$(shell which opm 2>/dev/null))
      	@{ \
      	set -e ;\
      	mkdir -p $(dir $(OPM)) ;\
      	OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
      	curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.23.0/$${OS}-$${ARCH}-opm ;\ (1)
      	chmod +x $(OPM) ;\
      	}
      else
      OPM = $(shell which opm)
      endif
      endif
      1 Replace v1.19.1 with v1.23.0.
    4. Edit your Makefile to replace the go get targets with go install targets:

      Old Makefile
      CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
      .PHONY: controller-gen
      controller-gen: ## Download controller-gen locally if necessary.
      	$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.8.0)
      
      KUSTOMIZE = $(shell pwd)/bin/kustomize
      .PHONY: kustomize
      kustomize: ## Download kustomize locally if necessary.
      	$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v3@v3.8.7)
      
      ENVTEST = $(shell pwd)/bin/setup-envtest
      .PHONY: envtest
      envtest: ## Download envtest-setup locally if necessary.
      	$(call go-get-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)
      
      # go-get-tool will 'go get' any package $2 and install it to $1.
      PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
      define go-get-tool
      @[ -f $(1) ] || { \
      set -e ;\
      TMP_DIR=$$(mktemp -d) ;\
      cd $$TMP_DIR ;\
      go mod init tmp ;\
      echo "Downloading $(2)" ;\
      GOBIN=$(PROJECT_DIR)/bin go get $(2) ;\
      rm -rf $$TMP_DIR ;\
      }
      endef
      New Makefile
      ##@ Build Dependencies
      
      ## Location to install dependencies to
      LOCALBIN ?= $(shell pwd)/bin
      $(LOCALBIN):
      	mkdir -p $(LOCALBIN)
      
      ## Tool Binaries
      KUSTOMIZE ?= $(LOCALBIN)/kustomize
      CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
      ENVTEST ?= $(LOCALBIN)/setup-envtest
      
      ## Tool Versions
      KUSTOMIZE_VERSION ?= v3.8.7
      CONTROLLER_TOOLS_VERSION ?= v0.8.0
      
      KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
      .PHONY: kustomize
      kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
      $(KUSTOMIZE): $(LOCALBIN)
      	curl -s $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN)
      
      .PHONY: controller-gen
      controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
      $(CONTROLLER_GEN): $(LOCALBIN)
      	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)
      	GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
    5. Update ENVTEST_K8S_VERSION and controller-gen fields in your Makefile to support Kubernetes 1.24:

      ...
      ENVTEST_K8S_VERSION = 1.24 (1)
      ...
      sigs.k8s.io/controller-tools/cmd/controller-gen@v0.9.0 (2)
      
      1 Update version 1.22 to 1.24.
      2 Update version 0.7.0 to 0.9.0.
    6. Apply the changes to your Makefile and rebuild your Operator by entering the following command:

      $ make
  3. Make the following changes to the go.mod file to update Go and its dependencies:

    go 1.18 (1)
    
    require (
      github.com/onsi/ginkgo v1.16.5 (2)
      github.com/onsi/gomega v1.18.1 (3)
      k8s.io/api v0.24.0 (4)
      k8s.io/apimachinery v0.24.0 (4)
      k8s.io/client-go v0.24.0 (4)
      sigs.k8s.io/controller-runtime v0.12.1 (5)
    )
    1 Update version 1.16 to 1.18.
    2 Update version v1.16.4 to v1.16.5.
    3 Update version v1.15.0 to v1.18.1.
    4 Update version v0.22.1 to v0.24.0.
    5 Update version v0.10.0 to v0.12.1.
  4. Download and clean up the dependencies by entering the following command:

    $ go mod tidy
  5. If you use the api/webhook_suitetest.go and controllers/suite_test.go suite test files, make the following changes:

    Old suite test file
    cfg, err := testEnv.Start()
    New suite test file
    var err error
    // cfg is defined in this file globally.
    cfg, err = testEnv.Start()
  6. If you use the Kubernetes declarative plug-in, update your Dockerfile with the following changes:

    1. Add the following changes below the line that begins COPY controllers/ controllers/:

      # https://github.com/kubernetes-sigs/kubebuilder-declarative-pattern/blob/master/docs/addon/walkthrough/README.md#adding-a-manifest
      # Stage channels and make readable
      COPY channels/ /channels/
      RUN chmod -R a+rx /channels/
    2. Add the following changes below the line that begins COPY --from=builder /workspace/manager .:

      # copy channels
      COPY --from=builder /channels /channels