Updating 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 Ansible-based Operator projects for Operator SDK v1.25.0
The following procedure updates an existing Ansible-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
Make the following changes to the
config/default/manager_auth_proxy_patch.yaml
file:apiVersion: apps/v1
kind: Deployment
metadata:
name: controller-manager
namespace: system
spec:
template:
spec:
containers:
- name: kube-rbac-proxy
image: registry.redhat.io/openshift4/ose-kube-rbac-proxy:v4.12 (1)
args:
- "--secure-listen-address=0.0.0.0:8443"
- "--upstream=http://127.0.0.1:8080/"
- "--logtostderr=true"
- "--v=0"
...
1 Update the tag version from v4.11
tov4.12
.Make the following changes to your
Makefile
:To enable multi-architecture build support, add the
docker-buildx
target to your projectMakefile
:Example
Makefile
# PLATFORMS defines the target platforms for the manager image be build to provide support to multiple
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
# - able to use docker buildx . More info: https://docs.docker.com/build/buildx/
# - have enable BuildKit, More info: https://docs.docker.com/develop/develop-images/build_enhancements/
# - 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)
# To properly provided solutions that supports more than one platform you should use this option.
PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
.PHONY: docker-buildx
docker-buildx: test ## Build and push docker image for the manager for cross-platform support
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
- docker buildx create --name project-v3-builder
docker buildx use project-v3-builder
- docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross
- docker buildx rm project-v3-builder
rm Dockerfile.cross
To enable support for
arm64
architectures in your Operator project, make the following changes to yourMakefile
:Old
Makefile
OS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
ARCH := $(shell uname -m | sed 's/x86_64/amd64/')
New
Makefile
OS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
ARCH := $(shell uname -m | sed 's/x86_64/amd64/' | sed 's/aarch64/arm64/')
Update the Kustomize version to
v4.5.5
as shown in the following example:Old
Makefile
.PHONY: kustomize
KUSTOMIZE = $(shell pwd)/bin/kustomize
kustomize: ## Download kustomize locally if necessary.
ifeq (,$(wildcard $(KUSTOMIZE)))
ifeq (,$(shell which kustomize 2>/dev/null))
@{ \
set -e ;\
mkdir -p $(dir $(KUSTOMIZE)) ;\
curl -sSLo - https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/v3.8.7/kustomize_v3.8.7_$(OS)_$(ARCH).tar.gz | \
tar xzf - -C bin/ ;\
}
else
New
Makefile
.PHONY: kustomize
KUSTOMIZE = $(shell pwd)/bin/kustomize
kustomize: ## Download kustomize locally if necessary.
ifeq (,$(wildcard $(KUSTOMIZE)))
ifeq (,$(shell which kustomize 2>/dev/null))
@{ \
set -e ;\
mkdir -p $(dir $(KUSTOMIZE)) ;\
curl -sSLo - https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/v4.5.5/kustomize_v4.5.5_$(OS)_$(ARCH).tar.gz | \ (1)
tar xzf - -C bin/ ;\
}
else
1 Update version v3.8.7
tov4.5.5
.Kustomize version
4.0.0
removed thego-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.To apply the changes to your
Makefile
and rebuild your Operator, enter the following command:$ make
Update your
config/default/kustomizations.yaml
file as shown in the following examples:Example
kustomizations.yaml
file# Adds namespace to all resources.
namespace: memcached-operator-system
# Value of this field is prepended to the
# names of all resources, e.g. a deployment named
# "wordpress" becomes "alices-wordpress".
# Note that it should also match with the prefix (text before '-') of the namespace
# field above.
namePrefix: memcached-operator-
# Labels to add to all resources and selectors.
#labels: (1)
#- includeSelectors: true (2)
# pairs:
# someName: someValue
resources: (3)
- ../crd
- ../rbac
- ../manager
1 Replace the commonLabels
field with thelabels
field.2 Add includeSelectors: true
.3 Replace the bases
field with theresources
field.Update your
molecule/default/kustomize.yml
file with the following changes:Example
molecule/default/kustomize.yml
file---
- name: Build kustomize testing overlay
# load_restrictor must be set to none so we can load patch files from the default overlay
command: '{{ kustomize }} build --load-restrictor LoadRestrictionsNone' (1)
args:
chdir: '{{ config_dir }}/testing'
register: resources
changed_when: false
1 Replace —load_restrictor none .
with—load-restrictor LoadRestrictionNone
.