From f698b36ece2bba8d589f0ab8e631dc596baaf1c4 Mon Sep 17 00:00:00 2001 From: Cesar Wong Date: Wed, 2 Dec 2020 20:07:49 -0500 Subject: [PATCH] Add check for the existence of profile annotations in release manifests --- pkg/cli/admin/release/new.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pkg/cli/admin/release/new.go b/pkg/cli/admin/release/new.go index 7bd37cd880..d1aa2c1dea 100644 --- a/pkg/cli/admin/release/new.go +++ b/pkg/cli/admin/release/new.go @@ -45,6 +45,8 @@ import ( imagemanifest "github.com/openshift/oc/pkg/cli/image/manifest" ) +const profileAnnotationPrefix = "include.release.openshift.io/" + func NewNewOptions(streams genericclioptions.IOStreams) *NewOptions { return &NewOptions{ IOStreams: streams, @@ -737,6 +739,24 @@ func (o *NewOptions) Run() error { if s, ok := m["apiVersion"].(string); !ok || s == "" { return fmt.Errorf("%s: manifests must contain Kubernetes API objects with 'kind' and 'apiVersion' set: %s", filename, s) } + metadata, ok := m["metadata"].(map[string]interface{}) + if !ok || metadata == nil { + return fmt.Errorf("%s: missing metadata; manifests must set at least one profile annotation", filename) + } + annotations, ok := metadata["annotations"].(map[string]interface{}) + if !ok || annotations == nil { + return fmt.Errorf("%s: missing annotations; manifests must set at least one profile annotation", filename) + } + hasProfileAnnotation := false + for key := range annotations { + if strings.HasPrefix(key, profileAnnotationPrefix) { + hasProfileAnnotation = true + break + } + } + if !hasProfileAnnotation { + return fmt.Errorf("%s: missing profile annotation; manifests must set at least one profile annotation", filename) + } break } return nil