@@ -5,21 +5,16 @@ package cvo
55import (
66 "context"
77 "fmt"
8- "os"
9- "path/filepath"
10- "time"
8+ "strings"
119
1210 g "github.com/onsi/ginkgo/v2"
1311 o "github.com/onsi/gomega"
1412
1513 apierrors "k8s.io/apimachinery/pkg/api/errors"
1614 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
17- "k8s.io/apimachinery/pkg/util/sets"
1815 "k8s.io/client-go/kubernetes"
1916 "k8s.io/client-go/rest"
2017
21- "github.com/openshift/library-go/pkg/manifest"
22-
2318 "github.com/openshift/cluster-version-operator/pkg/cvo/external/dynamicclient"
2419 "github.com/openshift/cluster-version-operator/pkg/external"
2520 "github.com/openshift/cluster-version-operator/test/oc"
@@ -118,50 +113,40 @@ var _ = g.Describe(`[Jira:"Cluster Version Operator"] cluster-version-operator`,
118113 err = util .SkipIfNetworkRestricted (ctx , restCfg , util .FauxinnatiAPIURL )
119114 o .Expect (err ).NotTo (o .HaveOccurred (), "Failed to determine if cluster is network restricted" )
120115
121- // Initialize the ocapi.OC instance
122- g .By ("Setting up oc" )
123- ocClient , err := oc .NewOC (ocapi.Options {Logger : logger , Timeout : 90 * time .Second })
116+ pods , err := util .GetPodsByNamespace (ctx , kubeClient , external .DefaultCVONamespace , map [string ]string {"k8s-app" : "cluster-version-operator" })
124117 o .Expect (err ).NotTo (o .HaveOccurred ())
118+ logger .Info ("CVO pod found" , "name" , pods [0 ].Name )
125119
126- g .By ("Extracting manifests in the release" )
127120 annotation := "release.openshift.io/delete"
128- tempDir , err := os .MkdirTemp ("" , "OTA-42543-manifest-" )
129- o .Expect (err ).NotTo (o .HaveOccurred (), "create temp manifest dir failed" )
130-
131- authFile , err := util .GetAuthFile (context .Background (), kubeClient , "openshift-config" , "pull-secret" , ".dockerconfigjson" )
121+ manifestDir := "/release-manifests/"
122+ command := []string {"find" , manifestDir , "-iname" , "*.yaml" , "-exec" , "grep" , "-l" , annotation , "{}" , ";" }
123+ files , err := util .ListFilesInPodContainer (ctx , restCfg , command , external .DefaultCVONamespace , pods [0 ].Name , "cluster-version-operator" )
132124 o .Expect (err ).NotTo (o .HaveOccurred ())
133- defer func () { _ = os .Remove (authFile ) }()
134- manifestDir := ocapi.ReleaseExtractOptions {To : tempDir , AuthFile : authFile }
135- logger .Info (fmt .Sprintf ("Extract manifests to: %s" , manifestDir .To ))
136- defer func () { _ = os .RemoveAll (manifestDir .To ) }()
137- err = ocClient .AdmReleaseExtract (manifestDir )
138- o .Expect (err ).NotTo (o .HaveOccurred (), "extracting manifests failed" )
139-
140- files , err := os .ReadDir (manifestDir .To )
141- o .Expect (err ).NotTo (o .HaveOccurred ())
142- g .By (fmt .Sprintf ("Checking if getting manifests with %s on the cluster led to not-found error" , annotation ))
143- ignore := sets .New ("release-metadata" , "image-references" )
144- for _ , manifestFile := range files {
145- if manifestFile .IsDir () || ignore .Has (manifestFile .Name ()) {
125+ o .Expect (files ).ToNot (o .BeEmpty (), "Expected to find files in manifests directory of CVO pod, but found none" )
126+
127+ for _ , f := range files {
128+ fileContent , err := util .GetFileContentInPodContainer (ctx , restCfg , external .DefaultCVONamespace , pods [0 ].Name , "cluster-version-operator" , f )
129+ o .Expect (err ).NotTo (o .HaveOccurred (), fmt .Sprintf ("Failed to get content of file %s in CVO pod" , f ))
130+ o .Expect (fileContent ).ToNot (o .BeEmpty (), fmt .Sprintf ("Expected to get content of file %s in CVO pod, but got empty content" , f ))
131+
132+ if ! strings .Contains (fileContent , annotation ) {
146133 continue
147134 }
148- filePath := filepath .Join (manifestDir .To , manifestFile .Name ())
149- o .Expect (err ).NotTo (o .HaveOccurred (), "failed to read manifest file" )
150- manifests , err := manifest .ManifestsFromFiles ([]string {filePath })
151- o .Expect (err ).NotTo (o .HaveOccurred (), fmt .Sprintf ("failed to parse manifest file: %s" , filePath ))
152-
153- for _ , ms := range manifests {
154- ann := ms .Obj .GetAnnotations ()
155- if ann [annotation ] != "true" {
156- continue
157- }
158- client , err := dynamicclient .New (restCfg , ms .GVK , ms .Obj .GetNamespace ())
159- o .Expect (err ).NotTo (o .HaveOccurred ())
160- _ , err = client .Get (ctx , ms .Obj .GetName (), metav1.GetOptions {})
161- o .Expect (apierrors .IsNotFound (err )).To (o .BeTrue (),
162- fmt .Sprintf ("The deleted manifest should not be installed, but actually installed: manifest: %s %s in namespace %s from file %q, error: %v" ,
163- ms .GVK , ms .Obj .GetName (), ms .Obj .GetNamespace (), ms .OriginalFilename , err ))
135+
136+ manifest , err := util .ParseManifest (fileContent )
137+ o .Expect (err ).NotTo (o .HaveOccurred (), fmt .Sprintf ("Failed to parse manifest content of file %s in CVO pod" , f ))
138+
139+ ann := manifest .Obj .GetAnnotations ()
140+ if ann [annotation ] != "true" {
141+ continue
164142 }
143+ logger .Info ("Checking file: " , f , ", GVK:" , manifest .GVK .String (), ", Name: " , manifest .Obj .GetName (), ", Namespace: " , manifest .Obj .GetNamespace ())
144+ client , err := dynamicclient .New (restCfg , manifest .GVK , manifest .Obj .GetNamespace ())
145+ o .Expect (err ).NotTo (o .HaveOccurred ())
146+ _ , err = client .Get (ctx , manifest .Obj .GetName (), metav1.GetOptions {})
147+ o .Expect (apierrors .IsNotFound (err )).To (o .BeTrue (),
148+ fmt .Sprintf ("The deleted manifest should not be installed, but actually installed: manifest: %s %s in namespace %s from file %q, error: %v" ,
149+ manifest .GVK , manifest .Obj .GetName (), manifest .Obj .GetNamespace (), f , err ))
165150 }
166151 })
167152})
0 commit comments