mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 17:12:51 +00:00
Allow setters/substitutions with . in the name
This commit is contained in:
@@ -372,6 +372,41 @@ metadata:
|
|||||||
name: nginx-deployment
|
name: nginx-deployment
|
||||||
spec:
|
spec:
|
||||||
replicas: 3 # {"$openapi":"replicas"}
|
replicas: 3 # {"$openapi":"replicas"}
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "add setter with . in the name",
|
||||||
|
args: []string{"foo.bar", "3"},
|
||||||
|
input: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: nginx-deployment
|
||||||
|
spec:
|
||||||
|
replicas: 3
|
||||||
|
`,
|
||||||
|
inputOpenAPI: `
|
||||||
|
apiVersion: v1alpha1
|
||||||
|
kind: Example
|
||||||
|
`,
|
||||||
|
expectedOpenAPI: `
|
||||||
|
apiVersion: v1alpha1
|
||||||
|
kind: Example
|
||||||
|
openAPI:
|
||||||
|
definitions:
|
||||||
|
io.k8s.cli.setters.foo.bar:
|
||||||
|
x-k8s-cli:
|
||||||
|
setter:
|
||||||
|
name: foo.bar
|
||||||
|
value: "3"
|
||||||
|
`,
|
||||||
|
expectedResources: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: nginx-deployment
|
||||||
|
spec:
|
||||||
|
replicas: 3 # {"$openapi":"foo.bar"}
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -155,8 +155,18 @@ func (fm *FieldMeta) Write(n *yaml.RNode) error {
|
|||||||
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
|
||||||
arr := strings.Split(fm.Schema.Ref.String(), ".")
|
ref := fm.Schema.Ref.String()
|
||||||
n.YNode().LineComment = fmt.Sprintf(`{"%s":"%s"}`, shortHandRef, arr[len(arr)-1])
|
var shortHandRefValue string
|
||||||
|
switch {
|
||||||
|
case strings.HasPrefix(ref, DefinitionsPrefix+SetterDefinitionPrefix):
|
||||||
|
shortHandRefValue = strings.TrimPrefix(ref, DefinitionsPrefix+SetterDefinitionPrefix)
|
||||||
|
case strings.HasPrefix(ref, DefinitionsPrefix+SubstitutionDefinitionPrefix):
|
||||||
|
shortHandRefValue = strings.TrimPrefix(ref, DefinitionsPrefix+SubstitutionDefinitionPrefix)
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("unexpected ref format: %s", ref)
|
||||||
|
}
|
||||||
|
n.YNode().LineComment = fmt.Sprintf(`{"%s":"%s"}`, shortHandRef,
|
||||||
|
shortHandRefValue)
|
||||||
} else {
|
} else {
|
||||||
n.YNode().LineComment = ""
|
n.YNode().LineComment = ""
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -303,7 +303,7 @@ metadata:
|
|||||||
//
|
//
|
||||||
//
|
//
|
||||||
{
|
{
|
||||||
name: "windows_line_ending",
|
name: "windows_line_ending",
|
||||||
input: "\r\n---\r\na: b # first resource\r\nc: d\r\n---\r\n# second resource\r\ne: f\r\ng:\r\n- h\r\n---\r\n\r\n---\r\n i: j",
|
input: "\r\n---\r\na: b # first resource\r\nc: d\r\n---\r\n# second resource\r\ne: f\r\ng:\r\n- h\r\n---\r\n\r\n---\r\n i: j",
|
||||||
expectedItems: []string{
|
expectedItems: []string{
|
||||||
`a: b # first resource
|
`a: b # first resource
|
||||||
|
|||||||
@@ -169,6 +169,29 @@ metadata:
|
|||||||
name: nginx-deployment
|
name: nginx-deployment
|
||||||
spec:
|
spec:
|
||||||
replicas: 3
|
replicas: 3
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "ref has . in name of setter",
|
||||||
|
add: Add{
|
||||||
|
FieldValue: "3",
|
||||||
|
Ref: "#/definitions/io.k8s.cli.setters.foo.bar",
|
||||||
|
},
|
||||||
|
input: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: nginx-deployment
|
||||||
|
spec:
|
||||||
|
replicas: 3
|
||||||
|
`,
|
||||||
|
expected: `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: nginx-deployment
|
||||||
|
spec:
|
||||||
|
replicas: 3 # {"$openapi":"foo.bar"}
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user