mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-13 01:50:55 +00:00
Special treatment for core apiVersions.
This commit is contained in:
@@ -302,8 +302,6 @@ kind: Bar
|
|||||||
expected: `
|
expected: `
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Bar
|
kind: Bar
|
||||||
a:
|
|
||||||
b: e
|
|
||||||
`,
|
`,
|
||||||
filter: fsslice.Filter{
|
filter: fsslice.Filter{
|
||||||
SetValue: fsslice.SetScalar("e"),
|
SetValue: fsslice.SetScalar("e"),
|
||||||
@@ -326,6 +324,8 @@ kind: Bar
|
|||||||
expected: `
|
expected: `
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Bar
|
kind: Bar
|
||||||
|
a:
|
||||||
|
b: e
|
||||||
`,
|
`,
|
||||||
filter: fsslice.Filter{
|
filter: fsslice.Filter{
|
||||||
SetValue: fsslice.SetScalar("e"),
|
SetValue: fsslice.SetScalar("e"),
|
||||||
|
|||||||
@@ -9,6 +9,18 @@ import (
|
|||||||
"sigs.k8s.io/kustomize/kyaml/yaml"
|
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Return true for 'v' followed by a 1 or 2, and don't look at rest.
|
||||||
|
// I.e. 'v1', 'v1beta1', 'v2', would return true.
|
||||||
|
func looksLikeACoreApiVersion(s string) bool {
|
||||||
|
if len(s) < 2 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if s[0:1] != "v" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return s[1:2] == "1" || s[1:2] == "2"
|
||||||
|
}
|
||||||
|
|
||||||
// parseGV parses apiVersion field into group and version.
|
// parseGV parses apiVersion field into group and version.
|
||||||
func parseGV(apiVersion string) (group, version string) {
|
func parseGV(apiVersion string) (group, version string) {
|
||||||
// parse the group and version from the apiVersion field
|
// parse the group and version from the apiVersion field
|
||||||
@@ -17,12 +29,12 @@ func parseGV(apiVersion string) (group, version string) {
|
|||||||
if len(parts) > 1 {
|
if len(parts) > 1 {
|
||||||
version = parts[1]
|
version = parts[1]
|
||||||
}
|
}
|
||||||
// TODO: Special case the original "apiVersion" of what
|
// Special case the original "apiVersion" of what
|
||||||
// we now call the "core" (empty) group.
|
// we now call the "core" (empty) group.
|
||||||
//if group == "v1" && version == "" {
|
if version == "" && looksLikeACoreApiVersion(group) {
|
||||||
// version = "v1"
|
version = group
|
||||||
// group = ""
|
group = ""
|
||||||
//}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,18 +44,18 @@ func TestParseGV(t *testing.T) {
|
|||||||
},
|
},
|
||||||
"coreV1": {
|
"coreV1": {
|
||||||
input: "v1",
|
input: "v1",
|
||||||
expectedGroup: "v1",
|
expectedGroup: "",
|
||||||
expectedVersion: "",
|
expectedVersion: "v1",
|
||||||
},
|
},
|
||||||
"coreV2": {
|
"coreV2": {
|
||||||
input: "v2",
|
input: "v2",
|
||||||
expectedGroup: "v2",
|
expectedGroup: "",
|
||||||
expectedVersion: "",
|
expectedVersion: "v2",
|
||||||
},
|
},
|
||||||
"coreV2Beta1": {
|
"coreV2Beta1": {
|
||||||
input: "v2beta1",
|
input: "v2beta1",
|
||||||
expectedGroup: "v2beta1",
|
expectedGroup: "",
|
||||||
expectedVersion: "",
|
expectedVersion: "v2beta1",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,12 +103,6 @@ apiVersion: apps/v1
|
|||||||
`,
|
`,
|
||||||
expected: resid.Gvk{Group: "apps", Version: "v1", Kind: ""},
|
expected: resid.Gvk{Group: "apps", Version: "v1", Kind: ""},
|
||||||
},
|
},
|
||||||
// When apiVersion is just "v1" (not, say, "apps/v1"), that
|
|
||||||
// could be interpreted as Group="", Version="v1"
|
|
||||||
// (implying the original "core" api group) or the other way around
|
|
||||||
// (Group="v1", Version="").
|
|
||||||
// At the time of writing, fsslice.go does the latter -
|
|
||||||
// might have to change that.
|
|
||||||
"apiVersionOnlyNoSlash1": {
|
"apiVersionOnlyNoSlash1": {
|
||||||
input: `
|
input: `
|
||||||
apiVersion: apps
|
apiVersion: apps
|
||||||
@@ -119,7 +113,7 @@ apiVersion: apps
|
|||||||
input: `
|
input: `
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
`,
|
`,
|
||||||
expected: resid.Gvk{Group: "v1", Version: "", Kind: ""},
|
expected: resid.Gvk{Group: "", Version: "v1", Kind: ""},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -283,7 +283,7 @@ metadata:
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
Gvk: resid.Gvk{
|
Gvk: resid.Gvk{
|
||||||
Group: "v1",
|
Version: "v1",
|
||||||
},
|
},
|
||||||
Path: "a/b",
|
Path: "a/b",
|
||||||
CreateIfNotPresent: true,
|
CreateIfNotPresent: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user