Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions pkg/controllers/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,13 @@ func UpgradeImages(ctx context.Context, image *string, initimage *string) (upgra
if s == nil {
continue
}

// e.g. intel-dsa-plugin@sha256:hash -> [intel-dsa-plugin@sha256, hash]
if parts := strings.SplitN(*s, ":", 2); len(parts) == 2 && len(parts[0]) > 0 {
name, version := parts[0], parts[1]
// e.g. [intel-dsa-plugin@sha256, hash] -> [intel-dsa-plugin, hash]
name, version := strings.TrimSuffix(parts[0], "@sha256"), parts[1]

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

if envVarValue != "" && *s != envVarValue {
Expand Down
32 changes: 32 additions & 0 deletions pkg/controllers/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package controllers

import (
"context"
"os"
"testing"

v1 "k8s.io/api/core/v1"
Expand All @@ -27,6 +28,7 @@ func TestUpgrade(test *testing.T) {
version := ":" + ImageMinVersion.String()
prevVersion := ":" + ImageMinVersion.WithMinor(ImageMinVersion.Minor()-1).String()
tests := []struct {
envVars map[string]string
image string
initimage string
expectedImage string
Expand Down Expand Up @@ -61,18 +63,48 @@ func TestUpgrade(test *testing.T) {
expectedInitimage: initimage,
upgrade: false,
},
{
envVars: map[string]string{
"INTEL_DSA_PLUGIN_SHA": "intel/intel-dsa-plugin@sha256:000000000000000000000000000000000000000000000000000000000000000b",
"INTEL_IDXD_CONFIG_INITCONTAINER_SHA": "intel/intel-idxd-config-initcontainer@sha256:000000000000000000000000000000000000000000000000000000000000000b",
},
image: image + "@sha256:000000000000000000000000000000000000000000000000000000000000000a",
expectedImage: image + "@sha256:000000000000000000000000000000000000000000000000000000000000000b",
initimage: initimage + "@sha256:000000000000000000000000000000000000000000000000000000000000000a",
expectedInitimage: initimage + "@sha256:000000000000000000000000000000000000000000000000000000000000000b",
upgrade: true,
},
{
envVars: map[string]string{
"INTEL_DSA_PLUGIN_SHA": "intel/intel-dsa-plugin@sha256:000000000000000000000000000000000000000000000000000000000000000a",
"INTEL_IDXD_CONFIG_INITCONTAINER_SHA": "intel/intel-idxd-config-initcontainer@sha256:000000000000000000000000000000000000000000000000000000000000000a",
},
image: image + "@sha256:000000000000000000000000000000000000000000000000000000000000000a",
expectedImage: image + "@sha256:000000000000000000000000000000000000000000000000000000000000000a",
initimage: initimage + "@sha256:000000000000000000000000000000000000000000000000000000000000000a",
expectedInitimage: initimage + "@sha256:000000000000000000000000000000000000000000000000000000000000000a",
upgrade: false,
},
}

for i := range tests {
t := tests[i]

for key, value := range t.envVars {
os.Setenv(key, value)
}

upgrade := UpgradeImages(context.Background(), &t.image, &t.initimage)

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

for key := range t.envVars {
os.Unsetenv(key)
}
}
}

Expand Down
Loading