Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-2.2] Fixing image repo secret extraction for unloading worker pod #931

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
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