Skip to content

Commit

Permalink
Fixing image repo secret extraction for unloading worker pod
Browse files Browse the repository at this point in the history
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
  • Loading branch information
yevgeny-shnaidman authored and k8s-ci-robot committed Nov 13, 2024
1 parent 67241e4 commit 2ef0cb3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 36 deletions.
32 changes: 4 additions & 28 deletions internal/controllers/nmc_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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++ {
Expand Down
9 changes: 1 addition & 8 deletions internal/controllers/nmc_reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 2ef0cb3

Please sign in to comment.