From 2ef0cb36f3e1a4597303e5fd963749f6e3f37b02 Mon Sep 17 00:00:00 2001 From: Yevgeny Shnaidman Date: Wed, 13 Nov 2024 15:29:41 +0200 Subject: [PATCH] Fixing image repo secret extraction for unloading worker pod image repo secret wasd previously extracted from the volume that was mapped into the loading pod. Since the volume no longer exists, we must extract it from the imagePullSecret of the loading pod --- internal/controllers/nmc_reconciler.go | 32 +++------------------ internal/controllers/nmc_reconciler_test.go | 9 +----- 2 files changed, 5 insertions(+), 36 deletions(-) diff --git a/internal/controllers/nmc_reconciler.go b/internal/controllers/nmc_reconciler.go index b25ac9556..33d9f170a 100644 --- a/internal/controllers/nmc_reconciler.go +++ b/internal/controllers/nmc_reconciler.go @@ -538,16 +538,9 @@ func (h *nmcReconcilerHelperImpl) SyncStatus(ctx context.Context, nmcObj *kmmv1b continue } - if irsName, err := getImageRepoSecretName(&p); err != nil { - logger.Info( - utils.WarnString("Error while looking for the imageRepoSecret volume"), - "error", - err, - ) - } else if irsName != "" { - status.ImageRepoSecret = &v1.LocalObjectReference{Name: irsName} + if p.Spec.ImagePullSecrets != nil { + status.ImageRepoSecret = &p.Spec.ImagePullSecrets[0] } - status.ServiceAccountName = p.Spec.ServiceAccountName podLTT := GetContainerStatus(p.Status.ContainerStatuses, workerContainerName). @@ -729,9 +722,8 @@ const ( configFileName = "config.yaml" configFullPath = volMountPointConfig + "/" + configFileName - volNameConfig = "config" - volNameImageRepoSecret = "image-repo-secret" - volMountPointConfig = "/etc/kmm-worker" + volNameConfig = "config" + volMountPointConfig = "/etc/kmm-worker" ) //go:generate mockgen -source=nmc_reconciler.go -package=controllers -destination=mock_nmc_reconciler.go podManager @@ -1235,22 +1227,6 @@ func setHashAnnotation(pod *v1.Pod) error { return nil } -func getImageRepoSecretName(pod *v1.Pod) (string, error) { - for _, v := range pod.Spec.Volumes { - if v.Name == volNameImageRepoSecret { - svs := v.VolumeSource.Secret - - if svs == nil { - return "", fmt.Errorf("volume %s is not of type secret", volNameImageRepoSecret) - } - - return svs.SecretName, nil - } - } - - return "", nil -} - func getModulesOrderAnnotationValue(modulesNames []string) string { var softDepData strings.Builder for i := 0; i < len(modulesNames)-1; i++ { diff --git a/internal/controllers/nmc_reconciler_test.go b/internal/controllers/nmc_reconciler_test.go index 95450864c..f32dcfde7 100644 --- a/internal/controllers/nmc_reconciler_test.go +++ b/internal/controllers/nmc_reconciler_test.go @@ -1047,14 +1047,7 @@ var _ = Describe("nmcReconcilerHelperImpl_SyncStatus", func() { }, Spec: v1.PodSpec{ ServiceAccountName: serviceAccountName, - Volumes: []v1.Volume{ - { - Name: volNameImageRepoSecret, - VolumeSource: v1.VolumeSource{ - Secret: &v1.SecretVolumeSource{SecretName: irsName}, - }, - }, - }, + ImagePullSecrets: []v1.LocalObjectReference{v1.LocalObjectReference{Name: irsName}}, }, Status: v1.PodStatus{ Phase: v1.PodSucceeded,