Skip to content

Commit

Permalink
Only prevent validation of top-level metadata field
Browse files Browse the repository at this point in the history
Signed-off-by: Arjun Naik <arjun.rn@gmail.com>
  • Loading branch information
arjunrn committed Jan 26, 2020
1 parent a1c859b commit cca9bfe
Show file tree
Hide file tree
Showing 3 changed files with 905 additions and 5 deletions.
13 changes: 13 additions & 0 deletions pkg/crd/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func (g Generator) Generate(ctx *genall.GenerationContext) error {
parser.NeedCRDFor(groupKind, g.MaxDescLen)
crdRaw := parser.CustomResourceDefinitions[groupKind]
addAttribution(&crdRaw)
fixupMetadata(crdRaw)

versionedCRDs := make([]interface{}, len(crdVersions))
for i, ver := range crdVersions {
Expand Down Expand Up @@ -156,6 +157,18 @@ func (g Generator) Generate(ctx *genall.GenerationContext) error {
return nil
}

// fixupMetadata resets the schema for the top-level metadata field which is need for CRD validation
func fixupMetadata(crd apiext.CustomResourceDefinition) {
for _, v := range crd.Spec.Versions {
if v.Schema != nil && v.Schema.OpenAPIV3Schema != nil && v.Schema.OpenAPIV3Schema.Properties != nil {
schemaProperties := v.Schema.OpenAPIV3Schema.Properties
if _, ok := schemaProperties["metadata"]; ok {
schemaProperties["metadata"] = apiext.JSONSchemaProps{Type: "object"}
}
}
}
}

// toTrivialVersions strips out all schemata except for the storage schema,
// and moves that up into the root object. This makes the CRD compatible
// with pre 1.13 clusters.
Expand Down
5 changes: 0 additions & 5 deletions pkg/crd/known_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ import (
var KnownPackages = map[string]PackageOverride{

"k8s.io/apimachinery/pkg/apis/meta/v1": func(p *Parser, pkg *loader.Package) {
// ObjectMeta is managed by the Kubernetes API server, so no need to
// generate validation for it.
p.Schemata[TypeIdent{Name: "ObjectMeta", Package: pkg}] = apiext.JSONSchemaProps{
Type: "object",
}
p.Schemata[TypeIdent{Name: "Time", Package: pkg}] = apiext.JSONSchemaProps{
Type: "string",
Format: "date-time",
Expand Down
Loading

0 comments on commit cca9bfe

Please sign in to comment.