11package payload
22
33import (
4+ "fmt"
45 "os"
6+ "path/filepath"
57 "strings"
68 "testing"
79
@@ -12,6 +14,7 @@ import (
1214 "k8s.io/utils/ptr"
1315
1416 configv1 "github.com/openshift/api/config/v1"
17+ "github.com/openshift/library-go/pkg/manifest"
1518)
1619
1720func TestRenderManifest (t * testing.T ) {
@@ -304,3 +307,48 @@ data:
304307
305308 return yaml
306309}
310+ func Test_cvoManifests (t * testing.T ) {
311+ installDir := filepath .Join ("../../install" )
312+ files , err := os .ReadDir (installDir )
313+ if err != nil {
314+ t .Fatalf ("failed to read directory: %v" , err )
315+ }
316+
317+ if len (files ) == 0 {
318+ t .Fatalf ("no files found in %s" , installDir )
319+ }
320+
321+ var manifestsWithoutIncludeAnnotation []manifest.Manifest
322+ const prefix = "include.release.openshift.io/"
323+ for _ , manifestFile := range files {
324+ if manifestFile .IsDir () {
325+ continue
326+ }
327+ filePath := filepath .Join (installDir , manifestFile .Name ())
328+ manifests , err := manifest .ManifestsFromFiles ([]string {filePath })
329+ if err != nil {
330+ t .Fatalf ("failed to load manifests: %v" , err )
331+ }
332+
333+ for _ , m := range manifests {
334+ var found bool
335+ for k := range m .Obj .GetAnnotations () {
336+ if strings .HasPrefix (k , prefix ) {
337+ found = true
338+ break
339+ }
340+ }
341+ if ! found {
342+ manifestsWithoutIncludeAnnotation = append (manifestsWithoutIncludeAnnotation , m )
343+ }
344+ }
345+ }
346+
347+ if len (manifestsWithoutIncludeAnnotation ) > 0 {
348+ var messages []string
349+ for _ , m := range manifestsWithoutIncludeAnnotation {
350+ messages = append (messages , fmt .Sprintf ("%s/%s/%s/%s" , m .OriginalFilename , m .GVK , m .Obj .GetName (), m .Obj .GetNamespace ()))
351+ }
352+ t .Fatalf ("Those manifests have no annotation with prefix %q and will not beinstalled by CVO: %s" , prefix , strings .Join (messages , "', '" ))
353+ }
354+ }
0 commit comments