Skip to content

Commit 20caa42

Browse files
operator: add ctx to func UpgradeImages and logger for env vars of images
Signed-off-by: Hyeongju Johannes Lee <[email protected]>
1 parent 6a60c74 commit 20caa42

File tree

9 files changed

+12
-9
lines changed

9 files changed

+12
-9
lines changed

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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ func (r *reconciler) createObjects(ctx context.Context,
169169
return result, nil
170170
}
171171

172-
func UpgradeImages(image *string, initimage *string) (upgrade bool) {
172+
func UpgradeImages(ctx context.Context, image *string, initimage *string) (upgrade bool) {
173173
for _, s := range []*string{image, initimage} {
174174
if s == nil {
175175
continue
@@ -181,6 +181,8 @@ func UpgradeImages(image *string, initimage *string) (upgrade bool) {
181181
envVarValue := os.Getenv(strings.ReplaceAll(strings.ToUpper(filepath.Base(name)), "-", "_") + "_SHA")
182182

183183
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+
184186
*s = envVarValue
185187
upgrade = true
186188

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)