Required setters for apply

This commit is contained in:
Phani Teja Marupaka
2020-06-22 20:17:17 -07:00
parent a895220743
commit 68ab3b87d9
12 changed files with 75 additions and 25 deletions

View File

@@ -50,6 +50,8 @@ func NewCreateSetterRunner(parent string) *CreateSetterRunner {
set.Flags().MarkHidden("partial")
set.Flags().StringVar(&setterVersion, "version", "",
"use this version of the setter format")
set.Flags().BoolVar(&r.CreateSetter.Required, "required", false,
"indicates that this setter must be set by package consumer before live apply/preview")
set.Flags().StringVar(&r.CreateSetter.SchemaPath, "schema-path", "",
`openAPI schema file path for setter constraints -- file content `+
`e.g. {"type": "string", "maxLength": 15, "enum": ["allowedValue1", "allowedValue2"]}`)

View File

@@ -79,7 +79,7 @@ func (r *ListSettersRunner) ListSetters(c *cobra.Command, args []string) error {
return err
}
table := newTable(c.OutOrStdout(), r.Markdown)
table.SetHeader([]string{"NAME", "VALUE", "SET BY", "DESCRIPTION", "COUNT"})
table.SetHeader([]string{"NAME", "VALUE", "SET BY", "DESCRIPTION", "COUNT", "REQUIRED"})
for i := range r.List.Setters {
s := r.List.Setters[i]
v := s.Value
@@ -89,8 +89,14 @@ func (r *ListSettersRunner) ListSetters(c *cobra.Command, args []string) error {
v = strings.Join(s.ListValues, ",")
v = fmt.Sprintf("[%s]", v)
}
var required string
if s.Required {
required = "Yes"
} else {
required = "No"
}
table.Append([]string{
s.Name, v, s.SetBy, s.Description, fmt.Sprintf("%d", s.Count)})
s.Name, v, s.SetBy, s.Description, fmt.Sprintf("%d", s.Count), required})
}
table.Render()

View File

@@ -34,6 +34,7 @@ openAPI:
name: replicas
value: "3"
setBy: me
required: true
description: "hello world"
`,
input: `
@@ -44,8 +45,8 @@ metadata:
spec:
replicas: 3 # {"$ref": "#/definitions/io.k8s.cli.setters.replicas"}
`,
expected: ` NAME VALUE SET BY DESCRIPTION COUNT
replicas 3 me hello world 1
expected: ` NAME VALUE SET BY DESCRIPTION COUNT REQUIRED
replicas 3 me hello world 1 Yes
`,
},
{
@@ -74,6 +75,8 @@ openAPI:
name: tag
value: "1.7.9"
setBy: me3
required: true
isSet: false
io.k8s.cli.substitutions.image:
x-k8s-cli:
substitution:
@@ -100,10 +103,10 @@ spec:
- name: nginx2
image: nginx # {"$ref": "#/definitions/io.k8s.cli.setters.image"}
`,
expected: ` NAME VALUE SET BY DESCRIPTION COUNT
image nginx me2 hello world 2 2
replicas 3 me1 hello world 1 1
tag 1.7.9 me3 hello world 3 1
expected: ` NAME VALUE SET BY DESCRIPTION COUNT REQUIRED
image nginx me2 hello world 2 2 No
replicas 3 me1 hello world 1 1 No
tag 1.7.9 me3 hello world 3 1 Yes
SUBSTITUTION PATTERN REFERENCES
image IMAGE:TAG [image,tag]
`,
@@ -174,10 +177,10 @@ spec:
- name: nginx2
image: nginx
`,
expected: ` NAME VALUE SET BY DESCRIPTION COUNT
image nginx me2 hello world 2 3
replicas 3 me1 hello world 1 2
tag 1.7.9 me3 hello world 3 2
expected: ` NAME VALUE SET BY DESCRIPTION COUNT REQUIRED
image nginx me2 hello world 2 3 No
replicas 3 me1 hello world 1 2 No
tag 1.7.9 me3 hello world 3 2 No
SUBSTITUTION PATTERN REFERENCES
image IMAGE:TAG [image,tag]
`,
@@ -202,6 +205,7 @@ openAPI:
name: image
value: "nginx"
setBy: me2
required: true
io.k8s.cli.setters.tag:
description: "hello world 3"
x-k8s-cli:
@@ -249,8 +253,8 @@ spec:
- name: nginx2
image: nginx
`,
expected: ` NAME VALUE SET BY DESCRIPTION COUNT
image nginx me2 hello world 2 3
expected: ` NAME VALUE SET BY DESCRIPTION COUNT REQUIRED
image nginx me2 hello world 2 3 Yes
SUBSTITUTION PATTERN REFERENCES
image IMAGE:TAG [image,tag]
`,
@@ -277,6 +281,7 @@ openAPI:
- b
- c
setBy: me
required: true
`,
input: `
apiVersion: example.com/v1beta1
@@ -290,8 +295,8 @@ spec:
- "b"
- "c"
`,
expected: ` NAME VALUE SET BY DESCRIPTION COUNT
list [a,b,c] me hello world 1
expected: ` NAME VALUE SET BY DESCRIPTION COUNT REQUIRED
list [a,b,c] me hello world 1 Yes
`,
},
@@ -327,6 +332,8 @@ openAPI:
setter:
name: my-tag-setter
value: 1.7.9
required: true
isSet: true
io.k8s.cli.substitutions.my-image-subst:
x-k8s-cli:
substitution:
@@ -353,10 +360,10 @@ openAPI:
name: my-other-setter
value: nginxotherthing
`,
expected: ` NAME VALUE SET BY DESCRIPTION COUNT
my-image-setter nginx 2
my-other-setter nginxotherthing 1
my-tag-setter 1.7.9 2
expected: ` NAME VALUE SET BY DESCRIPTION COUNT REQUIRED
my-image-setter nginx 2 No
my-other-setter nginxotherthing 1 No
my-tag-setter 1.7.9 2 Yes
SUBSTITUTION PATTERN REFERENCES
my-image-subst ${my-image-setter}::${my-tag-setter} [my-image-setter,my-tag-setter]
my-nested-subst something/${my-image-subst}/${my-other-setter} [my-image-subst,my-other-setter]

View File

@@ -64,6 +64,7 @@ openAPI:
name: replicas
value: "4"
setBy: pw
isSet: true
`,
expectedResources: `
apiVersion: apps/v1
@@ -158,6 +159,7 @@ openAPI:
setter:
name: replicas
value: "4"
isSet: true
`,
expectedResources: `
apiVersion: apps/v1
@@ -229,6 +231,7 @@ openAPI:
setter:
name: tag
value: "1.8.1"
isSet: true
io.k8s.cli.substitutions.image:
x-k8s-cli:
substitution:
@@ -539,6 +542,7 @@ openAPI:
setter:
name: replicas
value: "4"
isSet: true
`,
expectedResources: `
apiVersion: apps/v1
@@ -639,6 +643,7 @@ openAPI:
listValues:
- "10"
- "11"
isSet: true
`,
expectedResources: `
apiVersion: example.com/v1beta1
@@ -771,6 +776,7 @@ openAPI:
setter:
name: my-image-setter
value: ubuntu
isSet: true
io.k8s.cli.setters.my-tag-setter:
x-k8s-cli:
setter:

View File

@@ -34,8 +34,8 @@ openAPI:
`,
},
expectedStdOut: `
NAME VALUE SET BY DESCRIPTION COUNT
replicas 3 1
NAME VALUE SET BY DESCRIPTION COUNT REQUIRED
replicas 3 1 No
`,
},
}

View File

@@ -54,6 +54,7 @@ openAPI:
setter:
name: replicas
value: "4"
isSet: true
`,
},
},