Skip to content

Commit

Permalink
Merge "Ensure looping over unmarshalled YAML data is consistent"
Browse files Browse the repository at this point in the history
  • Loading branch information
Microzuul CI authored and Gerrit Code Review committed Sep 4, 2024
2 parents c8a6d71 + 2d51c38 commit cc10794
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 7 additions & 3 deletions cli/cmd/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down
10 changes: 9 additions & 1 deletion controllers/libs/base/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ package base

import (
_ "embed"
"sort"

"golang.org/x/exp/maps"
"gopkg.in/yaml.v2"
)

Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit cc10794

Please sign in to comment.