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

Commit

Permalink
Ensure consistent ordering of policy (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
travisgroth authored May 11, 2020
1 parent 96be7fe commit 3b4586e
Showing 1 changed file with 22 additions and 3 deletions.
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()
})

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

return
Expand Down

0 comments on commit 3b4586e

Please sign in to comment.