Skip to content

Commit

Permalink
Review 5 changes
Browse files Browse the repository at this point in the history
Signed-off-by: Kanha gupta <kanhag4163@gmail.com>
  • Loading branch information
kanha-gupta committed May 10, 2024
1 parent 0a0801f commit 888d39b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 20 deletions.
25 changes: 17 additions & 8 deletions pkg/antctl/raw/check/cluster/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand All @@ -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),
}
}

Expand Down
16 changes: 7 additions & 9 deletions pkg/antctl/raw/check/cluster/test_checkcniexistence.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,20 @@ 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 {
testContext.Log("No files present in /etc/cni/net.d in Node %s", testContext.testPod.Spec.NodeName)
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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/antctl/raw/check/cluster/test_checkovsloadable.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 888d39b

Please sign in to comment.