11package cvo
22
33import (
4+ "bytes"
45 "context"
6+ "fmt"
7+ "os"
8+ "path/filepath"
9+ "strings"
510
611 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
712 "k8s.io/client-go/kubernetes"
@@ -13,6 +18,7 @@ import (
1318 "github.com/openshift/cluster-version-operator/test/oc"
1419 ocapi "github.com/openshift/cluster-version-operator/test/oc/api"
1520 "github.com/openshift/cluster-version-operator/test/util"
21+ "github.com/openshift/library-go/pkg/manifest"
1622)
1723
1824var logger = g .GinkgoLogr .WithName ("cluster-version-operator-tests" )
@@ -80,4 +86,56 @@ var _ = g.Describe(`[Jira:"Cluster Version Operator"] cluster-version-operator`,
8086 sccAnnotation := cvoPod .Annotations ["openshift.io/scc" ]
8187 o .Expect (sccAnnotation ).To (o .Equal ("hostaccess" ), "Expected the annotation 'openshift.io/scc annotation' on pod %s to have the value 'hostaccess', but got %s" , cvoPod .Name , sccAnnotation )
8288 })
89+
90+ g .It (`should not install resources annotated with release.openshift.io/delete=true` , g .Label ("Conformance" , "High" , "42543" ), func () {
91+ // Initialize the ocapi.OC instance
92+ g .By ("Setting up oc" )
93+ err := os .Setenv ("OC_CLI_TIMEOUT" , "90s" )
94+ o .Expect (err ).NotTo (o .HaveOccurred (), "Setup environment variable OC_CLI_TIMEOUT failed" )
95+ ocClient , err := oc .NewOC (logger )
96+ o .Expect (err ).NotTo (o .HaveOccurred ())
97+ o .Expect (ocClient ).NotTo (o .BeNil ())
98+ defer func () {
99+ err = os .Unsetenv ("OC_CLI_TIMEOUT" )
100+ o .Expect (err ).NotTo (o .HaveOccurred (), "Unset environment variable OC_CLI_TIMEOUT failed" )
101+ }()
102+
103+ g .By ("Extracting manifests in the release" )
104+ annotation := "release.openshift.io/delete"
105+ manifestDir := ocapi.ReleaseExtractOptions {To : "/tmp/OTA-42543-manifest" }
106+ logger .Info (fmt .Sprintf ("Extract manifests to: %s" , manifestDir .To ))
107+ defer func () { _ = os .RemoveAll (manifestDir .To ) }()
108+ err = ocClient .AdmReleaseExtract (manifestDir )
109+ o .Expect (err ).NotTo (o .HaveOccurred (), "extracting manifests failed" )
110+
111+ files , err := os .ReadDir (manifestDir .To )
112+ o .Expect (err ).NotTo (o .HaveOccurred ())
113+ g .By (fmt .Sprintf ("Checking if getting manifests with %s on the cluster led to not-found error" , annotation ))
114+ for _ , manifestFile := range files {
115+ if strings .Contains (strings .ToLower (manifestFile .Name ()), "cleanup" ) {
116+ logger .Info (fmt .Sprintf ("skipping file %s because it matches cleanup filter" , manifestFile .Name ()))
117+ continue
118+ }
119+
120+ filePath := filepath .Join (manifestDir .To , manifestFile .Name ())
121+ raw , err := os .ReadFile (filePath )
122+ if err != nil {
123+ o .Expect (err ).NotTo (o .HaveOccurred (), "failed to read manifest file" )
124+ }
125+ manifests , err := manifest .ParseManifests (bytes .NewReader (raw ))
126+ if err != nil {
127+ // files like release-metadata are not manifest file, so skip them
128+ logger .Error (err , "failed to parse manifest file: " + filePath )
129+ }
130+
131+ for _ , ms := range manifests {
132+ ann := ms .Obj .GetAnnotations ()
133+ if ann == nil || ann [annotation ] != "true" {
134+ continue
135+ }
136+ _ , err := ocClient .Run ("get" , "-f" , filePath )
137+ o .Expect (err ).To (o .HaveOccurred (), "The deleted manifest should not be installed, but actually installed" )
138+ }
139+ }
140+ })
83141})
0 commit comments