mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-17 18:25:26 +00:00
Fix regression 4388
This commit is contained in:
@@ -19,6 +19,7 @@ type PrefixTransformerPlugin struct {
|
||||
FieldSpecs types.FsSlice `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
|
||||
}
|
||||
|
||||
// TODO: Make this gvk skip list part of the config.
|
||||
var prefixFieldSpecsToSkip = types.FsSlice{
|
||||
{Gvk: resid.Gvk{Kind: "CustomResourceDefinition"}},
|
||||
{Gvk: resid.Gvk{Group: "apiregistration.k8s.io", Kind: "APIService"}},
|
||||
|
||||
@@ -19,6 +19,7 @@ type SuffixTransformerPlugin struct {
|
||||
FieldSpecs types.FsSlice `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
|
||||
}
|
||||
|
||||
// TODO: Make this gvk skip list part of the config.
|
||||
var suffixFieldSpecsToSkip = types.FsSlice{
|
||||
{Gvk: resid.Gvk{Kind: "CustomResourceDefinition"}},
|
||||
{Gvk: resid.Gvk{Group: "apiregistration.k8s.io", Kind: "APIService"}},
|
||||
|
||||
62
api/krusty/legacy_order_test.go
Normal file
62
api/krusty/legacy_order_test.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package krusty_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
|
||||
)
|
||||
|
||||
func TestIssue4388(t *testing.T) {
|
||||
th := kusttest_test.MakeHarness(t)
|
||||
th.WriteK(".", `
|
||||
resources:
|
||||
- resources.yaml
|
||||
`)
|
||||
th.WriteF("resources.yaml", `
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: testing
|
||||
data:
|
||||
key: value
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: testing-one
|
||||
data:
|
||||
key: value
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: testing-two
|
||||
data:
|
||||
key: value
|
||||
`)
|
||||
opts := th.MakeDefaultOptions()
|
||||
opts.DoLegacyResourceSort = true
|
||||
m := th.Run(".", opts)
|
||||
th.AssertActualEqualsExpected(m, `
|
||||
apiVersion: v1
|
||||
data:
|
||||
key: value
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: testing
|
||||
---
|
||||
apiVersion: v1
|
||||
data:
|
||||
key: value
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: testing-one
|
||||
---
|
||||
apiVersion: v1
|
||||
data:
|
||||
key: value
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: testing-two
|
||||
`)
|
||||
}
|
||||
@@ -33,5 +33,5 @@ func (a IdSlice) Less(i, j int) bool {
|
||||
if !a[i].Gvk.Equals(a[j].Gvk) {
|
||||
return a[i].Gvk.IsLessThan(a[j].Gvk)
|
||||
}
|
||||
return a[i].String() < a[j].String()
|
||||
return a[i].LegacySortString() < a[j].LegacySortString()
|
||||
}
|
||||
|
||||
@@ -97,6 +97,29 @@ func (x Gvk) String() string {
|
||||
return strings.Join([]string{k, v, g}, fieldSep)
|
||||
}
|
||||
|
||||
// legacySortString returns an older version of String() that LegacyOrderTransformer depends on
|
||||
// to keep its ordering stable across Kustomize versions
|
||||
func (x Gvk) legacySortString() string {
|
||||
legacyNoGroup := "~G"
|
||||
legacyNoVersion := "~V"
|
||||
legacyNoKind := "~K"
|
||||
legacyFieldSeparator := "_"
|
||||
|
||||
g := x.Group
|
||||
if g == "" {
|
||||
g = legacyNoGroup
|
||||
}
|
||||
v := x.Version
|
||||
if v == "" {
|
||||
v = legacyNoVersion
|
||||
}
|
||||
k := x.Kind
|
||||
if k == "" {
|
||||
k = legacyNoKind
|
||||
}
|
||||
return strings.Join([]string{g, v, k}, legacyFieldSeparator)
|
||||
}
|
||||
|
||||
// ApiVersion returns the combination of Group and Version
|
||||
func (x Gvk) ApiVersion() string {
|
||||
var sb strings.Builder
|
||||
@@ -180,7 +203,7 @@ func (x Gvk) IsLessThan(o Gvk) bool {
|
||||
if indexI != indexJ {
|
||||
return indexI < indexJ
|
||||
}
|
||||
return x.String() < o.String()
|
||||
return x.legacySortString() < o.legacySortString()
|
||||
}
|
||||
|
||||
// IsSelected returns true if `selector` selects `x`; otherwise, false.
|
||||
|
||||
@@ -47,8 +47,8 @@ var lessThanTests = []struct {
|
||||
Gvk{Group: "a", Version: "c", Kind: "ClusterRole"}},
|
||||
{Gvk{Group: "a", Version: "c", Kind: "Namespace"},
|
||||
Gvk{Group: "a", Version: "b", Kind: "ClusterRole"}},
|
||||
{Gvk{Group: "b", Version: "c", Kind: "Namespace"},
|
||||
Gvk{Group: "a", Version: "d", Kind: "Namespace"}},
|
||||
{Gvk{Group: "a", Version: "d", Kind: "Namespace"},
|
||||
Gvk{Group: "b", Version: "c", Kind: "Namespace"}},
|
||||
{Gvk{Group: "a", Version: "b", Kind: orderFirst[len(orderFirst)-1]},
|
||||
Gvk{Group: "a", Version: "b", Kind: orderLast[0]}},
|
||||
{Gvk{Group: "a", Version: "b", Kind: orderFirst[len(orderFirst)-1]},
|
||||
|
||||
@@ -60,6 +60,25 @@ func (id ResId) String() string {
|
||||
[]string{id.Gvk.String(), strings.Join([]string{nm, ns}, fieldSep)}, separator)
|
||||
}
|
||||
|
||||
// LegacySortString returns an older version of String() that LegacyOrderTransformer depends on
|
||||
// to keep its ordering stable across Kustomize versions
|
||||
func (id ResId) LegacySortString() string {
|
||||
legacyNoNamespace := "~X"
|
||||
legacyNoName := "~N"
|
||||
legacySeparator := "|"
|
||||
|
||||
ns := id.Namespace
|
||||
if ns == "" {
|
||||
ns = legacyNoNamespace
|
||||
}
|
||||
nm := id.Name
|
||||
if nm == "" {
|
||||
nm = legacyNoName
|
||||
}
|
||||
return strings.Join(
|
||||
[]string{id.Gvk.String(), ns, nm}, legacySeparator)
|
||||
}
|
||||
|
||||
func FromString(s string) ResId {
|
||||
values := strings.Split(s, separator)
|
||||
gvk := GvkFromString(values[0])
|
||||
|
||||
Reference in New Issue
Block a user