Updating Helm-based projects for newer Operator SDK versions

OKD 4.12 supports Operator SDK v1.25.0. If you already have the v1.22.0 CLI installed on your workstation, you can update the CLI to v1.25.0 by installing the latest version.

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

Updating Helm-based Operator projects for Operator SDK v1.25.0

The following procedure updates an existing Helm-based Operator project for compatibility with v1.25.0.

Prerequisites

  • Operator SDK v1.25.0 installed

  • An Operator project created or maintained with Operator SDK v1.22.0

Procedure

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

    1. apiVersion: apps/v1
    2. kind: Deployment
    3. metadata:
    4. name: controller-manager
    5. namespace: system
    6. spec:
    7. template:
    8. spec:
    9. containers:
    10. - name: kube-rbac-proxy
    11. image: registry.redhat.io/openshift4/ose-kube-rbac-proxy:v4.12 (1)
    12. args:
    13. - "--secure-listen-address=0.0.0.0:8443"
    14. - "--upstream=http://127.0.0.1:8080/"
    15. - "--logtostderr=true"
    16. - "--v=0"
    17. ...
    1Update the tag version from v4.11 to v4.12.
  2. Make the following changes to your Makefile:

    1. To enable multi-architecture build support, add the docker-buildx target to your project Makefile:

      Example Makefile

      1. # PLATFORMS defines the target platforms for the manager image be build to provide support to multiple
      2. # architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
      3. # - able to use docker buildx . More info: https://docs.docker.com/build/buildx/
      4. # - have enable BuildKit, More info: https://docs.docker.com/develop/develop-images/build_enhancements/
      5. # - be able to push the image for your registry (i.e. if you do not inform a valid value via IMG=<myregistry/image:<tag>> than the export will fail)
      6. # To properly provided solutions that supports more than one platform you should use this option.
      7. PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
      8. .PHONY: docker-buildx
      9. docker-buildx: test ## Build and push docker image for the manager for cross-platform support
      10. # copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
      11. sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
      12. - docker buildx create --name project-v3-builder
      13. docker buildx use project-v3-builder
      14. - docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross
      15. - docker buildx rm project-v3-builder
      16. rm Dockerfile.cross
    2. To enable support for arm64 architectures in your Operator project, make the following changes to your Makefile:

      Old Makefile

      1. OS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
      2. ARCH := $(shell uname -m | sed 's/x86_64/amd64/')

      New Makefile

      1. OS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
      2. ARCH := $(shell uname -m | sed 's/x86_64/amd64/' | sed 's/aarch64/arm64/')
    3. Update the Kustomize version to v4.5.5 as shown in the following example:

      Old Makefile

      1. .PHONY: kustomize
      2. KUSTOMIZE = $(shell pwd)/bin/kustomize
      3. kustomize: ## Download kustomize locally if necessary.
      4. ifeq (,$(wildcard $(KUSTOMIZE)))
      5. ifeq (,$(shell which kustomize 2>/dev/null))
      6. @{ \
      7. set -e ;\
      8. mkdir -p $(dir $(KUSTOMIZE)) ;\
      9. curl -sSLo - https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/v3.8.7/kustomize_v3.8.7_$(OS)_$(ARCH).tar.gz | \
      10. tar xzf - -C bin/ ;\
      11. }
      12. else

      New Makefile

      1. .PHONY: kustomize
      2. KUSTOMIZE = $(shell pwd)/bin/kustomize
      3. kustomize: ## Download kustomize locally if necessary.
      4. ifeq (,$(wildcard $(KUSTOMIZE)))
      5. ifeq (,$(shell which kustomize 2>/dev/null))
      6. @{ \
      7. set -e ;\
      8. mkdir -p $(dir $(KUSTOMIZE)) ;\
      9. curl -sSLo - https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/v4.5.5/kustomize_v4.5.5_$(OS)_$(ARCH).tar.gz | \ (1)
      10. tar xzf - -C bin/ ;\
      11. }
      12. else
      1Update version v3.8.7 to v4.5.5.

      Kustomize version 4.0.0 removed the go-getter plugin and introduced breaking changes that are not backwards compatible with earlier versions. Operator projects that rely on older versions of Kustomize might not work with newer releases.

    4. To apply the changes to your Makefile and rebuild your Operator, enter the following command:

      1. $ make
  3. Update your config/default/kustomizations.yaml file as shown in the following examples:

    Example kustomizations.yaml file

    1. # Adds namespace to all resources.
    2. namespace: memcached-operator-system
    3. # Value of this field is prepended to the
    4. # names of all resources, e.g. a deployment named
    5. # "wordpress" becomes "alices-wordpress".
    6. # Note that it should also match with the prefix (text before '-') of the namespace
    7. # field above.
    8. namePrefix: memcached-operator-
    9. # Labels to add to all resources and selectors.
    10. #labels: (1)
    11. #- includeSelectors: true (2)
    12. # pairs:
    13. # someName: someValue
    14. resources: (3)
    15. - ../crd
    16. - ../rbac
    17. - ../manager
    1Replace the commonLabels field with the labels field.
    2Add includeSelectors: true.
    3Replace the bases field with the resources field.

Additional resources