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.
We recommend using the following format when referencing your images within your values.yaml file. It will make it easier to refactor your operator if it needs to be provided within an air-gapped environment. This is also a technical requirement for 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.
1
vi values.yaml
Copied!
values.yaml
1
###omitted for brevity#
2
3
##​image:
4
## registry: docker.io
5
## repository: bitnami/wordpress
6
## tag: 5.3.2-debian-10-r0
7
image: docker.io/bitnami/wordpress:5.3.2-debian-10-r0
8
## Specify a imagePullPolicy
9
## Defaults to 'Always' if image tag is 'latest', else set to 'IfNotPresent'
10
## ref: http://kubernetes.io/docs/user-guide/images/#pre-pulling-images
11
pullPolicy: IfNotPresent​
12
13
###omitted for brevity###​
Copied!
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.
1
cd templates/
Copied!
1
grep "image:" *
Copied!
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.
deployment.yaml
1
### omitted for brevity ###​
2
3
containers:
4
- name: wordpress
5
image: {{ .Values.image.image }}
6
pullPolicy: {{ .Values.image.pullPolicy }}​
7
8
### omitted for brevity ###
Copied!
Next we need to edit the watches.yaml file to add the overrideValues: field
1
vi watches.yaml
Copied!
watches.yaml
1
---
2
- version: v1alpha1
3
group: apigw.wordpress.com
4
kind: Wordpress
5
chart: helm-charts/wordpress
6
overrideValues:
7
image.image: $RELATED_IMAGE_WORDPRESS
Copied!
Finally before we build the ClusterServiceVersion we need to edit the manager.yaml.
1
vi config/manager/manager.yaml
Copied!
manager.yaml
1
apiVersion: v1
2
kind: Namespace
3
metadata:
4
labels:
5
control-plane: controller-manager
6
name: system
7
---
8
apiVersion: apps/v1
9
kind: Deployment
10
metadata:
11
name: wordpress-operator
12
spec:
13
replicas: 1
14
selector:
15
matchLabels:
16
name: wordpress-operator
17
template:
18
metadata:
19
labels:
20
name: wordpress-operator
21
spec:
22
serviceAccountName: wordpress-operator
23
containers:
24
- name: wordpress-operator
25
# Replace this with the built image name
26
image: PUBLISHED IMAGE IN CONNECT (registry.redhat.connect/etc)
27
imagePullPolicy: Always
28
env:
29
- name: WATCH_NAMESPACE
30
valueFrom:
31
fieldRef:
32
fieldPath: metadata.namespace
33
- name: POD_NAME
34
valueFrom:
35
fieldRef:
36
fieldPath: metadata.name
37
- name: OPERATOR_NAME
38
value: "wordpress-operator"
39
- name: RELATED_IMAGE_WORDPRESS
40
value: docker.io/bitnami/wordpress:5.3.2-debian-10-10
Copied!
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.
Copy link