mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-07-01 10:20:35 +00:00
setters 2.0: support for adding references to setters
This commit is contained in:
@@ -128,3 +128,75 @@ spec:
|
||||
// - name: nginx
|
||||
// image: nginx:1.8.1 # {"$ref": "#/definitions/io.k8s.cli.substitutions.image"}
|
||||
}
|
||||
|
||||
// ExampleAdd demonstrates adding a setter reference to fields.
|
||||
func ExampleAdd_fieldName() {
|
||||
deployment := `
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: nginx-deployment
|
||||
annotations:
|
||||
something: 3
|
||||
spec:
|
||||
replicas: 3
|
||||
`
|
||||
|
||||
object := yaml.MustParse(deployment) // parse the configuration
|
||||
err := object.PipeE(&Add{
|
||||
Ref: "#/definitions/io.k8s.cli.setters.replicas",
|
||||
FieldName: "replicas",
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Print the object with the update value
|
||||
fmt.Println(object.MustString())
|
||||
|
||||
// Output:
|
||||
// apiVersion: apps/v1
|
||||
// kind: Deployment
|
||||
// metadata:
|
||||
// name: nginx-deployment
|
||||
// annotations:
|
||||
// something: 3
|
||||
// spec:
|
||||
// replicas: 3 # {"$ref":"#/definitions/io.k8s.cli.setters.replicas"}
|
||||
}
|
||||
|
||||
// ExampleAdd demonstrates adding a setter reference to fields.
|
||||
func ExampleAdd_fieldValue() {
|
||||
deployment := `
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: nginx-deployment
|
||||
annotations:
|
||||
something: 3
|
||||
spec:
|
||||
replicas: 3
|
||||
`
|
||||
|
||||
object := yaml.MustParse(deployment) // parse the configuration
|
||||
err := object.PipeE(&Add{
|
||||
Ref: "#/definitions/io.k8s.cli.setters.replicas",
|
||||
FieldValue: "3",
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Print the object with the update value
|
||||
fmt.Println(object.MustString())
|
||||
|
||||
// Output:
|
||||
// apiVersion: apps/v1
|
||||
// kind: Deployment
|
||||
// metadata:
|
||||
// name: nginx-deployment
|
||||
// annotations:
|
||||
// something: 3 # {"$ref":"#/definitions/io.k8s.cli.setters.replicas"}
|
||||
// spec:
|
||||
// replicas: 3 # {"$ref":"#/definitions/io.k8s.cli.setters.replicas"}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user