mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 01:14:22 +00:00
Fix V1 setters
This commit is contained in:
@@ -941,6 +941,70 @@ spec:
|
|||||||
`,
|
`,
|
||||||
errMsg: "cyclic substitution detected with name my-nested-subst",
|
errMsg: "cyclic substitution detected with name my-nested-subst",
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
name: "set v1 setter asm",
|
||||||
|
args: []string{"profilesetter", "my-asm"},
|
||||||
|
out: "set 1 fields\n",
|
||||||
|
inputOpenAPI: `
|
||||||
|
`,
|
||||||
|
input: `
|
||||||
|
apiVersion: install.istio.io/v1alpha2
|
||||||
|
kind: IstioControlPlane
|
||||||
|
metadata:
|
||||||
|
clusterName: "project-id/us-east1-d/cluster-name"
|
||||||
|
spec:
|
||||||
|
profile: asm # {"type":"string","x-kustomize":{"setter":{"name":"profilesetter","value":"asm"}}}
|
||||||
|
hub:
|
||||||
|
- --gcr.io/asm-testing
|
||||||
|
- --gcr.io/asm-testing2
|
||||||
|
`,
|
||||||
|
expectedOpenAPI: `
|
||||||
|
`,
|
||||||
|
expectedResources: `
|
||||||
|
apiVersion: install.istio.io/v1alpha2
|
||||||
|
kind: IstioControlPlane
|
||||||
|
metadata:
|
||||||
|
clusterName: "project-id/us-east1-d/cluster-name"
|
||||||
|
spec:
|
||||||
|
profile: my-asm # {"type":"string","x-kustomize":{"setter":{"name":"profilesetter","value":"my-asm"}}}
|
||||||
|
hub:
|
||||||
|
- --gcr.io/asm-testing
|
||||||
|
- --gcr.io/asm-testing2
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
name: "set v1 partial setter",
|
||||||
|
args: []string{"gcloud.core.project", "my-project"},
|
||||||
|
out: "set 1 fields\n",
|
||||||
|
inputOpenAPI: `
|
||||||
|
`,
|
||||||
|
input: `
|
||||||
|
apiVersion: install.istio.io/v1alpha2
|
||||||
|
kind: IstioControlPlane
|
||||||
|
metadata:
|
||||||
|
clusterName: "project-id/us-east1-d/cluster-name" # {"type":"string","x-kustomize":{"partialSetters":[{"name":"gcloud.core.project","value":"project-id"},{"name":"cluster-name","value":"cluster-name"},{"name":"gcloud.compute.zone","value":"us-east1-d"}]}}
|
||||||
|
spec:
|
||||||
|
profile: asm # {"type":"string","x-kustomize":{"setter":{"name":"profilesetter","value":"asm"}}}
|
||||||
|
hub:
|
||||||
|
- --gcr.io/asm-testing
|
||||||
|
- --gcr.io/asm-testing2
|
||||||
|
`,
|
||||||
|
expectedOpenAPI: `
|
||||||
|
`,
|
||||||
|
expectedResources: `
|
||||||
|
apiVersion: install.istio.io/v1alpha2
|
||||||
|
kind: IstioControlPlane
|
||||||
|
metadata:
|
||||||
|
clusterName: "my-project/us-east1-d/cluster-name" # {"type":"string","x-kustomize":{"partialSetters":[{"name":"gcloud.core.project","value":"my-project"},{"name":"cluster-name","value":"cluster-name"},{"name":"gcloud.compute.zone","value":"us-east1-d"}]}}
|
||||||
|
spec:
|
||||||
|
profile: asm # {"type":"string","x-kustomize":{"setter":{"name":"profilesetter","value":"asm"}}}
|
||||||
|
hub:
|
||||||
|
- --gcr.io/asm-testing
|
||||||
|
- --gcr.io/asm-testing2
|
||||||
|
`,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for i := range tests {
|
for i := range tests {
|
||||||
test := tests[i]
|
test := tests[i]
|
||||||
|
|||||||
@@ -146,15 +146,13 @@ func isExtensionEmpty(x XKustomize) bool {
|
|||||||
// Write writes the FieldMeta to a node
|
// Write writes the FieldMeta to a node
|
||||||
func (fm *FieldMeta) Write(n *yaml.RNode) error {
|
func (fm *FieldMeta) Write(n *yaml.RNode) error {
|
||||||
if !isExtensionEmpty(fm.Extensions) {
|
if !isExtensionEmpty(fm.Extensions) {
|
||||||
fm.Schema.VendorExtensible.AddExtension("x-kustomize", fm.Extensions)
|
return fm.WriteV1Setters(n)
|
||||||
} else {
|
|
||||||
delete(fm.Schema.VendorExtensible.Extensions, "x-kustomize")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ref is removed when a setter is deleted, so the Ref string could be empty.
|
// Ref is removed when a setter is deleted, so the Ref string could be empty.
|
||||||
if fm.Schema.Ref.String() != "" {
|
if fm.Schema.Ref.String() != "" {
|
||||||
// Ex: {"$ref":"#/definitions/io.k8s.cli.setters.replicas"} should be converted to
|
// Ex: {"$ref":"#/definitions/io.k8s.cli.setters.replicas"} should be converted to
|
||||||
// {"openAPI":"replicas"} and added to the line comment
|
// {"$openAPI":"replicas"} and added to the line comment
|
||||||
ref := fm.Schema.Ref.String()
|
ref := fm.Schema.Ref.String()
|
||||||
var shortHandRefValue string
|
var shortHandRefValue string
|
||||||
switch {
|
switch {
|
||||||
@@ -174,6 +172,18 @@ func (fm *FieldMeta) Write(n *yaml.RNode) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WriteV1Setters is the v1 setters way of writing setter definitions
|
||||||
|
// TODO: pmarupaka - remove this method after migration
|
||||||
|
func (fm *FieldMeta) WriteV1Setters(n *yaml.RNode) error {
|
||||||
|
fm.Schema.VendorExtensible.AddExtension("x-kustomize", fm.Extensions)
|
||||||
|
b, err := json.Marshal(fm.Schema)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err)
|
||||||
|
}
|
||||||
|
n.YNode().LineComment = string(b)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// FieldValueType defines the type of input to register
|
// FieldValueType defines the type of input to register
|
||||||
type FieldValueType string
|
type FieldValueType string
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user