From 888d39b03f04fd6fa04f1ab5e9ca22e6b3e7f9e8 Mon Sep 17 00:00:00 2001 From: Kanha gupta Date: Sat, 11 May 2024 03:06:27 +0530 Subject: [PATCH] Review 5 changes Signed-off-by: Kanha gupta --- pkg/antctl/raw/check/cluster/command.go | 25 +++++++++++++------ .../check/cluster/test_checkcniexistence.go | 16 ++++++------ .../test_checkcontrolplaneavailability.go | 2 +- .../check/cluster/test_checkovsloadable.go | 4 +-- 4 files changed, 27 insertions(+), 20 deletions(-) diff --git a/pkg/antctl/raw/check/cluster/command.go b/pkg/antctl/raw/check/cluster/command.go index 72f622b44e1..8d12fe4c2e3 100644 --- a/pkg/antctl/raw/check/cluster/command.go +++ b/pkg/antctl/raw/check/cluster/command.go @@ -44,11 +44,23 @@ func Command() *cobra.Command { } const ( - testNamespace = "antrea-test" - deploymentName = "cluster-checker" - podReadyTimeout = 1 * time.Minute + testNamespacePrefix = "antrea-test" + deploymentName = "cluster-checker" + podReadyTimeout = 1 * time.Minute ) +type uncertainError struct { + reason string +} + +func (e uncertainError) Error() string { + return fmt.Sprintf("test results are uncertain: %s", e.reason) +} + +func newUncertainError(reason string, a ...interface{}) uncertainError { + return uncertainError{reason: fmt.Sprintf(reason, a...)} +} + type Test interface { Run(ctx context.Context, testContext *testContext) error } @@ -168,10 +180,7 @@ func (t *testContext) setup(ctx context.Context) error { } testPods, err := t.client.CoreV1().Pods(t.namespace).List(ctx, metav1.ListOptions{LabelSelector: "component=cluster-checker"}) if err != nil { - return fmt.Errorf("unable to list test Pod: %s", err) - } - if len(testPods.Items) == 0 { - return fmt.Errorf("unable to list pods") + return fmt.Errorf("no pod found for test Deployment") } t.testPod = &testPods.Items[0] return nil @@ -189,7 +198,7 @@ func NewTestContext(client kubernetes.Interface, config *rest.Config, clusterNam client: client, config: config, clusterName: clusterName, - namespace: check.GenerateRandomNamespace(testNamespace), + namespace: check.GenerateRandomNamespace(testNamespacePrefix), } } diff --git a/pkg/antctl/raw/check/cluster/test_checkcniexistence.go b/pkg/antctl/raw/check/cluster/test_checkcniexistence.go index 5d1a56c7607..9de591887c2 100644 --- a/pkg/antctl/raw/check/cluster/test_checkcniexistence.go +++ b/pkg/antctl/raw/check/cluster/test_checkcniexistence.go @@ -33,7 +33,7 @@ func (t *checkCNIExistence) Run(ctx context.Context, testContext *testContext) e command := []string{"ls", "-1", "/etc/cni/net.d"} output, _, err := check.ExecInPod(ctx, testContext.client, testContext.config, testContext.namespace, testContext.testPod.Name, "", command) if err != nil { - return fmt.Errorf("Failed to execute command in Pod %s, error: %v", testContext.testPod.Name, err) + return fmt.Errorf("failed to execute command in Pod %s, error: %v", testContext.testPod.Name, err) } files := strings.Fields(output) if len(files) == 0 { @@ -41,14 +41,12 @@ func (t *checkCNIExistence) Run(ctx context.Context, testContext *testContext) e return nil } sort.Strings(files) - if len(files) > 0 { - if files[0] < "10-antrea.conflist" { - return fmt.Errorf("Another CNI configuration file with higher priority than Antrea's CNI configuration file found: %s; this may be expected if networkPolicyOnly mode is enabled", files[0]) - } else if files[0] != "10-antrea.conflist" { - testContext.Log("Another CNI configuration file found: %s with Antrea having higher precedence", files[0]) - } else { - testContext.Log("Antrea's CNI configuration file already present: %s", files[0]) - } + if files[0] < "10-antrea.conflist" { + return newUncertainError("another CNI configuration file with higher priority than Antrea's CNI configuration file found: %s; this may be expected if networkPolicyOnly mode is enabled", files[0]) + } else if files[0] != "10-antrea.conflist" { + testContext.Log("Another CNI configuration file found: %s with Antrea having higher precedence", files[0]) + } else { + testContext.Log("Antrea's CNI configuration file already present: %s", files[0]) } return nil } diff --git a/pkg/antctl/raw/check/cluster/test_checkcontrolplaneavailability.go b/pkg/antctl/raw/check/cluster/test_checkcontrolplaneavailability.go index 564344fd7f2..a4a7b1f8295 100644 --- a/pkg/antctl/raw/check/cluster/test_checkcontrolplaneavailability.go +++ b/pkg/antctl/raw/check/cluster/test_checkcontrolplaneavailability.go @@ -41,7 +41,7 @@ func (t *checkControlPlaneAvailability) Run(ctx context.Context, testContext *te } } if controlPlaneNodes.Len() == 0 { - testContext.Log("No control-plane Nodes were found; if installing Antrea in encap mode, some K8s functionalities (API aggregation, apiserver proxy, admission controllers) may be impacted.") + return newUncertainError("No control-plane Nodes were found; if installing Antrea in encap mode, some K8s functionalities (API aggregation, apiserver proxy, admission controllers) may be impacted.") } else { testContext.Log("control-plane Nodes were found in the cluster.") } diff --git a/pkg/antctl/raw/check/cluster/test_checkovsloadable.go b/pkg/antctl/raw/check/cluster/test_checkovsloadable.go index 2ee302da62a..020016622e6 100644 --- a/pkg/antctl/raw/check/cluster/test_checkovsloadable.go +++ b/pkg/antctl/raw/check/cluster/test_checkovsloadable.go @@ -47,12 +47,12 @@ func (c *checkOVSLoadable) Run(ctx context.Context, testContext *testContext) er if err != nil { return fmt.Errorf("error executing modprobe command in Pod %s: %v", testContext.testPod.Name, err) } else if stderr != "" { - return fmt.Errorf("failed to load the OVS kernel module from the container %s, try running 'modprobe openvswitch' on your Nodes", stderr) + return fmt.Errorf("failed to load the OVS kernel module: %s, try running 'modprobe openvswitch' on your Nodes", stderr) } else { testContext.Log("openvswitch kernel module loaded successfully") } } else { - return fmt.Errorf("error encountered while executing modprobe command %s", stderr) + return fmt.Errorf("error encountered while check if cni is existent - stderr: %s", stderr) } return nil }