From b745ff7e8a941ade965188826050a98b62f151a2 Mon Sep 17 00:00:00 2001 From: Max Smythe Date: Tue, 9 Jun 2020 14:39:10 -0700 Subject: [PATCH] Set maximum constraint name length to 63 Signed-off-by: Max Smythe --- constraint/pkg/client/crd_helpers.go | 8 ++++++++ constraint/pkg/client/crd_helpers_test.go | 12 +++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/constraint/pkg/client/crd_helpers.go b/constraint/pkg/client/crd_helpers.go index ed4f5999f..ce26c6be2 100644 --- a/constraint/pkg/client/crd_helpers.go +++ b/constraint/pkg/client/crd_helpers.go @@ -51,6 +51,14 @@ func (h *crdHelper) createSchema(templ *templates.ConstraintTemplate, target Mat } schema := &apiextensions.JSONSchemaProps{ Properties: map[string]apiextensions.JSONSchemaProps{ + "metadata": apiextensions.JSONSchemaProps{ + Properties: map[string]apiextensions.JSONSchemaProps{ + "name": apiextensions.JSONSchemaProps{ + Type: "string", + MaxLength: func(i int64) *int64 { return &i }(63), + }, + }, + }, "spec": apiextensions.JSONSchemaProps{ Properties: props, }, diff --git a/constraint/pkg/client/crd_helpers_test.go b/constraint/pkg/client/crd_helpers_test.go index 665380041..1a2793ff0 100644 --- a/constraint/pkg/client/crd_helpers_test.go +++ b/constraint/pkg/client/crd_helpers_test.go @@ -104,7 +104,17 @@ func tProp(t string) apiextensions.JSONSchemaProps { func expectedSchema(pm propMap) *apiextensions.JSONSchemaProps { pm["enforcementAction"] = apiextensions.JSONSchemaProps{Type: "string"} - p := prop(propMap{"spec": prop(pm)}) + p := prop( + propMap{ + "metadata": prop(propMap{ + "name": apiextensions.JSONSchemaProps{ + Type: "string", + MaxLength: func(i int64) *int64 { return &i }(63), + }, + }), + "spec": prop(pm), + }, + ) return &p }