Skip to content

Commit

Permalink
review 8 changes
Browse files Browse the repository at this point in the history
Signed-off-by: Kanha gupta <[email protected]>
  • Loading branch information
kanha-gupta committed Apr 24, 2024
1 parent 130283a commit 78dab63
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 65 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/kind.yml
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ jobs:
- name: Create Kind Cluster
run: |
kind create cluster --config ci/kind/config-3nodes.yml
- name: Load docker image into kind
- name: Load Docker images and deploy Antrea
run: |
kind load docker-image antrea/antrea-controller-ubuntu-coverage:latest antrea/antrea-agent-ubuntu-coverage:latest
kubectl apply -f build/yamls/antrea.yml
Expand Down
96 changes: 52 additions & 44 deletions pkg/antctl/raw/check/installation/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ type testContext struct {
config *rest.Config
clusterName string
antreaNamespace string
clientPods *corev1.PodList
echoSameNodePod map[string]string
echoOtherNodePod map[string]string
clientPods []corev1.Pod
echoSameNodePod *corev1.Pod
echoOtherNodePod *corev1.Pod
namespace string
}

Expand All @@ -99,7 +99,7 @@ func Run(o *options) error {
return err
}
for name, test := range testsRegistry {
testContext.Header("Running test: %s\n", name)
testContext.Header("Running test: %s", name)
if err := test.Run(ctx, testContext); err != nil {
testContext.Header("Test %s failed: %s", name, err)
} else {
Expand Down Expand Up @@ -147,22 +147,20 @@ func newDeployment(p deploymentParameters) *appsv1.Deployment {
p.Replicas = 1
}
replicas32 := int32(p.Replicas)
labels := map[string]string{
"name": p.Name,
"kind": p.Role,
}
return &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: p.Name,
Labels: map[string]string{
"name": p.Name,
"kind": p.Role,
},
Name: p.Name,
Labels: labels,
},
Spec: appsv1.DeploymentSpec{
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Name: p.Name,
Labels: map[string]string{
"name": p.Name,
"kind": p.Role,
},
Name: p.Name,
Labels: labels,
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{
Expand All @@ -179,7 +177,8 @@ func newDeployment(p deploymentParameters) *appsv1.Deployment {
Command: p.Command,
},
},
Affinity: p.Affinity,
Affinity: p.Affinity,
Tolerations: p.Tolerations,
},
},
Replicas: &replicas32,
Expand Down Expand Up @@ -217,10 +216,10 @@ func generateRandomNamespace(baseName string) string {
}

func (t *testContext) teardown(ctx context.Context) {
t.Log("Deleting Post installation tests setup...")
t.Log("Deleting post installation tests setup...")
t.client.CoreV1().Namespaces().Delete(ctx, t.namespace, metav1.DeleteOptions{})
t.Log("Waiting for Namespace %s to disappear", t.namespace)
err := wait.PollUntilContextTimeout(ctx, 1*time.Second, 5*time.Minute, true, func(ctx context.Context) (bool, error) {
err := wait.PollUntilContextTimeout(ctx, 2*time.Second, 1*time.Minute, true, func(ctx context.Context) (bool, error) {
_, err := t.client.CoreV1().Namespaces().Get(ctx, t.namespace, metav1.GetOptions{})
if err != nil {
return true, nil
Expand All @@ -240,17 +239,24 @@ func (t *testContext) setup(ctx context.Context) error {
if err != nil {
return fmt.Errorf("unable to determine status of Antrea DaemonSet: %w", err)
}
t.Log("Creating Namespace for Post installation tests...")
t.Log("Creating Namespace %s for post installation tests...", t.namespace)
_, err = t.client.CoreV1().Namespaces().Create(ctx, &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: t.namespace}}, metav1.CreateOptions{})
if err != nil {
return fmt.Errorf("unable to create Namespace %s: %s", t.namespace, err)
}
t.Log("Deploying echo-same-node service...")
t.Log("Deploying echo-same-node Service %s...", echoSameNodeDeploymentName)
svc := newService(echoSameNodeDeploymentName, map[string]string{"name": echoSameNodeDeploymentName}, 80)
_, err = t.client.CoreV1().Services(t.namespace).Create(ctx, svc, metav1.CreateOptions{})
if err != nil {
return err
}
commonToleration := []corev1.Toleration{
{
Key: "node-role.kubernetes.io/control-plane",
Operator: "Exists",
Effect: "NoSchedule",
},
}
echoDeployment := newDeployment(deploymentParameters{
Name: echoSameNodeDeploymentName,
Role: kindEchoName,
Expand All @@ -275,27 +281,29 @@ func (t *testContext) setup(ctx context.Context) error {
},
},
},
Labels: map[string]string{"app": echoSameNodeDeploymentName},
Tolerations: commonToleration,
Labels: map[string]string{"app": echoSameNodeDeploymentName},
})
_, err = t.client.AppsV1().Deployments(t.namespace).Create(ctx, echoDeployment, metav1.CreateOptions{})
if err != nil {
return fmt.Errorf("unable to create Deployment %s: %s", echoSameNodeDeploymentName, err)
}
t.Log("Deploying client Deployment...")
t.Log("Deploying client Deployment %s...", clientDeploymentName)
clientDeployment := newDeployment(deploymentParameters{
Name: clientDeploymentName,
Role: kindClientName,
Image: deploymentImage,
Command: []string{"/agnhost", "pause"},
Port: 80,
Labels: map[string]string{"app": clientDeploymentName},
Name: clientDeploymentName,
Role: kindClientName,
Image: deploymentImage,
Command: []string{"/agnhost", "pause"},
Port: 80,
Tolerations: commonToleration,
Labels: map[string]string{"app": clientDeploymentName},
})
_, err = t.client.AppsV1().Deployments(t.namespace).Create(ctx, clientDeployment, metav1.CreateOptions{})
if err != nil {
return fmt.Errorf("unable to create Deployment %s: %s", clientDeploymentName, err)
}

t.Log("Deploying echo-other-node Service...")
t.Log("Deploying echo-other-node Service %s...", echoOtherNodeDeploymentName)
svc = newService(echoOtherNodeDeploymentName, map[string]string{"name": echoOtherNodeDeploymentName}, 80)
_, err = t.client.CoreV1().Services(t.namespace).Create(ctx, svc, metav1.CreateOptions{})
if err != nil {
Expand All @@ -321,45 +329,45 @@ func (t *testContext) setup(ctx context.Context) error {
},
},
},
Labels: map[string]string{"app": echoOtherNodeDeploymentName},
Tolerations: commonToleration,
Labels: map[string]string{"app": echoOtherNodeDeploymentName},
})
nodes, err := t.client.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{})
nodes, err := t.client.CoreV1().Nodes().List(ctx, metav1.ListOptions{})
if err != nil {
return fmt.Errorf("unable to list Nodes: %s", err)
}
if len(nodes.Items) > 2 {
if len(nodes.Items) >= 2 {
_, err = t.client.AppsV1().Deployments(t.namespace).Create(ctx, echoOtherNodeDeployment, metav1.CreateOptions{})
if err != nil {
return fmt.Errorf("unable to create Deployment %s: %s", echoOtherNodeDeploymentName, err)
}
if err := t.waitForDeploymentsReady(ctx, time.Second, podReadyTimeout, clientDeploymentName, echoSameNodeDeploymentName, echoOtherNodeDeploymentName); err != nil {
return err
}
t.echoOtherNodePod = map[string]string{}
echoOtherNodePod, err := t.client.CoreV1().Pods(t.namespace).List(ctx, metav1.ListOptions{LabelSelector: "name=" + echoOtherNodeDeploymentName})
podList, err := t.client.CoreV1().Pods(t.namespace).List(ctx, metav1.ListOptions{LabelSelector: "name=" + echoOtherNodeDeploymentName})
if err != nil {
return fmt.Errorf("unable to list Echo Other Node Pod: %s", err)
}
for _, echoOtherNodePod := range echoOtherNodePod.Items {
t.echoOtherNodePod[echoOtherNodePod.Name] = echoOtherNodePod.Status.PodIP
if len(podList.Items) > 0 {
t.echoOtherNodePod = &podList.Items[0]
}
} else {
t.Log("Skipping other node Deployments as multiple nodes are not available")
t.Log("skipping other Node Deployments as multiple Nodes are not available")
if err := t.waitForDeploymentsReady(ctx, time.Second, podReadyTimeout, clientDeploymentName, echoSameNodeDeploymentName); err != nil {
return err
}
}
t.clientPods, err = t.client.CoreV1().Pods(t.namespace).List(ctx, metav1.ListOptions{LabelSelector: "kind=" + kindClientName})
podList, err := t.client.CoreV1().Pods(t.namespace).List(ctx, metav1.ListOptions{LabelSelector: "kind=" + kindClientName})
if err != nil {
return fmt.Errorf("unable to list Client Pods: %s", err)
return fmt.Errorf("unable to list client Pods: %s", err)
}
t.echoSameNodePod = map[string]string{}
echoSameNodePod, err := t.client.CoreV1().Pods(t.namespace).List(ctx, metav1.ListOptions{LabelSelector: "name=" + echoSameNodeDeploymentName})
t.clientPods = podList.Items
podList, err = t.client.CoreV1().Pods(t.namespace).List(ctx, metav1.ListOptions{LabelSelector: "name=" + echoSameNodeDeploymentName})
if err != nil {
return fmt.Errorf("unable to list Echo same node Pod: %s", err)
return fmt.Errorf("unable to list Echo Same Node Pod: %s", err)
}
for _, echoSameNodePod := range echoSameNodePod.Items {
t.echoSameNodePod[echoSameNodePod.Name] = echoSameNodePod.Status.PodIP
if len(podList.Items) > 0 {
t.echoSameNodePod = &podList.Items[0]
}
t.Log("Deployment is validated successfully")
return nil
Expand All @@ -371,7 +379,7 @@ func (t *testContext) waitForDeploymentsReady(ctx context.Context, interval, tim
err := wait.PollUntilContextTimeout(ctx, interval, timeout, false, func(ctx context.Context) (bool, error) {
ready, err := check.DeploymentIsReady(ctx, t.client, t.namespace, deployment)
if err != nil {
return false, fmt.Errorf("error checking readiness of deployment %s: %w", deployment, err)
return false, fmt.Errorf("error checking readiness of Deployment %s: %w", deployment, err)
}
return ready, nil
})
Expand Down
6 changes: 3 additions & 3 deletions pkg/antctl/raw/check/installation/test_podtointernet.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ func init() {
}

func (t *PodToInternetConnectivityTest) Run(ctx context.Context, testContext *testContext) error {
for _, clientPod := range testContext.clientPods.Items {
for _, clientPod := range testContext.clientPods {
srcPod := testContext.namespace + "/" + clientPod.Name
testContext.Log("Validating connectivity from pod %s to the world (google.com)...", srcPod)
testContext.Log("Validating connectivity from Pod %s to the world (google.com)...", srcPod)
_, _, err := check.ExecInPod(ctx, testContext.client, testContext.config, testContext.namespace, clientPod.Name, clientDeploymentName, agnhostConnectCommand("google.com:80"))
if err != nil {
return fmt.Errorf("pod %s was not able to connect to google.com: %w", srcPod, err)
return fmt.Errorf("Pod %s was not able to connect to google.com: %w", srcPod, err)
}
testContext.Log("Pod %s was able to connect to google.com", srcPod)
}
Expand Down
20 changes: 10 additions & 10 deletions pkg/antctl/raw/check/installation/test_podtopodinternode.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@ func init() {
}

func (t *PodToPodInterNodeConnectivityTest) Run(ctx context.Context, testContext *testContext) error {
if len(testContext.echoOtherNodePod) == 0 {
return fmt.Errorf("Skipping Inter-Node test because multiple nodes are not available")
if testContext.echoOtherNodePod == nil {
return fmt.Errorf("Skipping Inter-Node test because multiple Nodes are not available")
}
for _, clientPod := range testContext.clientPods.Items {
for echoName, echoIP := range testContext.echoOtherNodePod {
srcPod := testContext.namespace + "/" + clientPod.Name
dstPod := testContext.namespace + "/" + echoName
testContext.Log("Validating from pod %s to pod %s...", srcPod, dstPod)
for _, clientPod := range testContext.clientPods {
srcPod := testContext.namespace + "/" + clientPod.Name
dstPod := testContext.namespace + "/" + testContext.echoOtherNodePod.Name
for _, ipInfo := range testContext.echoOtherNodePod.Status.PodIPs {
echoIP := ipInfo.IP
testContext.Log("Validating from Pod %s to Pod %s...", srcPod, dstPod)
_, _, err := check.ExecInPod(ctx, testContext.client, testContext.config, testContext.namespace, clientPod.Name, "", agnhostConnectCommand(echoIP+":80"))
if err != nil {
return fmt.Errorf("client pod %s was not able to communicate with echo pod %s (%s): %w", clientPod.Name, echoName, echoIP, err)
return fmt.Errorf("client Pod %s was not able to communicate with echo Pod %s (%s): %w", clientPod.Name, testContext.echoOtherNodePod.Name, echoIP, err)
}
testContext.Log("client pod %s was able to communicate with echo pod %s (%s)", clientPod.Name, echoName, echoIP)

testContext.Log("client Pod %s was able to communicate with echo Pod %s (%s)", clientPod.Name, testContext.echoOtherNodePod.Name, echoIP)
}
}
return nil
Expand Down
15 changes: 8 additions & 7 deletions pkg/antctl/raw/check/installation/test_podtopodintranode.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,17 @@ func init() {
}

func (t *PodToPodIntraNodeConnectivityTest) Run(ctx context.Context, testContext *testContext) error {
for _, clientPod := range testContext.clientPods.Items {
for echoName, echoIP := range testContext.echoSameNodePod {
srcPod := testContext.namespace + "/" + clientPod.Name
dstPod := testContext.namespace + "/" + echoName
testContext.Log("Validating from pod %s to pod %s...", srcPod, dstPod)
for _, clientPod := range testContext.clientPods {
srcPod := testContext.namespace + "/" + clientPod.Name
dstPod := testContext.namespace + "/" + testContext.echoSameNodePod.Name
for _, ipInfo := range testContext.echoSameNodePod.Status.PodIPs {
echoIP := ipInfo.IP
testContext.Log("Validating from Pod %s to Pod %s...", srcPod, dstPod)
_, _, err := check.ExecInPod(ctx, testContext.client, testContext.config, testContext.namespace, clientPod.Name, "", agnhostConnectCommand(echoIP+":80"))
if err != nil {
return fmt.Errorf("client pod %s was not able to communicate with echo pod %s (%s): %w", clientPod.Name, echoName, echoIP, err)
return fmt.Errorf("client Pod %s was not able to communicate with echo Pod %s (%s): %w", clientPod.Name, testContext.echoSameNodePod.Name, echoIP, err)
}
testContext.Log("client pod %s was able to communicate with echo pod %s (%s)", clientPod.Name, echoName, echoIP)
testContext.Log("client Pod %s was able to communicate with echo Pod %s (%s)", clientPod.Name, testContext.echoSameNodePod.Name, echoIP)
}
}
return nil
Expand Down

0 comments on commit 78dab63

Please sign in to comment.