Skip to content

Commit f927eb2

Browse files
authored
Merge pull request #5943 from nojnhuh/ilb-flake
Retry more error conditions in ILB e2e test
2 parents 5cc81a9 + 3324bc2 commit f927eb2

File tree

1 file changed

+39
-44
lines changed

1 file changed

+39
-44
lines changed

test/e2e/azure_apiserver_ilb.go

Lines changed: 39 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ import (
9999
v1 "k8s.io/api/apps/v1"
100100
corev1 "k8s.io/api/core/v1"
101101
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
102+
"k8s.io/apimachinery/pkg/labels"
102103
"k8s.io/apimachinery/pkg/runtime"
103104
"k8s.io/apimachinery/pkg/runtime/schema"
104105
"k8s.io/apimachinery/pkg/util/wait"
@@ -254,6 +255,22 @@ func AzureAPIServerILBSpec(ctx context.Context, inputGetter func() AzureAPIServe
254255
},
255256
},
256257
Spec: corev1.PodSpec{
258+
Affinity: &corev1.Affinity{
259+
NodeAffinity: &corev1.NodeAffinity{
260+
RequiredDuringSchedulingIgnoredDuringExecution: &corev1.NodeSelector{
261+
NodeSelectorTerms: []corev1.NodeSelectorTerm{
262+
{
263+
MatchExpressions: []corev1.NodeSelectorRequirement{
264+
{
265+
Key: "node-role.kubernetes.io/control-plane",
266+
Operator: corev1.NodeSelectorOpDoesNotExist,
267+
},
268+
},
269+
},
270+
},
271+
},
272+
},
273+
},
257274
Containers: []corev1.Container{
258275
{
259276
Name: "node-debug",
@@ -303,67 +320,42 @@ func AzureAPIServerILBSpec(ctx context.Context, inputGetter func() AzureAPIServe
303320
err = workloadClusterClient.Create(ctx, nodeDebugDS)
304321
Expect(err).NotTo(HaveOccurred())
305322

323+
WaitForDaemonset(ctx, WaitForDaemonsetInput{
324+
DaemonSet: nodeDebugDS,
325+
Getter: workloadClusterClient,
326+
Clientset: workloadClusterClientSet,
327+
}, e2eConfig.GetIntervals(specName, "wait-daemonset")...)
328+
306329
backoff = wait.Backoff{
307330
Duration: 100 * time.Second,
308331
Factor: 0.5,
309332
Jitter: 0.5,
310333
Steps: 5,
311334
}
312335
retryDSFn := func(ctx context.Context) (bool, error) {
313-
defer GinkgoRecover()
314-
315-
By("Saving all the nodes")
316-
allNodes := &corev1.NodeList{}
317-
err = workloadClusterClient.List(ctx, allNodes)
318-
if err != nil {
319-
return false, fmt.Errorf("failed to list nodes in the workload cluster: %v", err)
320-
}
321-
322-
if len(allNodes.Items) == 0 {
323-
return false, fmt.Errorf("no nodes found in the workload cluster")
324-
}
325-
326-
By("Saving all the worker nodes")
327-
workerNodes := make(map[string]corev1.Node, 0)
328-
for i, node := range allNodes.Items {
329-
if strings.Contains(node.Name, input.ClusterName+"-md-0") {
330-
workerNodes[node.Name] = allNodes.Items[i]
331-
}
332-
}
333-
if len(workerNodes) != int(input.ExpectedWorkerNodes) {
334-
return false, fmt.Errorf("expected number of worker nodes: %d, got: %d", input.ExpectedWorkerNodes, len(workerNodes))
335-
}
336-
337336
By("Saving all the node-debug pods running on the worker nodes")
338-
allNodeDebugPods, err := workloadClusterClientSet.CoreV1().Pods("default").List(ctx, metav1.ListOptions{
339-
LabelSelector: "app=node-debug",
337+
workerDSPods, err := workloadClusterClientSet.CoreV1().Pods(nodeDebugDS.Namespace).List(ctx, metav1.ListOptions{
338+
LabelSelector: labels.FormatLabels(nodeDebugDS.Spec.Selector.MatchLabels),
340339
})
341340
if err != nil {
342-
return false, fmt.Errorf("failed to list node-debug pods in the workload cluster: %v", err)
341+
Logf("failed to list node-debug pods in the workload cluster: %v", err)
342+
return false, nil
343343
}
344344

345-
workerDSPods := make(map[string]corev1.Pod, 0)
346345
workerDSPodsTestResult := make(map[string]bool, 0)
347-
for _, daemonsetPod := range allNodeDebugPods.Items {
348-
if _, ok := workerNodes[daemonsetPod.Spec.NodeName]; ok {
349-
workerDSPods[daemonsetPod.Name] = daemonsetPod
350-
workerDSPodsTestResult[daemonsetPod.Name] = false
351-
}
352-
}
353-
if len(workerDSPods) != int(input.ExpectedWorkerNodes) {
354-
return false, fmt.Errorf("expected number of worker node-debug daemonset pods: %d, got: %d", input.ExpectedWorkerNodes, len(workerDSPods))
346+
for _, daemonsetPod := range workerDSPods.Items {
347+
workerDSPodsTestResult[daemonsetPod.Name] = false
355348
}
356-
357349
By("Getting the kubeconfig path for the workload cluster")
358350
workloadClusterKubeConfigPath := workloadClusterProxy.GetKubeconfigPath()
359351
workloadClusterKubeConfig, err := clientcmd.BuildConfigFromFlags("", workloadClusterKubeConfigPath)
360-
361352
if err != nil {
362-
return false, fmt.Errorf("failed to build workload cluster kubeconfig from flags: %v", err)
353+
Logf("failed to build workload cluster kubeconfig from flags: %v", err)
354+
return false, nil
363355
}
364356

365-
Logf("Number of node debug pods deployed on worker nodes: %v\n", len(workerDSPods))
366-
for _, nodeDebugPod := range workerDSPods {
357+
Logf("Number of node debug pods deployed on worker nodes: %v\n", len(workerDSPods.Items))
358+
for _, nodeDebugPod := range workerDSPods.Items {
367359
Logf("node-debug pod %v is deployed on node %v\n", nodeDebugPod.Name, nodeDebugPod.Spec.NodeName)
368360

369361
By("Checking the status of the node-debug pod")
@@ -374,7 +366,8 @@ func AzureAPIServerILBSpec(ctx context.Context, inputGetter func() AzureAPIServe
374366
case corev1.PodRunning:
375367
Logf("Pod %s is in Running phase. Proceeding\n", nodeDebugPod.Name)
376368
default:
377-
return false, fmt.Errorf("node-debug pod %s is in an unexpected phase: %v", nodeDebugPod.Name, nodeDebugPod.Status.Phase)
369+
Logf("node-debug pod %s is in an unexpected phase: %v", nodeDebugPod.Name, nodeDebugPod.Status.Phase)
370+
return false, nil
378371
}
379372

380373
helloFromTheNodeDebugPod := "Hello from node-debug pod"
@@ -408,7 +401,8 @@ func AzureAPIServerILBSpec(ctx context.Context, inputGetter func() AzureAPIServe
408401
Logf("Creating executor for the pod %s using the URL %v\n", nodeDebugPod.Name, execRequest.URL())
409402
exec, err := remotecommand.NewSPDYExecutor(workloadClusterKubeConfig, "POST", execRequest.URL())
410403
if err != nil {
411-
return false, fmt.Errorf("failed to create executor: %v", err)
404+
Logf("failed to create executor: %v", err)
405+
return false, nil
412406
}
413407

414408
By("Streaming stdout/err from the daemonset")
@@ -420,7 +414,8 @@ func AzureAPIServerILBSpec(ctx context.Context, inputGetter func() AzureAPIServe
420414
Tty: false,
421415
})
422416
if err != nil {
423-
return false, fmt.Errorf("failed to stream stdout/err from the daemonset: %v", err)
417+
Logf("failed to stream stdout/err from the daemonset: %v", err)
418+
return false, nil
424419
}
425420
output := stdout.String()
426421
Logf("Captured output:\n%s\n", output)

0 commit comments

Comments
 (0)