Skip to content

Commit 8059b9b

Browse files
committed
Address comments: change flag name and add tests
1 parent 5906e25 commit 8059b9b

File tree

8 files changed

+26
-13
lines changed

8 files changed

+26
-13
lines changed

cmd/internal/codegen/parse/crd.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,13 +217,13 @@ func (b *APIs) parsePrimitiveValidation(t *types.Type, found sets.String, commen
217217

218218
type mapTempateArgs struct {
219219
Result string
220-
SkipMap bool
220+
SkipMapValidation bool
221221
}
222222

223223
var mapTemplate = template.Must(template.New("map-template").Parse(
224224
`v1beta1.JSONSchemaProps{
225225
Type: "object",
226-
{{if not .SkipMap}}AdditionalProperties: &v1beta1.JSONSchemaPropsOrBool{
226+
{{if not .SkipMapValidation}}AdditionalProperties: &v1beta1.JSONSchemaPropsOrBool{
227227
Allows: true,
228228
Schema: &{{.Result}},
229229
},{{end}}
@@ -237,14 +237,14 @@ func (b *APIs) parseMapValidation(t *types.Type, found sets.String, comments []s
237237
Type: "object",
238238
}
239239
parseOption := b.arguments.CustomArgs.(*ParseOptions)
240-
if !parseOption.SkipMap {
240+
if !parseOption.SkipMapValidation {
241241
props.AdditionalProperties = &v1beta1.JSONSchemaPropsOrBool{
242242
Allows: true,
243243
Schema: &additionalProps}
244244
}
245245

246246
buff := &bytes.Buffer{}
247-
if err := mapTemplate.Execute(buff, mapTempateArgs{result, parseOption.SkipMap}); err != nil {
247+
if err := mapTemplate.Execute(buff, mapTempateArgs{Result: result, SkipMapValidation: parseOption.SkipMapValidation}); err != nil {
248248
log.Fatalf("%v", err)
249249
}
250250
return props, buff.String()

cmd/internal/codegen/parse/util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
)
2828

2929
type ParseOptions struct {
30-
SkipMap bool
30+
SkipMapValidation bool
3131
}
3232

3333
// IsAPIResource returns true if t has a +resource/+kubebuilder:resource comment tag

cmd/kubebuilder-gen/codegen/run/generator.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ func (g *CodeGenerator) Execute() error {
5252

5353
// Custom args.
5454
customArgs := &parse.ParseOptions{}
55-
pflag.CommandLine.BoolVar(&customArgs.SkipMap, "skip-map", true,
56-
"If set true, skip map types.")
55+
pflag.CommandLine.BoolVar(&customArgs.SkipMapValidation, "skip-map-validation", true,
56+
"if set to true, skip generating validation schema for map type in CRD.")
5757
arguments.CustomArgs = customArgs
5858

5959
arguments.OutputFileBaseName = g.OutputFileBaseName

cmd/kubebuilder/create/config/config.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ kubebuilder create config --crds --output myextensionname.yaml
5757
fmt.Printf("Must either specify the name of the extension with --name or set --crds.\n")
5858
return
5959
}
60-
CodeGenerator{SkipMap: skipmap}.Execute()
60+
CodeGenerator{SkipMapValidation: skipMapValidation}.Execute()
6161
log.Printf("Config written to %s", output)
6262
},
6363
}
6464

6565
var (
6666
controllerType, controllerImage, name, output, crdNamespace string
67-
crds, skipmap bool
67+
crds, skipMapValidation bool
6868
)
6969

7070
func AddCreateConfig(cmd *cobra.Command) {
@@ -75,5 +75,5 @@ func AddCreateConfig(cmd *cobra.Command) {
7575
configCmd.Flags().StringVar(&controllerImage, "controller-image", "", "name of the controller container to run.")
7676
configCmd.Flags().StringVar(&name, "name", "", "name of the installation. used to generate the namespace and resource names.")
7777
configCmd.Flags().StringVar(&output, "output", filepath.Join("hack", "install.yaml"), "location to write yaml to")
78-
configCmd.Flags().BoolVar(&skipmap, "skip-map", true, "if set to true, skip validation of map in CRD")
78+
configCmd.Flags().BoolVar(&skipMapValidation, "skip-map-validation", true, "if set to true, skip generating validation schema for map type in CRD.")
7979
}

cmd/kubebuilder/create/config/gen.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import (
3737

3838
// CodeGenerator generates code for Kubernetes resources and controllers
3939
type CodeGenerator struct{
40-
SkipMap bool
40+
SkipMapValidation bool
4141
}
4242

4343
var kblabels = map[string]string{
@@ -69,7 +69,7 @@ func (g CodeGenerator) Execute() error {
6969
return fmt.Errorf("Failed making a context: %v", err)
7070
}
7171

72-
arguments.CustomArgs = &parse.ParseOptions{SkipMap: g.SkipMap}
72+
arguments.CustomArgs = &parse.ParseOptions{SkipMapValidation: g.SkipMapValidation}
7373

7474
p := parse.NewAPIs(c, arguments)
7575
if crds {

cmd/kubebuilder/docs/gen.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func (g CodeGenerator) Execute(dir string) error {
3232
return fmt.Errorf("Failed making a context: %v", err)
3333
}
3434

35-
arguments.CustomArgs = &parse.ParseOptions{SkipMap: true}
35+
arguments.CustomArgs = &parse.ParseOptions{SkipMapValidation: true}
3636

3737
p := parse.NewAPIs(c, arguments)
3838
path := filepath.Join(dir, outputDir, "config.yaml")

test.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ function generate_crd_resources {
150150
sed -i -e "s|type Bee struct|// +kubebuilder:categories=foo,bar\ntype Bee struct|" pkg/apis/insect/v1beta1/bee_types.go
151151
sed -i -e "s|type BeeController struct {|// +kubebuilder:rbac:groups="",resources=pods,verbs=get;watch;list\ntype BeeController struct {|" pkg/controller/bee/controller.go
152152

153+
header_text "adding a map type to resource"
154+
sed -i -e "s|type BeeSpec struct {|type BeeSpec struct {\n Request map[string]string \`json:\"request,omitempty\"\`|" pkg/apis/insect/v1beta1/bee_types.go
155+
153156
header_text "generating and testing CRD definition"
154157
kubebuilder create config --crds --output crd.yaml
155158
kubebuilder create config --controller-image myimage:v1 --name myextensionname --output install.yaml
@@ -187,6 +190,9 @@ spec:
187190
metadata:
188191
type: object
189192
spec:
193+
properties:
194+
request:
195+
type: object
190196
type: object
191197
status:
192198
type: object
@@ -281,6 +287,9 @@ spec:
281287
metadata:
282288
type: object
283289
spec:
290+
properties:
291+
request:
292+
type: object
284293
type: object
285294
status:
286295
type: object
@@ -429,6 +438,9 @@ spec:
429438
metadata:
430439
type: object
431440
spec:
441+
properties:
442+
request:
443+
type: object
432444
type: object
433445
status:
434446
type: object

test/docs/expected/includes/_generated_bee_v1beta1_insect_concept.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Appears In:
3939

4040
Field | Description
4141
------------ | -----------
42+
`request`<br /> *object* |
4243

4344
### BeeStatus v1beta1
4445

0 commit comments

Comments
 (0)