Skip to content

Commit

Permalink
Merge pull request #9311 from kokes/sort_order_naming
Browse files Browse the repository at this point in the history
🌱 adjust naming in SortForCreate implementation
  • Loading branch information
k8s-ci-robot committed Aug 25, 2023
2 parents fd60888 + ff4370b commit a595a0c
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions util/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
)

var priorityMap = map[string]int{
// orderMapping maps resource kinds to their creation order,
// the lower the number, the earlier the resource should be created.
var orderMapping = map[string]int{
// Namespaces go first because all namespaced resources depend on them.
"Namespace": -100,
// Custom Resource Definitions come before Custom Resource so that they can be
Expand Down Expand Up @@ -53,8 +55,8 @@ var priorityMap = map[string]int{
// priorityLess returns true if o1 should be created before o2.
// To be used in sort.{Slice,SliceStable} to sort manifests in place.
func priorityLess(o1, o2 unstructured.Unstructured) bool {
p1 := priorityMap[o1.GetKind()]
p2 := priorityMap[o2.GetKind()]
p1 := orderMapping[o1.GetKind()]
p2 := orderMapping[o2.GetKind()]
return p1 < p2
}

Expand Down

0 comments on commit a595a0c

Please sign in to comment.