33package e2e
44
55import (
6- "fmt"
7-
86 . "github.com/onsi/ginkgo/v2"
97 . "github.com/onsi/gomega"
108 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -33,10 +31,9 @@ var _ = Describe("Test config-policy-controller deployment", func() {
3331 deploy = GetWithTimeout (
3432 cluster .clusterClient , gvrDeployment , case2DeploymentName , addonNamespace , true , 30 ,
3533 )
36- spec := deploy .Object ["spec" ].(map [string ]interface {})["template" ].(map [string ]interface {})["spec" ]
37- containers := spec .(map [string ]interface {})["containers" ]
34+ containers , _ , _ := unstructured .NestedSlice (deploy .Object , "spec" , "template" , "spec" , "containers" )
3835
39- return len (containers .([] interface {}) )
36+ return len (containers )
4037 }, 60 , 1 ).Should (Equal (1 ))
4138
4239 if startupProbeInCluster (i ) {
@@ -45,11 +42,18 @@ var _ = Describe("Test config-policy-controller deployment", func() {
4542 deploy = GetWithTimeout (
4643 cluster .clusterClient , gvrDeployment , case2DeploymentName , addonNamespace , true , 30 ,
4744 )
48- status := deploy .Object ["status" ]
49- replicas := status .(map [string ]interface {})["replicas" ]
50- availableReplicas := status .(map [string ]interface {})["availableReplicas" ]
5145
52- return (availableReplicas != nil ) && replicas .(int64 ) == availableReplicas .(int64 )
46+ replicas , found , err := unstructured .NestedInt64 (deploy .Object , "status" , "replicas" )
47+ if ! found || err != nil {
48+ return false
49+ }
50+
51+ available , found , err := unstructured .NestedInt64 (deploy .Object , "status" , "availableReplicas" )
52+ if ! found || err != nil {
53+ return false
54+ }
55+
56+ return available == replicas
5357 }, 240 , 1 ).Should (Equal (true ))
5458 }
5559
@@ -59,9 +63,10 @@ var _ = Describe("Test config-policy-controller deployment", func() {
5963 LabelSelector : case2PodSelector ,
6064 }
6165 pods := ListWithTimeoutByNamespace (cluster .clusterClient , gvrPod , opts , addonNamespace , 1 , true , 30 )
62- phase := pods .Items [0 ].Object ["status" ].(map [string ]interface {})["phase" ]
6366
64- return phase .(string ) == "Running"
67+ phase , _ , _ := unstructured .NestedString (pods .Items [0 ].Object , "status" , "phase" )
68+
69+ return phase == "Running"
6570 }, 60 , 1 ).Should (Equal (true ))
6671
6772 By (logPrefix + "showing the config-policy-controller managedclusteraddon as available" )
@@ -84,7 +89,7 @@ var _ = Describe("Test config-policy-controller deployment", func() {
8489 })
8590
8691 It ("should create a config-policy-controller deployment with custom logging levels and concurrency" , func () {
87- for i , cluster := range managedClusterList {
92+ for _ , cluster := range managedClusterList {
8893 logPrefix := cluster .clusterType + " " + cluster .clusterName + ": "
8994 By (logPrefix + "deploying the default config-policy-controller managedclusteraddon" )
9095 Kubectl ("apply" , "-n" , cluster .clusterName , "-f" , case2ManagedClusterAddOnCR )
@@ -117,54 +122,33 @@ var _ = Describe("Test config-policy-controller deployment", func() {
117122 evaluationConcurrencyAnnotation ,
118123 )
119124
120- By (logPrefix + "restarting the config-policy-controller deployment" )
121- Kubectl (
122- "-n" ,
123- addonNamespace ,
124- "rollout" ,
125- "restart" ,
126- "deployments/config-policy-controller" ,
127- fmt .Sprintf ("--kubeconfig=%s%d.kubeconfig" , kubeconfigFilename , i + 1 ),
128- )
129- Kubectl (
130- "-n" ,
131- addonNamespace ,
132- "rollout" ,
133- "status" ,
134- "deployments/config-policy-controller" ,
135- "--watch" ,
136- "--timeout=360s" , // to allow for the 5 minute delay on old k8s
137- fmt .Sprintf ("--kubeconfig=%s%d.kubeconfig" , kubeconfigFilename , i + 1 ),
138- )
139-
140125 By (logPrefix + "verifying the pod has been deployed with a new logging level and concurrency" )
141- opts := metav1.ListOptions {
142- LabelSelector : case2PodSelector ,
143- }
144- pods := ListWithTimeoutByNamespace (cluster .clusterClient , gvrPod , opts , addonNamespace , 1 , true , 60 )
145- phase := pods .Items [0 ].Object ["status" ].(map [string ]interface {})["phase" ]
126+ Eventually (func (g Gomega ) {
127+ opts := metav1.ListOptions {
128+ LabelSelector : case2PodSelector ,
129+ }
130+ pods := ListWithTimeoutByNamespace (cluster .clusterClient , gvrPod , opts , addonNamespace , 1 , true , 60 )
131+ phase := pods .Items [0 ].Object ["status" ].(map [string ]interface {})["phase" ]
146132
147- Expect (phase .(string )).To (Equal ("Running" ))
148- containerList , _ , err := unstructured .NestedSlice (pods .Items [0 ].Object , "spec" , "containers" )
149- if err != nil {
150- panic ( err )
151- }
152- for _ , container := range containerList {
153- if containerObj , ok := container .( map [ string ] interface {}); ok {
154- if Expect (containerObj ).To (HaveKey ("name" )) && containerObj ["name" ] != case2DeploymentName {
133+ g . Expect (phase .(string )).To (Equal ("Running" ))
134+ containerList , _ , err := unstructured .NestedSlice (pods .Items [0 ].Object , "spec" , "containers" )
135+ g . Expect ( err ). To ( BeNil ())
136+ for _ , container := range containerList {
137+ containerObj , ok := container .( map [ string ] interface {})
138+ g . Expect ( ok ). To ( BeTrue ())
139+
140+ if g . Expect (containerObj ).To (HaveKey ("name" )) && containerObj ["name" ] != case2DeploymentName {
155141 continue
156142 }
157- if Expect (containerObj ).To (HaveKey ("args" )) {
143+ if g . Expect (containerObj ).To (HaveKey ("args" )) {
158144 args := containerObj ["args" ]
159- Expect (args ).To (ContainElement ("--log-encoder=console" ))
160- Expect (args ).To (ContainElement ("--log-level=8" ))
161- Expect (args ).To (ContainElement ("--v=6" ))
162- Expect (args ).To (ContainElement ("--evaluation-concurrency=5" ))
145+ g . Expect (args ).To (ContainElement ("--log-encoder=console" ))
146+ g . Expect (args ).To (ContainElement ("--log-level=8" ))
147+ g . Expect (args ).To (ContainElement ("--v=6" ))
148+ g . Expect (args ).To (ContainElement ("--evaluation-concurrency=5" ))
163149 }
164- } else {
165- panic (fmt .Errorf ("containerObj type assertion failed" ))
166150 }
167- }
151+ }, 180 , 10 ). Should ( Succeed ())
168152
169153 By (logPrefix +
170154 "removing the config-policy-controller deployment when the ManagedClusterAddOn CR is removed" )
0 commit comments