Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort built-in Namespace kind before CRDs with the same name #5458

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions api/types/kustomization.go
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
Expand Up @@ -163,6 +163,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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the group name in these tests significant? If not, could we use something more generic (such as group.example.org/v1)?

Same for the namespace name (most resources use fruit names, it would be nice to keep that consistent).

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