mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-14 02:20:53 +00:00
Required setters for apply
This commit is contained in:
@@ -162,6 +162,11 @@ type SetterDefinition struct {
|
||||
// Example -- may be used for t-shirt sizing values by allowing cpu to be
|
||||
// set to small, medium or large, and then mapping these values to cpu values -- 0.5, 2, 8
|
||||
EnumValues map[string]string `yaml:"enumValues,omitempty"`
|
||||
|
||||
// Required indicates that the setter must be set by package consumer before
|
||||
// live apply/preview. This field is added to the setter definition to record
|
||||
// the package publisher's intent to make the setter required to be set.
|
||||
Required bool `yaml:"required,omitempty"`
|
||||
}
|
||||
|
||||
func (sd SetterDefinition) AddToFile(path string) error {
|
||||
|
||||
@@ -132,12 +132,12 @@ func (dd DeleterDefinition) Filter(object *yaml.RNode) (*yaml.RNode, error) {
|
||||
return nil, errors.Errorf("setter is used in substitution %s, please delete the substitution first", subst)
|
||||
}
|
||||
|
||||
_, err = definitions.Pipe(yaml.FieldClearer{Name:key})
|
||||
_, err = definitions.Pipe(yaml.FieldClearer{Name: key})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// remove definitions if it's empty
|
||||
_, err = object.Pipe(yaml.Lookup(openapi.SupplementaryOpenAPIFieldName), yaml.FieldClearer{Name:"definitions", IfEmpty: true})
|
||||
_, err = object.Pipe(yaml.Lookup(openapi.SupplementaryOpenAPIFieldName), yaml.FieldClearer{Name: "definitions", IfEmpty: true})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -181,6 +181,8 @@ func (l *List) listSubst(object *yaml.RNode) error {
|
||||
}
|
||||
|
||||
// count returns the number of fields set by the setter with name
|
||||
// set filter is leveraged for this but the resources are not written
|
||||
// back to files as only LocalPackageReader is invoked and not writer
|
||||
func (l *List) count(path, name string) (int, error) {
|
||||
s := &Set{Name: name}
|
||||
err := kio.Pipeline{
|
||||
|
||||
@@ -419,6 +419,10 @@ func (s SetOpenAPI) Filter(object *yaml.RNode) (*yaml.RNode, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := def.PipeE(&yaml.FieldSetter{Name: "isSet", StringValue: "true"}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if s.Description != "" {
|
||||
d, err := object.Pipe(yaml.LookupCreate(
|
||||
yaml.MappingNode, "openAPI", "definitions", key))
|
||||
|
||||
@@ -927,6 +927,8 @@ openAPI:
|
||||
setter:
|
||||
name: replicas
|
||||
value: "4"
|
||||
required: true
|
||||
isSet: true
|
||||
io.k8s.cli.setters.no-match-2':
|
||||
x-k8s-cli:
|
||||
setter:
|
||||
@@ -946,6 +948,8 @@ openAPI:
|
||||
setter:
|
||||
name: replicas
|
||||
value: "3"
|
||||
required: true
|
||||
isSet: true
|
||||
io.k8s.cli.setters.no-match-2':
|
||||
x-k8s-cli:
|
||||
setter:
|
||||
@@ -974,6 +978,7 @@ openAPI:
|
||||
setter:
|
||||
name: replicas
|
||||
value: "3"
|
||||
isSet: true
|
||||
`,
|
||||
},
|
||||
{
|
||||
@@ -1013,6 +1018,7 @@ openAPI:
|
||||
setter:
|
||||
name: replicas
|
||||
value: "3"
|
||||
isSet: true
|
||||
description: hello world
|
||||
io.k8s.cli.setters.no-match-2':
|
||||
x-k8s-cli:
|
||||
@@ -1059,6 +1065,7 @@ openAPI:
|
||||
name: replicas
|
||||
value: "3"
|
||||
setBy: carl
|
||||
isSet: true
|
||||
io.k8s.cli.setters.no-match-2':
|
||||
x-k8s-cli:
|
||||
setter:
|
||||
@@ -1106,6 +1113,7 @@ openAPI:
|
||||
setter:
|
||||
name: replicas
|
||||
value: "3"
|
||||
isSet: true
|
||||
io.k8s.cli.setters.no-match-2':
|
||||
x-k8s-cli:
|
||||
setter:
|
||||
@@ -1159,6 +1167,7 @@ openAPI:
|
||||
enumValues:
|
||||
foo: bar
|
||||
baz: biz
|
||||
isSet: true
|
||||
io.k8s.cli.setters.no-match-2':
|
||||
x-k8s-cli:
|
||||
setter:
|
||||
@@ -1245,6 +1254,7 @@ openAPI:
|
||||
setter:
|
||||
name: args
|
||||
listValues: ["1"]
|
||||
required: true
|
||||
`,
|
||||
expected: `
|
||||
openAPI:
|
||||
@@ -1255,6 +1265,8 @@ openAPI:
|
||||
setter:
|
||||
name: args
|
||||
listValues: ["2", "3", "4"]
|
||||
required: true
|
||||
isSet: true
|
||||
`,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -37,6 +37,11 @@ type SetterCreator struct {
|
||||
// FieldValue if set will add the OpenAPI reference to fields if they have this value.
|
||||
// Optional. If unspecified match all field values.
|
||||
FieldValue string
|
||||
|
||||
// Required indicates that the setter must be set by package consumer before
|
||||
// live apply/preview. This field is added to the setter definition to record
|
||||
// the package publisher's intent to make the setter required to be set.
|
||||
Required bool
|
||||
}
|
||||
|
||||
func (c SetterCreator) Create(openAPIPath, resourcesPath string) error {
|
||||
@@ -47,7 +52,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, Description: c.Description, SetBy: c.SetBy,
|
||||
Type: c.Type, Schema: schema,
|
||||
Type: c.Type, Schema: schema, Required: c.Required,
|
||||
}
|
||||
if err := sd.AddToFile(openAPIPath); err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user