@@ -14,11 +14,13 @@ import (
1414
1515 configv1 "github.com/openshift/api/config/v1"
1616 operatoringressv1 "github.com/openshift/api/operatoringress/v1"
17- operatorsv1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned/typed/operators/v1"
1817
1918 exutil "github.com/openshift/origin/test/extended/util"
2019 corev1 "k8s.io/api/core/v1"
2120 apierrors "k8s.io/apimachinery/pkg/api/errors"
21+ "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
22+ "k8s.io/apimachinery/pkg/runtime/schema"
23+ "k8s.io/apimachinery/pkg/types"
2224 "k8s.io/apimachinery/pkg/util/intstr"
2325 e2e "k8s.io/kubernetes/test/e2e/framework"
2426 admissionapi "k8s.io/pod-security-admission/api"
@@ -160,17 +162,29 @@ var _ = g.Describe("[sig-network-edge][OCPFeatureGate:GatewayAPIController][Feat
160162
161163 g .By ("Deleting the OSSM Operator resources" )
162164
163- operator , err := operatorsv1 .NewForConfigOrDie (oc .AsAdmin ().UserConfig ()).Operators ().Get (context .Background (), serviceMeshOperatorName , metav1.GetOptions {})
165+ gvr := schema.GroupVersionResource {
166+ Group : "operators.coreos.com" ,
167+ Version : "v1" ,
168+ Resource : "operators" ,
169+ }
170+ operator , err := oc .KubeFramework ().DynamicClient .Resource (gvr ).Get (context .Background (), serviceMeshOperatorName , metav1.GetOptions {})
164171 o .Expect (err ).NotTo (o .HaveOccurred (), "Failed to get Operator %q" , serviceMeshOperatorName )
165172
173+ refs , ok , err := unstructured .NestedSlice (operator .Object , "status" , "components" , "refs" )
174+ o .Expect (err ).NotTo (o .HaveOccurred ())
175+ o .Expect (ok ).To (o .BeTrue (), "Failed to find status.components.refs in Operator %q" , serviceMeshOperatorName )
166176 restmapper := oc .AsAdmin ().RESTMapper ()
167- for _ , ref := range operator .Status .Components .Refs {
177+ for _ , ref := range refs {
178+ ref := extractObjectReference (ref .(map [string ]any ))
168179 mapping , err := restmapper .RESTMapping (ref .GroupVersionKind ().GroupKind ())
169180 o .Expect (err ).NotTo (o .HaveOccurred ())
170181
182+ e2e .Logf ("Deleting %s %s/%s..." , ref .Kind , ref .Namespace , ref .Name )
171183 err = oc .KubeFramework ().DynamicClient .Resource (mapping .Resource ).Namespace (ref .Namespace ).Delete (context .Background (), ref .Name , metav1.DeleteOptions {})
172184 o .Expect (err ).Should (o .Or (o .Not (o .HaveOccurred ()), o .MatchError (apierrors .IsNotFound , "IsNotFound" )), "Failed to delete %s %q: %v" , ref .GroupVersionKind ().Kind , ref .Name , err )
173185 }
186+
187+ o .Expect (oc .AsAdmin ().WithoutNamespace ().Run ("delete" ).Args ("operators" , serviceMeshOperatorName ).Execute ()).Should (o .Succeed ())
174188 }
175189 })
176190
@@ -850,3 +864,28 @@ func checkAllTestsDone(oc *exutil.CLI) bool {
850864
851865 return true
852866}
867+
868+ // getNestedString returns a string value of a nested field value of an
869+ // unstructured.Unstructured object. If the named field is of a non-string
870+ // type, getNestedString returns the empty string.
871+ func getNestedString (obj map [string ]any , field string ) string {
872+ val , found , err := unstructured .NestedString (obj , field )
873+ if ! found || err != nil {
874+ return ""
875+ }
876+ return val
877+ }
878+
879+ // extractObjectReference returns a ObjectReference value of a nested field
880+ // value of an unstructured.Unstructured object.
881+ func extractObjectReference (v map [string ]any ) corev1.ObjectReference {
882+ return corev1.ObjectReference {
883+ Kind : getNestedString (v , "kind" ),
884+ Namespace : getNestedString (v , "namespace" ),
885+ Name : getNestedString (v , "name" ),
886+ UID : types .UID (getNestedString (v , "uid" )),
887+ APIVersion : getNestedString (v , "apiVersion" ),
888+ ResourceVersion : getNestedString (v , "resourceVersion" ),
889+ FieldPath : getNestedString (v , "fieldPath" ),
890+ }
891+ }
0 commit comments