Skip to content

Commit d2279d1

Browse files
authored
Merge pull request #1865 from hj-johannes-lee/PR-2024-010
operator: fix upgradeImages
2 parents f31ff37 + 6915c7d commit d2279d1

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

pkg/controllers/reconciler.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,13 @@ func UpgradeImages(ctx context.Context, image *string, initimage *string) (upgra
158158
if s == nil {
159159
continue
160160
}
161-
161+
// e.g. intel-dsa-plugin@sha256:hash -> [intel-dsa-plugin@sha256, hash]
162162
if parts := strings.SplitN(*s, ":", 2); len(parts) == 2 && len(parts[0]) > 0 {
163-
name, version := parts[0], parts[1]
163+
// e.g. [intel-dsa-plugin@sha256, hash] -> [intel-dsa-plugin, hash]
164+
name, version := strings.TrimSuffix(parts[0], "@sha256"), parts[1]
164165

166+
// e.g. intel-dsa-plugin -> INTEL_DSA_PLUGIN_SHA
167+
// and get the value of the env var INTEL_DSA_PLUGIN_SHA
165168
envVarValue := os.Getenv(strings.ReplaceAll(strings.ToUpper(filepath.Base(name)), "-", "_") + "_SHA")
166169

167170
if envVarValue != "" && *s != envVarValue {

pkg/controllers/reconciler_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package controllers
1616

1717
import (
1818
"context"
19+
"os"
1920
"testing"
2021

2122
v1 "k8s.io/api/core/v1"
@@ -27,6 +28,7 @@ func TestUpgrade(test *testing.T) {
2728
version := ":" + ImageMinVersion.String()
2829
prevVersion := ":" + ImageMinVersion.WithMinor(ImageMinVersion.Minor()-1).String()
2930
tests := []struct {
31+
envVars map[string]string
3032
image string
3133
initimage string
3234
expectedImage string
@@ -61,18 +63,48 @@ func TestUpgrade(test *testing.T) {
6163
expectedInitimage: initimage,
6264
upgrade: false,
6365
},
66+
{
67+
envVars: map[string]string{
68+
"INTEL_DSA_PLUGIN_SHA": "intel/intel-dsa-plugin@sha256:000000000000000000000000000000000000000000000000000000000000000b",
69+
"INTEL_IDXD_CONFIG_INITCONTAINER_SHA": "intel/intel-idxd-config-initcontainer@sha256:000000000000000000000000000000000000000000000000000000000000000b",
70+
},
71+
image: image + "@sha256:000000000000000000000000000000000000000000000000000000000000000a",
72+
expectedImage: image + "@sha256:000000000000000000000000000000000000000000000000000000000000000b",
73+
initimage: initimage + "@sha256:000000000000000000000000000000000000000000000000000000000000000a",
74+
expectedInitimage: initimage + "@sha256:000000000000000000000000000000000000000000000000000000000000000b",
75+
upgrade: true,
76+
},
77+
{
78+
envVars: map[string]string{
79+
"INTEL_DSA_PLUGIN_SHA": "intel/intel-dsa-plugin@sha256:000000000000000000000000000000000000000000000000000000000000000a",
80+
"INTEL_IDXD_CONFIG_INITCONTAINER_SHA": "intel/intel-idxd-config-initcontainer@sha256:000000000000000000000000000000000000000000000000000000000000000a",
81+
},
82+
image: image + "@sha256:000000000000000000000000000000000000000000000000000000000000000a",
83+
expectedImage: image + "@sha256:000000000000000000000000000000000000000000000000000000000000000a",
84+
initimage: initimage + "@sha256:000000000000000000000000000000000000000000000000000000000000000a",
85+
expectedInitimage: initimage + "@sha256:000000000000000000000000000000000000000000000000000000000000000a",
86+
upgrade: false,
87+
},
6488
}
6589

6690
for i := range tests {
6791
t := tests[i]
6892

93+
for key, value := range t.envVars {
94+
os.Setenv(key, value)
95+
}
96+
6997
upgrade := UpgradeImages(context.Background(), &t.image, &t.initimage)
7098

7199
if !(upgrade == t.upgrade && t.image == t.expectedImage && t.initimage == t.expectedInitimage) {
72100
test.Errorf("expectedUpgrade: %v, received: %v", t.upgrade, upgrade)
73101
test.Errorf("expectedImage: %s, received: %s", t.expectedImage, t.image)
74102
test.Errorf("expectedInitimage: %s, received: %s", t.expectedInitimage, t.initimage)
75103
}
104+
105+
for key := range t.envVars {
106+
os.Unsetenv(key)
107+
}
76108
}
77109
}
78110

0 commit comments

Comments
 (0)