Skip to content

Commit 44cc057

Browse files
authored
Merge pull request #1499 from hj-johannes-lee/PR-2023-026
operator: add image upgrade with env vars
2 parents 0889ca1 + 26bf615 commit 44cc057

File tree

12 files changed

+34
-14
lines changed

12 files changed

+34
-14
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

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
2424
endif
2525
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
2626
OLM_MANIFESTS = deployments/operator/manifests
27+
BUNDLE_GEN_FLAGS ?= -q --overwrite --version $(TAG) $(BUNDLE_METADATA_OPTS) --kustomize-dir $(OLM_MANIFESTS) --output-dir . --use-image-digests
2728
BUNDLE_DIR = community-operators/operators/intel-device-plugins-operator/$(TAG)
2829

2930
TESTDATA_DIR = pkg/topology/testdata
@@ -120,7 +121,7 @@ bundle:
120121
rm -rf $(BUNDLE_DIR)
121122
mkdir -p $(BUNDLE_DIR)
122123
$(OPERATOR_SDK) generate kustomize manifests -q --input-dir $(OLM_MANIFESTS) --output-dir $(OLM_MANIFESTS) --apis-dir pkg/apis
123-
$(KUSTOMIZE) build $(OLM_MANIFESTS) | sed "s|intel-deviceplugin-operator:devel|intel-deviceplugin-operator:$(TAG)|" | $(OPERATOR_SDK) generate bundle -q --overwrite --kustomize-dir $(OLM_MANIFESTS) --version $(TAG) $(BUNDLE_METADATA_OPTS) --output-dir .
124+
$(KUSTOMIZE) build $(OLM_MANIFESTS) | sed "s|intel-deviceplugin-operator:devel|intel-deviceplugin-operator:$(TAG)|" | $(OPERATOR_SDK) generate bundle $(BUNDLE_GEN_FLAGS)
124125
# Remove unneeded resources
125126
rm manifests/*service.yaml
126127
rm manifests/*clusterrole.yaml

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/dlb/controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func (c *controller) CreateEmptyObject() client.Object {
6868

6969
func (c *controller) Upgrade(ctx context.Context, obj client.Object) bool {
7070
dp := obj.(*devicepluginv1.DlbDevicePlugin)
71-
return controllers.UpgradeImages(&dp.Spec.Image, &dp.Spec.InitImage)
71+
return controllers.UpgradeImages(ctx, &dp.Spec.Image, &dp.Spec.InitImage)
7272
}
7373

7474
func (c *controller) GetTotalObjectCount(ctx context.Context, clnt client.Client) (int, error) {

pkg/controllers/dsa/controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func (c *controller) CreateEmptyObject() client.Object {
7171

7272
func (c *controller) Upgrade(ctx context.Context, obj client.Object) bool {
7373
dp := obj.(*devicepluginv1.DsaDevicePlugin)
74-
return controllers.UpgradeImages(&dp.Spec.Image, &dp.Spec.InitImage)
74+
return controllers.UpgradeImages(ctx, &dp.Spec.Image, &dp.Spec.InitImage)
7575
}
7676

7777
func (c *controller) GetTotalObjectCount(ctx context.Context, clnt client.Client) (int, error) {

pkg/controllers/fpga/controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func (c *controller) CreateEmptyObject() client.Object {
6767

6868
func (c *controller) Upgrade(ctx context.Context, obj client.Object) bool {
6969
dp := obj.(*devicepluginv1.FpgaDevicePlugin)
70-
return controllers.UpgradeImages(&dp.Spec.Image, &dp.Spec.InitImage)
70+
return controllers.UpgradeImages(ctx, &dp.Spec.Image, &dp.Spec.InitImage)
7171
}
7272

7373
func (c *controller) GetTotalObjectCount(ctx context.Context, clnt client.Client) (int, error) {

pkg/controllers/gpu/controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func (c *controller) CreateEmptyObject() client.Object {
7272

7373
func (c *controller) Upgrade(ctx context.Context, obj client.Object) bool {
7474
dp := obj.(*devicepluginv1.GpuDevicePlugin)
75-
return controllers.UpgradeImages(&dp.Spec.Image, &dp.Spec.InitImage)
75+
return controllers.UpgradeImages(ctx, &dp.Spec.Image, &dp.Spec.InitImage)
7676
}
7777

7878
func (c *controller) GetTotalObjectCount(ctx context.Context, clnt client.Client) (int, error) {

pkg/controllers/iaa/controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func (c *controller) CreateEmptyObject() client.Object {
6969

7070
func (c *controller) Upgrade(ctx context.Context, obj client.Object) bool {
7171
dp := obj.(*devicepluginv1.IaaDevicePlugin)
72-
return controllers.UpgradeImages(&dp.Spec.Image, &dp.Spec.InitImage)
72+
return controllers.UpgradeImages(ctx, &dp.Spec.Image, &dp.Spec.InitImage)
7373
}
7474

7575
func (c *controller) GetTotalObjectCount(ctx context.Context, clnt client.Client) (int, error) {

pkg/controllers/qat/controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func (c *controller) CreateEmptyObject() client.Object {
7272

7373
func (c *controller) Upgrade(ctx context.Context, obj client.Object) bool {
7474
dp := obj.(*devicepluginv1.QatDevicePlugin)
75-
return controllers.UpgradeImages(&dp.Spec.Image, &dp.Spec.InitImage)
75+
return controllers.UpgradeImages(ctx, &dp.Spec.Image, &dp.Spec.InitImage)
7676
}
7777

7878
func (c *controller) GetTotalObjectCount(ctx context.Context, clnt client.Client) (int, error) {

pkg/controllers/reconciler.go

Lines changed: 15 additions & 1 deletion
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

@@ -167,14 +169,26 @@ func (r *reconciler) createObjects(ctx context.Context,
167169
return result, nil
168170
}
169171

170-
func UpgradeImages(image *string, initimage *string) (upgrade bool) {
172+
func UpgradeImages(ctx context.Context, image *string, initimage *string) (upgrade bool) {
171173
for _, s := range []*string{image, initimage} {
172174
if s == nil {
173175
continue
174176
}
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+
log.FromContext(ctx).Info("env var for the image: " + name + " is already set; user input of the image is ignored")
185+
186+
*s = envVarValue
187+
upgrade = true
188+
189+
continue
190+
}
191+
178192
if ver, err := versionutil.ParseSemantic(version); err == nil && ver.LessThan(ImageMinVersion) {
179193
*s = name + ":" + ImageMinVersion.String()
180194
upgrade = true

pkg/controllers/reconciler_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package controllers
1616

1717
import (
18+
"context"
1819
"testing"
1920
)
2021

@@ -63,7 +64,7 @@ func TestUpgrade(test *testing.T) {
6364
for i := range tests {
6465
t := tests[i]
6566

66-
upgrade := UpgradeImages(&t.image, &t.initimage)
67+
upgrade := UpgradeImages(context.Background(), &t.image, &t.initimage)
6768

6869
if !(upgrade == t.upgrade && t.image == t.expectedImage && t.initimage == t.expectedInitimage) {
6970
test.Errorf("expectedUpgrade: %v, received: %v", t.upgrade, upgrade)

pkg/controllers/sgx/controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ type controller struct {
6464

6565
func (c *controller) Upgrade(ctx context.Context, obj client.Object) bool {
6666
dp := obj.(*devicepluginv1.SgxDevicePlugin)
67-
return controllers.UpgradeImages(&dp.Spec.Image, &dp.Spec.InitImage)
67+
return controllers.UpgradeImages(ctx, &dp.Spec.Image, &dp.Spec.InitImage)
6868
}
6969

7070
func (c *controller) CreateEmptyObject() client.Object {

0 commit comments

Comments
 (0)