Skip to content

Commit

Permalink
Sort built-in Namespace kind before CRDs with the same name (#5458)
Browse files Browse the repository at this point in the history
* add core api sort priority for NAmespace kind in gvkLessThan

* fix logic

* fix syntax

* fix syntax

* fix logic

* regenerate builtin plugins
  • Loading branch information
danielwilsonkainos authored Sep 3, 2024
1 parent 27d508f commit b7cdd91
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions api/internal/builtins/SortOrderTransformer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions api/types/kustomization.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const (
MetadataNamespacePath = "metadata/namespace"
MetadataNamespaceApiVersion = "v1"
MetadataNamePath = "metadata/name"
NamespaceKind = "Namespace"

OriginAnnotations = "originAnnotations"
TransformerAnnotations = "transformerAnnotations"
Expand Down
3 changes: 3 additions & 0 deletions plugin/builtin/sortordertransformer/SortOrderTransformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ func gvkLessThan(gvk1, gvk2 resid.Gvk, typeOrders map[string]int) bool {
if index1 != index2 {
return index1 < index2
}
if (gvk1.Kind == types.NamespaceKind && gvk2.Kind == types.NamespaceKind) && (gvk1.Group == "" || gvk2.Group == "") {
return legacyGVKSortString(gvk1) > legacyGVKSortString(gvk2)
}
return legacyGVKSortString(gvk1) < legacyGVKSortString(gvk2)
}

Expand Down
24 changes: 24 additions & 0 deletions plugin/builtin/sortordertransformer/SortOrderTransformer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ kind: Namespace
metadata:
name: apple
---
apiVersion: servicebus.azure.com/v1api20210101preview
kind: Namespace
metadata:
name: aso-namespace
namespace: default
---
apiVersion: v1
kind: Secret
metadata:
Expand Down Expand Up @@ -108,6 +114,12 @@ kind: Namespace
metadata:
name: apple
---
apiVersion: servicebus.azure.com/v1api20210101preview
kind: Namespace
metadata:
name: aso-namespace
namespace: default
---
apiVersion: v1
kind: Role
metadata:
Expand Down Expand Up @@ -228,6 +240,12 @@ kind: Namespace
metadata:
name: apple
---
apiVersion: servicebus.azure.com/v1api20210101preview
kind: Namespace
metadata:
name: aso-namespace
namespace: default
---
apiVersion: v1
kind: Deployment
metadata:
Expand Down Expand Up @@ -306,6 +324,12 @@ kind: Namespace
metadata:
name: apple
---
apiVersion: servicebus.azure.com/v1api20210101preview
kind: Namespace
metadata:
name: aso-namespace
namespace: default
---
apiVersion: v1
kind: Deployment
metadata:
Expand Down

0 comments on commit b7cdd91

Please sign in to comment.