mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-17 18:25:26 +00:00
Remove count field, convert error to warning
This commit is contained in:
@@ -55,7 +55,6 @@ openAPI:
|
||||
name: replicas
|
||||
value: "3"
|
||||
setBy: me
|
||||
count: 1
|
||||
`,
|
||||
expectedResources: `
|
||||
apiVersion: apps/v1
|
||||
@@ -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"},
|
||||
@@ -118,7 +155,6 @@ openAPI:
|
||||
name: replicas
|
||||
value: "3"
|
||||
setBy: me
|
||||
count: 1
|
||||
`,
|
||||
expectedResources: `
|
||||
apiVersion: apps/v1
|
||||
@@ -190,7 +226,6 @@ openAPI:
|
||||
- b
|
||||
- c
|
||||
setBy: me
|
||||
count: 2
|
||||
`,
|
||||
expectedResources: `
|
||||
apiVersion: example.com/v1beta1
|
||||
@@ -290,7 +325,6 @@ openAPI:
|
||||
- b
|
||||
- c
|
||||
setBy: me
|
||||
count: 1
|
||||
`,
|
||||
expectedResources: `
|
||||
apiVersion: example.com/v1beta1
|
||||
@@ -330,7 +364,6 @@ openAPI:
|
||||
name: replicas
|
||||
value: "3"
|
||||
setBy: me
|
||||
count: 1
|
||||
`,
|
||||
expectedResources: `
|
||||
apiVersion: apps/v1
|
||||
|
||||
@@ -49,7 +49,6 @@ openAPI:
|
||||
setter:
|
||||
name: replicas
|
||||
value: "3"
|
||||
count: 1
|
||||
`,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -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"
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user