Skip to content

Commit 834671d

Browse files
committed
All CVO manifests in payload should be included
Because `bootstrap-pod.yaml` is not a valid yaml [1], we have to render it and then parse out manifests from it. We could make it valid as we did for the others, but it might be dangerous to do so. We have only one manifest for bootstrap. I am fine with a rendering step. The test checks annotations on manifests, and thus it is not essential to do the rendering step if we could parse the file successfully. The rendering step is now applied to all manifests in this test even though it is not essential for the ones in the `install` folder. We do it anyway because * It makes the code simple as we do not have to distinguish where the file is from. * CVO does it too before applying it to the cluster. #1171 (comment)
1 parent 0276666 commit 834671d

1 file changed

Lines changed: 87 additions & 0 deletions

File tree

pkg/payload/render_test.go

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package payload
22

33
import (
4+
"bytes"
5+
"fmt"
6+
"io/fs"
47
"os"
8+
"path/filepath"
59
"strings"
610
"testing"
711

@@ -12,6 +16,7 @@ import (
1216
"k8s.io/utils/ptr"
1317

1418
configv1 "github.com/openshift/api/config/v1"
19+
"github.com/openshift/library-go/pkg/manifest"
1520
)
1621

1722
func TestRenderManifest(t *testing.T) {
@@ -304,3 +309,85 @@ data:
304309

305310
return yaml
306311
}
312+
func Test_cvoManifests(t *testing.T) {
313+
config := manifestRenderConfig{
314+
ReleaseImage: "quay.io/cvo/release:latest",
315+
ClusterProfile: "some-profile",
316+
}
317+
318+
tests := []struct {
319+
name string
320+
dir string
321+
}{
322+
{
323+
name: "install dir",
324+
dir: filepath.Join("../../install"),
325+
},
326+
{
327+
name: "bootstrap dir",
328+
dir: filepath.Join("../../bootstrap"),
329+
},
330+
}
331+
const prefix = "include.release.openshift.io/"
332+
for _, tt := range tests {
333+
t.Run(tt.name, func(t *testing.T) {
334+
var count int
335+
err := filepath.WalkDir(tt.dir, func(path string, d fs.DirEntry, err error) error {
336+
if err != nil {
337+
return err
338+
}
339+
340+
if d.IsDir() {
341+
return nil
342+
}
343+
344+
var manifestsWithoutIncludeAnnotation []manifest.Manifest
345+
data, err := os.ReadFile(path)
346+
if err != nil {
347+
t.Fatalf("failed to read manifest file: %v", err)
348+
}
349+
data, err = renderManifest(config, data)
350+
if err != nil {
351+
t.Fatalf("failed to render manifest: %v", err)
352+
}
353+
manifests, err := manifest.ParseManifests(bytes.NewReader(data))
354+
if err != nil {
355+
t.Fatalf("failed to load manifests: %v", err)
356+
}
357+
358+
for _, m := range manifests {
359+
m.OriginalFilename = path
360+
var found bool
361+
for k := range m.Obj.GetAnnotations() {
362+
if strings.HasPrefix(k, prefix) {
363+
found = true
364+
break
365+
}
366+
}
367+
if !found {
368+
manifestsWithoutIncludeAnnotation = append(manifestsWithoutIncludeAnnotation, m)
369+
}
370+
}
371+
372+
if len(manifestsWithoutIncludeAnnotation) > 0 {
373+
var messages []string
374+
for _, m := range manifestsWithoutIncludeAnnotation {
375+
messages = append(messages, fmt.Sprintf("%s/%s/%s/%s", m.OriginalFilename, m.GVK, m.Obj.GetName(), m.Obj.GetNamespace()))
376+
}
377+
t.Errorf("Those manifests have no annotation with prefix %q and will not be installed by CVO: %s", prefix, strings.Join(messages, ", "))
378+
}
379+
count++
380+
return nil
381+
})
382+
383+
if err != nil {
384+
t.Fatalf("failed to walk directory: %v", err)
385+
}
386+
387+
if count == 0 {
388+
t.Errorf("no files found in %s", tt.dir)
389+
}
390+
391+
})
392+
}
393+
}

0 commit comments

Comments
 (0)