@@ -17,7 +17,6 @@ import (
1717
1818 "k8s.io/apimachinery/pkg/runtime"
1919 "k8s.io/apimachinery/pkg/util/yaml"
20- "k8s.io/client-go/kubernetes"
2120 "k8s.io/klog/v2"
2221 nodehelper "k8s.io/kubernetes/test/e2e/framework/node"
2322 e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper"
@@ -258,49 +257,27 @@ func MonitorClusterOperators(oc *exutil.CLI, timeout time.Duration, pollInterval
258257func EnsureTNFDegradedOrSkip (oc * exutil.CLI ) {
259258 SkipIfNotTopology (oc , v1 .DualReplicaTopologyMode )
260259
261- ctx := context . Background ( )
262- kubeClient := oc . AdminKubeClient ( )
260+ nodeList , err := GetNodes ( oc , LabelNodeRoleControlPlane )
261+ o . Expect ( err ). NotTo ( o . HaveOccurred (), "failed to list master nodes" )
263262
264- masters , err := ListControlPlaneNodes (ctx , kubeClient )
265- o .Expect (err ).NotTo (o .HaveOccurred (), "failed to list control-plane nodes" )
263+ masters := nodeList .Items
266264
267265 if len (masters ) != 2 {
268266 g .Skip (fmt .Sprintf (
269- "TNF degraded tests expect exactly 2 control-plane nodes, found %d" ,
267+ "expect exactly 2 master nodes, found %d" ,
270268 len (masters ),
271269 ))
272270 }
273271
274272 readyCount := CountReadyNodes (masters )
275273 if readyCount != 1 {
276274 g .Skip (fmt .Sprintf (
277- "cluster is not in TNF degraded mode (expected exactly 1 Ready master, got %d)" ,
275+ "cluster is not TNF degraded mode (expected exactly 1 Ready master node , got %d)" ,
278276 readyCount ,
279277 ))
280278 }
281279}
282280
283- // ListControlPlaneNodes returns all nodes labeled as control-plane or master.
284- func ListControlPlaneNodes (ctx context.Context , client kubernetes.Interface ) ([]corev1.Node , error ) {
285- nodes , err := client .CoreV1 ().Nodes ().List (ctx , metav1.ListOptions {
286- LabelSelector : "node-role.kubernetes.io/master" ,
287- })
288- if err != nil {
289- return nil , err
290- }
291- if len (nodes .Items ) > 0 {
292- return nodes .Items , nil
293- }
294-
295- nodes , err = client .CoreV1 ().Nodes ().List (ctx , metav1.ListOptions {
296- LabelSelector : "node-role.kubernetes.io/control-plane" ,
297- })
298- if err != nil {
299- return nil , err
300- }
301- return nodes .Items , nil
302- }
303-
304281// CountReadyNodes returns the number of nodes in Ready state.
305282func CountReadyNodes (nodes []corev1.Node ) int {
306283 ready := 0
@@ -320,16 +297,26 @@ func GetReadyMasterNode(
320297 ctx context.Context ,
321298 oc * exutil.CLI ,
322299) (* corev1.Node , error ) {
323- nodes , err := ListControlPlaneNodes ( ctx , oc . AdminKubeClient () )
300+ nodeList , err := GetNodes ( oc , LabelNodeRoleControlPlane )
324301 if err != nil {
325302 return nil , err
326303 }
327- for i := range nodes {
328- node := & nodes [i ]
329- if IsNodeReady ( oc , node . Name ) {
304+ for i := range nodeList . Items {
305+ node := & nodeList . Items [i ]
306+ if isNodeObjReady ( nodeList . Items [ i ] ) {
330307 return node , nil
331308 }
332309 }
333310
334- return nil , fmt .Errorf ("no Ready master node found" )
311+ return nil , fmt .Errorf ("no Ready control-plane node found" )
312+ }
313+
314+ // check ready condition on an existing Node object.
315+ func isNodeObjReady (node corev1.Node ) bool {
316+ for _ , c := range node .Status .Conditions {
317+ if c .Type == corev1 .NodeReady {
318+ return c .Status == corev1 .ConditionTrue
319+ }
320+ }
321+ return false
335322}
0 commit comments