mirror of
https://github.com/intel/intel-device-plugins-for-kubernetes.git
synced 2025-06-03 03:59:37 +00:00
operator: add ctx to func UpgradeImages and logger for env vars of images
Signed-off-by: Hyeongju Johannes Lee <hyeongju.lee@intel.com>
This commit is contained in:
parent
6a60c745d2
commit
20caa42e7a
@ -68,7 +68,7 @@ func (c *controller) CreateEmptyObject() client.Object {
|
||||
|
||||
func (c *controller) Upgrade(ctx context.Context, obj client.Object) bool {
|
||||
dp := obj.(*devicepluginv1.DlbDevicePlugin)
|
||||
return controllers.UpgradeImages(&dp.Spec.Image, &dp.Spec.InitImage)
|
||||
return controllers.UpgradeImages(ctx, &dp.Spec.Image, &dp.Spec.InitImage)
|
||||
}
|
||||
|
||||
func (c *controller) GetTotalObjectCount(ctx context.Context, clnt client.Client) (int, error) {
|
||||
|
@ -71,7 +71,7 @@ func (c *controller) CreateEmptyObject() client.Object {
|
||||
|
||||
func (c *controller) Upgrade(ctx context.Context, obj client.Object) bool {
|
||||
dp := obj.(*devicepluginv1.DsaDevicePlugin)
|
||||
return controllers.UpgradeImages(&dp.Spec.Image, &dp.Spec.InitImage)
|
||||
return controllers.UpgradeImages(ctx, &dp.Spec.Image, &dp.Spec.InitImage)
|
||||
}
|
||||
|
||||
func (c *controller) GetTotalObjectCount(ctx context.Context, clnt client.Client) (int, error) {
|
||||
|
@ -67,7 +67,7 @@ func (c *controller) CreateEmptyObject() client.Object {
|
||||
|
||||
func (c *controller) Upgrade(ctx context.Context, obj client.Object) bool {
|
||||
dp := obj.(*devicepluginv1.FpgaDevicePlugin)
|
||||
return controllers.UpgradeImages(&dp.Spec.Image, &dp.Spec.InitImage)
|
||||
return controllers.UpgradeImages(ctx, &dp.Spec.Image, &dp.Spec.InitImage)
|
||||
}
|
||||
|
||||
func (c *controller) GetTotalObjectCount(ctx context.Context, clnt client.Client) (int, error) {
|
||||
|
@ -72,7 +72,7 @@ func (c *controller) CreateEmptyObject() client.Object {
|
||||
|
||||
func (c *controller) Upgrade(ctx context.Context, obj client.Object) bool {
|
||||
dp := obj.(*devicepluginv1.GpuDevicePlugin)
|
||||
return controllers.UpgradeImages(&dp.Spec.Image, &dp.Spec.InitImage)
|
||||
return controllers.UpgradeImages(ctx, &dp.Spec.Image, &dp.Spec.InitImage)
|
||||
}
|
||||
|
||||
func (c *controller) GetTotalObjectCount(ctx context.Context, clnt client.Client) (int, error) {
|
||||
|
@ -69,7 +69,7 @@ func (c *controller) CreateEmptyObject() client.Object {
|
||||
|
||||
func (c *controller) Upgrade(ctx context.Context, obj client.Object) bool {
|
||||
dp := obj.(*devicepluginv1.IaaDevicePlugin)
|
||||
return controllers.UpgradeImages(&dp.Spec.Image, &dp.Spec.InitImage)
|
||||
return controllers.UpgradeImages(ctx, &dp.Spec.Image, &dp.Spec.InitImage)
|
||||
}
|
||||
|
||||
func (c *controller) GetTotalObjectCount(ctx context.Context, clnt client.Client) (int, error) {
|
||||
|
@ -72,7 +72,7 @@ func (c *controller) CreateEmptyObject() client.Object {
|
||||
|
||||
func (c *controller) Upgrade(ctx context.Context, obj client.Object) bool {
|
||||
dp := obj.(*devicepluginv1.QatDevicePlugin)
|
||||
return controllers.UpgradeImages(&dp.Spec.Image, &dp.Spec.InitImage)
|
||||
return controllers.UpgradeImages(ctx, &dp.Spec.Image, &dp.Spec.InitImage)
|
||||
}
|
||||
|
||||
func (c *controller) GetTotalObjectCount(ctx context.Context, clnt client.Client) (int, error) {
|
||||
|
@ -169,7 +169,7 @@ func (r *reconciler) createObjects(ctx context.Context,
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func UpgradeImages(image *string, initimage *string) (upgrade bool) {
|
||||
func UpgradeImages(ctx context.Context, image *string, initimage *string) (upgrade bool) {
|
||||
for _, s := range []*string{image, initimage} {
|
||||
if s == nil {
|
||||
continue
|
||||
@ -181,6 +181,8 @@ func UpgradeImages(image *string, initimage *string) (upgrade bool) {
|
||||
envVarValue := os.Getenv(strings.ReplaceAll(strings.ToUpper(filepath.Base(name)), "-", "_") + "_SHA")
|
||||
|
||||
if envVarValue != "" && *s != envVarValue {
|
||||
log.FromContext(ctx).Info("env var for the image: " + name + " is already set; user input of the image is ignored")
|
||||
|
||||
*s = envVarValue
|
||||
upgrade = true
|
||||
|
||||
|
@ -15,6 +15,7 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@ -63,7 +64,7 @@ func TestUpgrade(test *testing.T) {
|
||||
for i := range tests {
|
||||
t := tests[i]
|
||||
|
||||
upgrade := UpgradeImages(&t.image, &t.initimage)
|
||||
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)
|
||||
|
@ -64,7 +64,7 @@ type controller struct {
|
||||
|
||||
func (c *controller) Upgrade(ctx context.Context, obj client.Object) bool {
|
||||
dp := obj.(*devicepluginv1.SgxDevicePlugin)
|
||||
return controllers.UpgradeImages(&dp.Spec.Image, &dp.Spec.InitImage)
|
||||
return controllers.UpgradeImages(ctx, &dp.Spec.Image, &dp.Spec.InitImage)
|
||||
}
|
||||
|
||||
func (c *controller) CreateEmptyObject() client.Object {
|
||||
|
Loading…
Reference in New Issue
Block a user