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

Correct order of hash sum calculation for pod refresh #15

Merged
merged 7 commits into from
Aug 1, 2024
8 changes: 4 additions & 4 deletions controllers/spec_preprocessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,6 @@ func (r *BackstageReconciler) addExtConfig(config *model.ExternalConfig, ctx con
return fmt.Errorf("failed to get external config from %s: %s", objectName, err)
}

if err := config.AddToSyncedConfig(obj); err != nil {
return fmt.Errorf("failed to add to synced %s: %s", obj.GetName(), err)
}

if obj.GetLabels() == nil {
obj.SetLabels(map[string]string{})
}
Expand All @@ -184,6 +180,10 @@ func (r *BackstageReconciler) addExtConfig(config *model.ExternalConfig, ctx con
lg.V(1).Info(fmt.Sprintf("update external config %s with label %s=%s and annotation %s=%s", obj.GetName(), model.ExtConfigSyncLabel, strconv.FormatBool(autoSync), model.BackstageNameAnnotation, backstageName))
}

if err := config.AddToSyncedConfig(obj); err != nil {
return fmt.Errorf("failed to add to synced %s: %s", obj.GetName(), err)
}

return nil

})
Expand Down
35 changes: 12 additions & 23 deletions pkg/model/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"fmt"
"os"
"reflect"
"sort"
"slices"

corev1 "k8s.io/api/core/v1"

Expand Down Expand Up @@ -74,29 +74,18 @@ func (m *BackstageModel) setRuntimeObject(object RuntimeObject) {
m.RuntimeObjects = append(m.RuntimeObjects, object)
}

// sort objects so DbStatefulSet and BackstageDeployment become the last in the list
func (m *BackstageModel) sortRuntimeObjects() {
// works with Go 1.18+
sort.Slice(m.RuntimeObjects, func(i, j int) bool {
_, ok1 := m.RuntimeObjects[i].(*DbStatefulSet)
_, ok2 := m.RuntimeObjects[j].(*BackstageDeployment)
if ok1 || ok2 {
return false
}
return true

})

// this does not work for Go 1.20
// so image-build fails
//slices.SortFunc(m.RuntimeObjects,
// func(a, b RuntimeObject) int {
// _, ok1 := b.(*DbStatefulSet)
// _, ok2 := b.(*BackstageDeployment)
// if ok1 || ok2 {
// return -1
// }
// return 1
// })

slices.SortFunc(m.RuntimeObjects,
func(a, b RuntimeObject) int {
_, ok1 := b.(*DbStatefulSet)
_, ok2 := b.(*BackstageDeployment)
if ok1 || ok2 {
return -1
}
return 1
})
}

// Registers config object
Expand Down