mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 17:12:51 +00:00
Make isSet a parameter
This commit is contained in:
@@ -163,6 +163,7 @@ func (r *SetRunner) ExecuteCmd(w io.Writer, pkgPath string) error {
|
|||||||
OpenAPIFileName: ext.KRMFileName(),
|
OpenAPIFileName: ext.KRMFileName(),
|
||||||
ResourcesPath: pkgPath,
|
ResourcesPath: pkgPath,
|
||||||
RecurseSubPackages: r.Set.RecurseSubPackages,
|
RecurseSubPackages: r.Set.RecurseSubPackages,
|
||||||
|
IsSet: true,
|
||||||
}
|
}
|
||||||
count, err := r.Set.Set()
|
count, err := r.Set.Set()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -353,6 +353,8 @@ type SetOpenAPI struct {
|
|||||||
Description string `yaml:"description"`
|
Description string `yaml:"description"`
|
||||||
|
|
||||||
SetBy string `yaml:"setBy"`
|
SetBy string `yaml:"setBy"`
|
||||||
|
|
||||||
|
IsSet bool `yaml:"isSet"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateFile updates the OpenAPI definitions in a file with the given setter value.
|
// UpdateFile updates the OpenAPI definitions in a file with the given setter value.
|
||||||
@@ -458,8 +460,10 @@ func (s SetOpenAPI) Filter(object *yaml.RNode) (*yaml.RNode, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := def.PipeE(&yaml.FieldSetter{Name: "isSet", StringValue: "true"}); err != nil {
|
if s.IsSet {
|
||||||
return nil, err
|
if err := def.PipeE(&yaml.FieldSetter{Name: "isSet", StringValue: "true"}); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.Description != "" {
|
if s.Description != "" {
|
||||||
|
|||||||
@@ -971,11 +971,13 @@ func TestSetOpenAPI_Filter(t *testing.T) {
|
|||||||
description string
|
description string
|
||||||
setBy string
|
setBy string
|
||||||
err string
|
err string
|
||||||
|
isSet bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "set-replicas",
|
name: "set-replicas",
|
||||||
setter: "replicas",
|
setter: "replicas",
|
||||||
value: "3",
|
value: "3",
|
||||||
|
isSet: true,
|
||||||
input: `
|
input: `
|
||||||
openAPI:
|
openAPI:
|
||||||
definitions:
|
definitions:
|
||||||
@@ -1023,6 +1025,7 @@ openAPI:
|
|||||||
name: "set-annotation-quoted",
|
name: "set-annotation-quoted",
|
||||||
setter: "replicas",
|
setter: "replicas",
|
||||||
value: "3",
|
value: "3",
|
||||||
|
isSet: true,
|
||||||
input: `
|
input: `
|
||||||
openAPI:
|
openAPI:
|
||||||
definitions:
|
definitions:
|
||||||
@@ -1048,6 +1051,7 @@ openAPI:
|
|||||||
setter: "replicas",
|
setter: "replicas",
|
||||||
value: "3",
|
value: "3",
|
||||||
description: "hello world",
|
description: "hello world",
|
||||||
|
isSet: true,
|
||||||
input: `
|
input: `
|
||||||
openAPI:
|
openAPI:
|
||||||
definitions:
|
definitions:
|
||||||
@@ -1094,6 +1098,7 @@ openAPI:
|
|||||||
setter: "replicas",
|
setter: "replicas",
|
||||||
value: "3",
|
value: "3",
|
||||||
setBy: "carl",
|
setBy: "carl",
|
||||||
|
isSet: true,
|
||||||
input: `
|
input: `
|
||||||
openAPI:
|
openAPI:
|
||||||
definitions:
|
definitions:
|
||||||
@@ -1139,6 +1144,7 @@ openAPI:
|
|||||||
name: "set-replicas-set-by-empty",
|
name: "set-replicas-set-by-empty",
|
||||||
setter: "replicas",
|
setter: "replicas",
|
||||||
value: "3",
|
value: "3",
|
||||||
|
isSet: true,
|
||||||
input: `
|
input: `
|
||||||
openAPI:
|
openAPI:
|
||||||
definitions:
|
definitions:
|
||||||
@@ -1229,7 +1235,6 @@ openAPI:
|
|||||||
enumValues:
|
enumValues:
|
||||||
foo: bar
|
foo: bar
|
||||||
baz: biz
|
baz: biz
|
||||||
isSet: true
|
|
||||||
io.k8s.cli.setters.no-match-2':
|
io.k8s.cli.setters.no-match-2':
|
||||||
x-k8s-cli:
|
x-k8s-cli:
|
||||||
setter:
|
setter:
|
||||||
@@ -1242,6 +1247,7 @@ openAPI:
|
|||||||
name: "set-replicas-fail",
|
name: "set-replicas-fail",
|
||||||
setter: "replicas",
|
setter: "replicas",
|
||||||
value: "hello",
|
value: "hello",
|
||||||
|
isSet: true,
|
||||||
input: `
|
input: `
|
||||||
openAPI:
|
openAPI:
|
||||||
definitions:
|
definitions:
|
||||||
@@ -1272,6 +1278,7 @@ openAPI:
|
|||||||
name: "error",
|
name: "error",
|
||||||
setter: "replicas",
|
setter: "replicas",
|
||||||
err: `setter "replicas" is not found`,
|
err: `setter "replicas" is not found`,
|
||||||
|
isSet: true,
|
||||||
input: `
|
input: `
|
||||||
openAPI:
|
openAPI:
|
||||||
definitions:
|
definitions:
|
||||||
@@ -1328,7 +1335,6 @@ openAPI:
|
|||||||
name: args
|
name: args
|
||||||
listValues: ["2", "3", "4"]
|
listValues: ["2", "3", "4"]
|
||||||
required: true
|
required: true
|
||||||
isSet: true
|
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -1343,7 +1349,7 @@ openAPI:
|
|||||||
// invoke the setter
|
// invoke the setter
|
||||||
instance := &SetOpenAPI{
|
instance := &SetOpenAPI{
|
||||||
Name: test.setter, Value: test.value, ListValues: test.values,
|
Name: test.setter, Value: test.value, ListValues: test.values,
|
||||||
SetBy: test.setBy, Description: test.description}
|
SetBy: test.setBy, Description: test.description, IsSet: test.isSet}
|
||||||
result, err := instance.Filter(in)
|
result, err := instance.Filter(in)
|
||||||
if test.err != "" {
|
if test.err != "" {
|
||||||
if !assert.EqualError(t, err, test.err) {
|
if !assert.EqualError(t, err, test.err) {
|
||||||
|
|||||||
@@ -38,6 +38,8 @@ type FieldSetter struct {
|
|||||||
ResourcesPath string
|
ResourcesPath string
|
||||||
|
|
||||||
RecurseSubPackages bool
|
RecurseSubPackages bool
|
||||||
|
|
||||||
|
IsSet bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fs *FieldSetter) Filter(input []*yaml.RNode) ([]*yaml.RNode, error) {
|
func (fs *FieldSetter) Filter(input []*yaml.RNode) ([]*yaml.RNode, error) {
|
||||||
@@ -54,6 +56,7 @@ func (fs FieldSetter) Set() (int, error) {
|
|||||||
ListValues: fs.ListValues,
|
ListValues: fs.ListValues,
|
||||||
Description: fs.Description,
|
Description: fs.Description,
|
||||||
SetBy: fs.SetBy,
|
SetBy: fs.SetBy,
|
||||||
|
IsSet: fs.IsSet,
|
||||||
}
|
}
|
||||||
|
|
||||||
// the input field value is updated in the openAPI file and then parsed
|
// the input field value is updated in the openAPI file and then parsed
|
||||||
@@ -156,6 +159,7 @@ func syncOpenAPIValuesWithSchema(openAPIPath string) error {
|
|||||||
Name: cliExt.Setter.Name,
|
Name: cliExt.Setter.Name,
|
||||||
Value: cliExt.Setter.Value,
|
Value: cliExt.Setter.Value,
|
||||||
ListValues: cliExt.Setter.ListValues,
|
ListValues: cliExt.Setter.ListValues,
|
||||||
|
IsSet: true,
|
||||||
}
|
}
|
||||||
if err := soa.UpdateFile(openAPIPath); err != nil {
|
if err := soa.UpdateFile(openAPIPath); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
Reference in New Issue
Block a user