Skip to content

Commit

Permalink
Fix get worker node logic for Kubelet config e2e (#8470)
Browse files Browse the repository at this point in the history
  • Loading branch information
mitalipaygude authored Jul 11, 2024
1 parent 120554e commit a5bb950
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions test/framework/kubeletconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package framework

import (
"context"
"strings"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
Expand Down Expand Up @@ -51,17 +50,17 @@ func (e *ClusterE2ETest) ValidateKubeletConfig() {
kubectlClient := buildLocalKubectl()

e.T.Log("Getting control plane nodes for kubelet max pod verification")
nodes, err := kubectlClient.GetControlPlaneNodes(ctx,
cpNodes, err := kubectlClient.GetControlPlaneNodes(ctx,
e.KubeconfigFilePath(),
)
if err != nil {
e.T.Fatalf("Error getting nodes: %v", err)
}
if len(nodes) == 0 {
if len(cpNodes) == 0 {
e.T.Fatalf("no control plane nodes found")
}

got, _ := nodes[0].Status.Capacity.Pods().AsInt64()
got, _ := cpNodes[0].Status.Capacity.Pods().AsInt64()
if got != int64(maxPod50) {
e.T.Fatalf("Node capacity for control plane pods not equal to %v", maxPod50)
}
Expand All @@ -80,20 +79,25 @@ func (e *ClusterE2ETest) ValidateKubeletConfig() {
}

e.T.Log("Getting worker nodes for kubelet max pod verification")
var workerNode corev1.Node
for i := range allNodes {
if strings.Contains(allNodes[i].Name, "-md-") {
workerNode = allNodes[i]
}
}
if err != nil {
e.T.Fatalf("Error getting nodes: %v", err)
}

workerNode := getWorkerNodes(allNodes, cpNodes)
got, _ = workerNode.Status.Capacity.Pods().AsInt64()
if got != int64(maxPod60) {
e.T.Fatalf("Node capacity for worker node pods not equal to %v", maxPod60)
}

e.T.Log("Successfully verified Kubelet Configuration for worker nodes")
}

func getWorkerNodes(all, cpNodes []corev1.Node) *corev1.Node {
cpNodeMap := make(map[string]bool)
for _, node := range cpNodes {
cpNodeMap[node.Name] = true
}

for _, node := range all {
if !cpNodeMap[node.Name] {
return &node
}
}
return nil
}

0 comments on commit a5bb950

Please sign in to comment.