Skip to content

Commit

Permalink
Remove count field, convert error to warning
Browse files Browse the repository at this point in the history
  • Loading branch information
phanimarupaka committed Jul 1, 2020
1 parent e5b0ceb commit 9567d7e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 9 deletions.
43 changes: 38 additions & 5 deletions cmd/config/internal/commands/cmdcreatesetter_test.go
Expand Up @@ -55,7 +55,6 @@ openAPI:
name: replicas
value: "3"
setBy: me
count: 1
`,
expectedResources: `
apiVersion: apps/v1
Expand All @@ -66,6 +65,44 @@ spec:
replicas: 3 # {"$openapi":"replicas"}
`,
},

{
name: "add replicas no match",
args: []string{"replicas", "3", "--description", "hello world", "--set-by", "me"},
input: `
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
foo: 2
`,
inputOpenAPI: `
apiVersion: v1alpha1
kind: Example
`,
expectedOpenAPI: `
apiVersion: v1alpha1
kind: Example
openAPI:
definitions:
io.k8s.cli.setters.replicas:
description: hello world
x-k8s-cli:
setter:
name: replicas
value: "3"
setBy: me
`,
expectedResources: `
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
foo: 2
`,
},
{
name: "error if substitution with same name exists",
args: []string{"my-image", "3", "--description", "hello world", "--set-by", "me"},
Expand Down Expand Up @@ -118,7 +155,6 @@ openAPI:
name: replicas
value: "3"
setBy: me
count: 1
`,
expectedResources: `
apiVersion: apps/v1
Expand Down Expand Up @@ -190,7 +226,6 @@ openAPI:
- b
- c
setBy: me
count: 2
`,
expectedResources: `
apiVersion: example.com/v1beta1
Expand Down Expand Up @@ -290,7 +325,6 @@ openAPI:
- b
- c
setBy: me
count: 1
`,
expectedResources: `
apiVersion: example.com/v1beta1
Expand Down Expand Up @@ -330,7 +364,6 @@ openAPI:
name: replicas
value: "3"
setBy: me
count: 1
`,
expectedResources: `
apiVersion: apps/v1
Expand Down
1 change: 0 additions & 1 deletion cmd/config/internal/commands/e2e/create_setter_test.go
Expand Up @@ -49,7 +49,6 @@ openAPI:
setter:
name: replicas
value: "3"
count: 1
`,
},
},
Expand Down
6 changes: 3 additions & 3 deletions kyaml/setters2/settersutil/settercreator.go
Expand Up @@ -4,9 +4,9 @@
package settersutil

import (
"fmt"
"io/ioutil"

"sigs.k8s.io/kustomize/kyaml/errors"
"sigs.k8s.io/kustomize/kyaml/fieldmeta"
"sigs.k8s.io/kustomize/kyaml/kio"
"sigs.k8s.io/kustomize/kyaml/openapi"
Expand Down Expand Up @@ -65,7 +65,7 @@ func (c SetterCreator) Create(openAPIPath, resourcesPath string) error {
Outputs: []kio.Writer{inout},
}.Execute()
if a.Count == 0 {
return errors.Errorf("created setter doesn't match any fields")
fmt.Printf("setter %s doesn't match any field in resources, but creating setter definition\n", c.Name)
}
if err != nil {
return err
Expand All @@ -74,7 +74,7 @@ func (c SetterCreator) Create(openAPIPath, resourcesPath string) error {
// Update the OpenAPI definitions to hace the setter
sd := setters2.SetterDefinition{
Name: c.Name, Value: c.FieldValue, SetBy: c.SetBy, Description: c.Description,
Count: a.Count, Type: c.Type, Schema: schema, Required: c.Required,
Type: c.Type, Schema: schema, Required: c.Required,
}
if err := sd.AddToFile(openAPIPath); err != nil {
return err
Expand Down

0 comments on commit 9567d7e

Please sign in to comment.