Skip to content

Commit 71b6e91

Browse files
committed
fix: add support for pointers as map values
1 parent 9d85d10 commit 71b6e91

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

pkg/crd/schema.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,8 @@ func mapToSchema(ctx *schemaContext, mapType *ast.MapType) *apiext.JSONSchemaPro
297297
ctx.pkg.AddError(loader.ErrFromNode(fmt.Errorf("map values must be a named type, not %T", mapType.Value), mapType.Value))
298298
return &apiext.JSONSchemaProps{}
299299
}
300+
case *ast.StarExpr:
301+
valSchema = typeToSchema(ctx.ForInfo(&markers.TypeInfo{}), val)
300302
default:
301303
ctx.pkg.AddError(loader.ErrFromNode(fmt.Errorf("map values must be a named type, not %T", mapType.Value), mapType.Value))
302304
return &apiext.JSONSchemaProps{}

pkg/crd/testdata/cronjob_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ type CronJobSpec struct {
9191
// This tests string slices are allowed as map values.
9292
StringSliceData map[string][]string `json:"stringSliceData,omitempty"`
9393

94+
// This tests pointers are allowed as map values.
95+
PtrData map[string]*string `json:"ptrData,omitempty"`
96+
9497
// This tests that markers that are allowed on both fields and types are applied to fields
9598
// +kubebuilder:validation:MinLength=4
9699
TwoOfAKindPart0 string `json:"twoOfAKindPart0"`

pkg/crd/testdata/testdata.kubebuilder.io_cronjobs.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5038,6 +5038,11 @@ spec:
50385038
description: This tests that pattern validator is properly applied.
50395039
pattern: ^$|^((https):\/\/?)[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|\/?))$
50405040
type: string
5041+
ptrData:
5042+
additionalProperties:
5043+
type: string
5044+
description: This tests pointers are allowed as map values.
5045+
type: object
50415046
schedule:
50425047
description: The schedule in Cron format, see https://en.wikipedia.org/wiki/Cron.
50435048
type: string

pkg/webhook/zz_generated.markerhelp.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)