Using a Single Image Variable (Red Hat Marketplace)
This step is Optional in terms of creating a certified operator but it is a technical requirement for the Red Hat Marketplace.
The first place we will need to make changes is within the values.yaml file referenced by the Helm Chart. Any image that is referenced with multiple image variables needs to be commented out and a new single image variable needs to be created.
vi values.yaml
###omitted for brevity#
##image:
## registry: docker.io
## repository: bitnami/wordpress
## tag: 5.3.2-debian-10-r0
image: docker.io/bitnami/wordpress:5.3.2-debian-10-r0
## Specify a imagePullPolicy
## Defaults to 'Always' if image tag is 'latest', else set to 'IfNotPresent'
## ref: http://kubernetes.io/docs/user-guide/images/#pre-pulling-images
pullPolicy: IfNotPresent
###omitted for brevity###
As you can see we condensed the image from being listed as 3 sub-variables to one single image variable. This must be done for all images listed within the values.yaml file. In this example this is the only image listed, therefore the only image that needs to have been changed. Next, we will need to identify any references to the image we modified in the templates/
directory.
cd templates/
grep "image:" *
This will list out all of the templates files that reference the image. Using wordpress as an example you can see that the deployment.yaml
is the only file we need to change. Within this file we now need to list the image as shown below.
### omitted for brevity ###
containers:
- name: wordpress
image: {{ .Values.image.image }}
pullPolicy: {{ .Values.image.pullPolicy }}
### omitted for brevity ###
Next we need to edit the watches.yaml file to add the overrideValues:
field
vi watches.yaml
---
- version: v1alpha1
group: apigw.wordpress.com
kind: Wordpress
chart: helm-charts/wordpress
overrideValues:
image.image: $RELATED_IMAGE_WORDPRESS
Finally before we build the ClusterServiceVersion we need to edit the manager.yaml.
vi config/manager/manager.yaml
apiVersion: v1
kind: Namespace
metadata:
labels:
control-plane: controller-manager
name: system
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: wordpress-operator
spec:
replicas: 1
selector:
matchLabels:
name: wordpress-operator
template:
metadata:
labels:
name: wordpress-operator
spec:
serviceAccountName: wordpress-operator
containers:
- name: wordpress-operator
# Replace this with the built image name
image: PUBLISHED IMAGE IN CONNECT (registry.redhat.connect/etc)
imagePullPolicy: Always
env:
- name: WATCH_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: OPERATOR_NAME
value: "wordpress-operator"
- name: RELATED_IMAGE_WORDPRESS
value: docker.io/bitnami/wordpress:5.3.2-debian-10-10
Adding the image location and the last environment variable to the manager.yaml will allow you to build your CSV with these changes automatically being generated. If you have already built the CSV you will need to adjust it as well.
This is not a required step for certification at this time. Though it may be in the future. Making the adjustments to how the image is referenced now, will save you a lot of time in the future if this feature becomes a requirement.
Last updated