Skip to content

Commit 6a60c74

Browse files
operator: add image upgrade with env vars
Signed-off-by: Hyeongju Johannes Lee <[email protected]>
1 parent ba3ded1 commit 6a60c74

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

DEVEL.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ Check if the fields mentioned below in the [base CSV manifest file](deployments/
132132
- metadata.annotations.containerImage
133133
- metadata.annotations.createdAT
134134

135+
Check if [manager yaml file](deployments/operator/manager/manager.yaml) `spec.template.spec.containers.env` has correct sha256 digest for each plugin image.
136+
135137
Fork the [Community Operators](https://github.com/k8s-operatorhub/community-operators) repo and clone it:
136138
```
137139
$ git clone https://github.com/<GitHub Username>/community-operators

cmd/operator/README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,13 @@ The upgrade of the deployed plugins can be done by simply installing a new relea
109109

110110
The operator auto-upgrades operator-managed plugins (CR images and thus corresponding deployed daemonsets) to the current release of the operator.
111111

112-
During upgrade the tag in the image path is updated (e.g. docker.io/intel/intel-sgx-plugin:tag), but the rest of the path is left intact.
112+
From `0.28.0` release, each version of the operator can have a set of images in `deployments/operator/manager/manager.yaml` as env variables.
113113

114-
No upgrade is done for:
115-
- Non-operator managed deployments
116-
- Operator deployments without numeric tags
114+
When env variables are set for specific plugins (and their initcontainers), plugins are upgraded to the images set as env variables and all user input is ignored.
115+
116+
The name of env variables is capitalized image with '_SHA' ending (e.g. in case of the image for `intel-sgx-plugin`, the env variable is `INTEL_SGX_PLUGIN_SHA`).
117+
118+
The value of env variables is the full path of the image (e.g. `docker.io/intel/intel-sgx-plugin@sha256:<digest>`).
117119

118120
## Limiting Supported Devices
119121

pkg/controllers/reconciler.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ package controllers
1717

1818
import (
1919
"context"
20+
"os"
21+
"path/filepath"
2022
"strings"
2123
"sync"
2224

@@ -175,6 +177,16 @@ func UpgradeImages(image *string, initimage *string) (upgrade bool) {
175177

176178
if parts := strings.SplitN(*s, ":", 2); len(parts) == 2 && len(parts[0]) > 0 {
177179
name, version := parts[0], parts[1]
180+
181+
envVarValue := os.Getenv(strings.ReplaceAll(strings.ToUpper(filepath.Base(name)), "-", "_") + "_SHA")
182+
183+
if envVarValue != "" && *s != envVarValue {
184+
*s = envVarValue
185+
upgrade = true
186+
187+
continue
188+
}
189+
178190
if ver, err := versionutil.ParseSemantic(version); err == nil && ver.LessThan(ImageMinVersion) {
179191
*s = name + ":" + ImageMinVersion.String()
180192
upgrade = true

0 commit comments

Comments
 (0)