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
Browse files Browse the repository at this point in the history
  • Loading branch information
travisgroth committed May 8, 2020
1 parent ce64e7a commit 0018dd8
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 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,21 @@ 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 {

return (policyIds[i].NamespacedName.String() < policyIds[j].NamespacedName.String() ||
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 0018dd8

Please sign in to comment.