Skip to content
This repository has been archived by the owner on Sep 20, 2022. It is now read-only.

Prevent spurious configuration saves #56

Merged
merged 2 commits into from
May 11, 2020
Merged
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
25 changes: 22 additions & 3 deletions internal/configmanager/configmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package configmanager
import (
"context"
"fmt"
"sort"
"sync"
"time"

Expand Down Expand Up @@ -143,9 +144,27 @@ func (c *ConfigManager) GetCurrentConfig() (options pomeriumconfig.Options, err
return options, fmt.Errorf("could not load base configuration: %w", err)
}

// Attach policies
for _, policy := range c.policyList {
options.Policies = append(options.Policies, policy...)
// Sort identifiers to return a consistent policy
var policyIds []ResourceIdentifier
for id := range c.policyList {
policyIds = append(policyIds, id)
}

sort.Slice(policyIds, func(i, j int) bool {

switch {
case policyIds[i].NamespacedName.String() < policyIds[j].NamespacedName.String():
return true
case policyIds[i].NamespacedName.String() > policyIds[j].NamespacedName.String():
return false

}
return policyIds[i].GVK.String() < policyIds[j].GVK.String()
})
calebdoxsey marked this conversation as resolved.
Show resolved Hide resolved

// Append policies in order
for _, id := range policyIds {
options.Policies = append(options.Policies, c.policyList[id]...)
}

return
Expand Down