diff --git a/cli/cmd/restore.go b/cli/cmd/restore.go index a07aac1..39b25a4 100644 --- a/cli/cmd/restore.go +++ b/cli/cmd/restore.go @@ -25,11 +25,13 @@ import ( "fmt" "os" "path/filepath" + "sort" cliutils "github.com/softwarefactory-project/sf-operator/cli/cmd/utils" controllers "github.com/softwarefactory-project/sf-operator/controllers" "github.com/spf13/cobra" + "golang.org/x/exp/maps" appsv1 "k8s.io/api/apps/v1" apiv1 "k8s.io/api/core/v1" @@ -47,11 +49,13 @@ func restoreSecret(backupDir string, env cliutils.ENV) { secret := apiv1.Secret{} if cliutils.GetMOrDie(&env, sec, &secret) { secretMap := secretContent["data"].(map[string]interface{}) - for key, value := range secretMap { - stringValue, ok := value.(string) + secretMapKeys := maps.Keys(secretMap) + sort.Strings(secretMapKeys) + for _, key := range secretMapKeys { + stringValue, ok := secretMap[key].(string) if !ok { ctrl.Log.Error(errors.New("can not convert secret data value to string"), - "Can not restore secret"+sec) + "Can not restore secret "+sec) os.Exit(1) } secret.Data[key] = []byte(stringValue) diff --git a/controllers/libs/base/images.go b/controllers/libs/base/images.go index 7a343b4..c0be4a0 100644 --- a/controllers/libs/base/images.go +++ b/controllers/libs/base/images.go @@ -6,7 +6,9 @@ package base import ( _ "embed" + "sort" + "golang.org/x/exp/maps" "gopkg.in/yaml.v2" ) @@ -44,13 +46,19 @@ func getImage(name string) string { } func GetSelfManagedImages() []Image { + imagesByName := make(map[string]Image) ret := []Image{} images := loadImages() for _, image := range images.Images { if image.Source != "" { - ret = append(ret, image) + imagesByName[image.Name] = image } } + imageNames := maps.Keys(imagesByName) + sort.Strings(imageNames) + for _, imageName := range imageNames { + ret = append(ret, imagesByName[imageName]) + } return ret }