Updating projects for newer Operator SDK versions

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

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

Updating projects for Operator SDK v1.16.0

The following procedure updates an existing Operator project for compatibility with v1.16.0.

  • Operator SDK v1.16.0 supports Kubernetes 1.22.

  • Many deprecated v1beta1 APIs were removed in Kubernetes 1.22, including sigs.k8s.io/controller-runtime v0.10.0 and controller-gen v0.7.

  • Updating projects to Kubernetes 1.22 is a breaking change if you need to scaffold v1beta1 APIs for custom resource definitions (CRDs) or webhooks to publish your project into older cluster versions.

See Validating bundle manifests for APIs removed from Kubernetes 1.22 and Beta APIs removed from Kubernetes 1.22 for more information about changes introduced in Kubernetes 1.22.

Prerequisites

  • Operator SDK v1.16.0 installed.

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

Procedure

  1. Add the protocol field in the config/default/manager_auth_proxy_patch.yaml and config/rbac/auth_proxy_service.yaml files:

    1. ...
    2. ports:
    3. - containerPort: 8443
    4. + protocol: TCP
    5. name: https
  2. Make the following changes to the config/manager/manager.yaml file:

    1. Increase the CPU and memory resource limits:

      1. resources:
      2. limits:
      3. - cpu: 100m
      4. - memory: 30Mi
      5. + cpu: 200m
      6. + memory: 100Mi
    2. Add an annotation to specify the default container manager:

      1. ...
      2. template:
      3. metadata:
      4. annotations:
      5. kubectl.kubernetes.io/default-container: manager
      6. ...
  3. Add PHONY targets to all of the targets in your Makefile file.

  4. For Go-based Operator projects, make the following changes:

    1. Install the setup-envtest binary.

    2. Change your go.mod file to update the dependencies:

      1. k8s.io/api v0.22.1
      2. k8s.io/apimachinery v0.22.1
      3. k8s.io/client-go v0.22.1
      4. sigs.k8s.io/controller-runtime v0.10.0
    3. Run the go mod tidy command to download the dependencies:

      1. $ go mod tidy
    4. Make the following changes to your Makefile file:

      1. ...
      2. + ENVTEST_K8S_VERSION = 1.22
      3. test: manifests generate fmt vet envtest ## Run tests.
      4. - go test ./... -coverprofile cover.out
      5. + KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out
      6. ...
      7. - $(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
      8. + $(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
      9. ...
      10. # Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
      11. - CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false"
      12. ...
      13. - admissionReviewVersions={v1,v1beta1}
      14. + admissionReviewVersions=v1
      15. ...
      16. + ifndef ignore-not-found
      17. + ignore-not-found = false
      18. + endif
      19. ##@ Deployment
      20. ...
      21. - sh kubectl delete -f -
      22. + sh kubectl delete --ignore-not-found=$(ignore-not-found) -f -
    5. Run the make manifest command to generate your manifests with the updated version of Kubernetes:

      1. $ make manifest
  5. For Ansible-based Operator projects, make the following changes:

    1. Change your requirements.yml file to include the following:

      1. Replace the community.kubernetes collection with the kubernetes.core collection:

        1. ...
        2. - name: kubernetes.core
        3. version: "2.2.0"
        4. ...
      2. Update the operator_sdk.util utility from version 0.2.0 to 0.3.1:

        1. ...
        2. - name: operator_sdk.util
        3. version: "0.3.1"
    2. Verify the default resource limits in the config/manager/manager.yaml file:

      1. ...
      2. # TODO(user): Configure the resources accordingly based on the project requirements.
      3. # More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
      4. resources:
      5. limits:
      6. cpu: 500m
      7. memory: 768Mi
      8. requests:
      9. cpu: 10m
      10. memory: 256Mi

      Operator SDK scaffolds these values as a reasonable default setting. Operator authors should set and optimize resource limits based on the requirements of their project.

    3. Optional: Make the following changes if you want to run your Ansible-based Operator locally by using the make run command:

      1. Change the run target in the Makefile file:

        1. ANSIBLE_ROLES_PATH="$(ANSIBLE_ROLES_PATH):$(shell pwd)/roles" $(ANSIBLE_OPERATOR) run
      2. Update the local version of ansible-runner to 2.0.2 or later.

        As of version 2.0, the ansible-runner tool includes changes in the command signature that are not compatible with earlier versions.

Additional resources