From 4612a414a020b09856a2fef849e4e7a56cb12432 Mon Sep 17 00:00:00 2001 From: jpayne3506 Date: Wed, 24 Jan 2024 11:50:35 -0600 Subject: [PATCH] chore: address comments --- test/internal/kubernetes/utils.go | 3 +++ test/validate/linux_validate.go | 6 ++++-- test/validate/validate.go | 14 +++++++------- test/validate/windows_validate.go | 4 +++- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/test/internal/kubernetes/utils.go b/test/internal/kubernetes/utils.go index 6323fa8c6a3..48ffcdb14e7 100644 --- a/test/internal/kubernetes/utils.go +++ b/test/internal/kubernetes/utils.go @@ -489,6 +489,9 @@ func RestartKubeProxyService(ctx context.Context, clientset *kubernetes.Clientse return errors.Wrapf(err, "failed to get privileged pod on node %s", node.Name) } + if len(pod.Items) == 0 { + return errors.Errorf("there are no privileged pods on node - %v", node.Name) + } privilegedPod := pod.Items[0] // exec into the pod and restart kubeproxy _, err = ExecCmdOnPod(ctx, clientset, privilegedNamespace, privilegedPod.Name, restartKubeProxyCmd, config) diff --git a/test/validate/linux_validate.go b/test/validate/linux_validate.go index ecd9f0b0745..ed9c919eb27 100644 --- a/test/validate/linux_validate.go +++ b/test/validate/linux_validate.go @@ -214,11 +214,13 @@ func (v *Validator) validateRestartNetwork(ctx context.Context) error { continue } // get the privileged pod - pod, err := acnk8s.GetPodsByNode(ctx, v.clientset, privilegedNamespace, privilegedLabelSelector, nodes.Items[index].Name) + pod, err := acnk8s.GetPodsByNode(ctx, v.clientset, privilegedNamespace, privilegedLabelSelector, node.Name) if err != nil { return errors.Wrapf(err, "failed to get privileged pod") } - + if len(pod.Items) == 0 { + return errors.Errorf("there are no privileged pods on node - %v", node.Name) + } privilegedPod := pod.Items[0] // exec into the pod to get the state file _, err = acnk8s.ExecCmdOnPod(ctx, v.clientset, privilegedNamespace, privilegedPod.Name, restartNetworkCmd, v.config) diff --git a/test/validate/validate.go b/test/validate/validate.go index 243900c9c0f..5e5dc536f8b 100644 --- a/test/validate/validate.go +++ b/test/validate/validate.go @@ -73,17 +73,14 @@ func CreateValidator(ctx context.Context, clientset *kubernetes.Clientset, confi switch os { case "windows": checks = windowsChecksMap[cni] - case "linux": - checks = linuxChecksMap[cni] - default: - return nil, errors.Errorf("unsupported os: %s", os) - } - - if os == "windows" { err := acnk8s.RestartKubeProxyService(ctx, clientset, privilegedNamespace, privilegedLabelSelector, config) if err != nil { return nil, errors.Wrapf(err, "failed to restart kubeproxy") } + case "linux": + checks = linuxChecksMap[cni] + default: + return nil, errors.Errorf("unsupported os: %s", os) } return &Validator{ @@ -138,6 +135,9 @@ func (v *Validator) validateIPs(ctx context.Context, stateFileIps stateFileIpsFu if err != nil { return errors.Wrapf(err, "failed to get privileged pod") } + if len(pod.Items) == 0 { + return errors.Errorf("there are no privileged pods on node - %v", nodes.Items[index].Name) + } podName := pod.Items[0].Name // exec into the pod to get the state file result, err := acnk8s.ExecCmdOnPod(ctx, v.clientset, namespace, podName, cmd, v.config) diff --git a/test/validate/windows_validate.go b/test/validate/windows_validate.go index c6bcf306970..437bb0a1adb 100644 --- a/test/validate/windows_validate.go +++ b/test/validate/windows_validate.go @@ -204,7 +204,9 @@ func validateHNSNetworkState(ctx context.Context, nodes *corev1.NodeList, client if err != nil { return errors.Wrap(err, "failed to get privileged pod") } - + if len(pod.Items) == 0 { + return errors.Errorf("there are no privileged pods on node - %v", nodes.Items[index].Name) + } podName := pod.Items[0].Name // exec into the pod to get the state file result, err := acnk8s.ExecCmdOnPod(ctx, clientset, privilegedNamespace, podName, hnsNetworkCmd, restConfig)