Skip to content

Commit

Permalink
Enabling service connectivity tests in Post-installation testing fram…
Browse files Browse the repository at this point in the history
…ework (#6313)

Signed-off-by: Kanha gupta <[email protected]>
  • Loading branch information
kanha-gupta authored May 11, 2024
1 parent 28b88b3 commit 1b0cf55
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 7 deletions.
13 changes: 6 additions & 7 deletions pkg/antctl/raw/check/installation/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,13 +331,6 @@ func (t *testContext) setup(ctx context.Context) error {
if err != nil {
return fmt.Errorf("unable to create Deployment %s: %s", clientDeploymentName, err)
}

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 {
return err
}
echoOtherNodeDeployment := newDeployment(deploymentParameters{
Name: echoOtherNodeDeploymentName,
Role: kindEchoName,
Expand Down Expand Up @@ -366,6 +359,12 @@ func (t *testContext) setup(ctx context.Context) error {
return fmt.Errorf("unable to list Nodes: %s", err)
}
if len(nodes.Items) >= 2 {
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 {
return err
}
_, 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)
Expand Down
44 changes: 44 additions & 0 deletions pkg/antctl/raw/check/installation/test_podtoserviceinternode.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright 2024 Antrea Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package installation

import (
"context"
"fmt"

"antrea.io/antrea/pkg/antctl/raw/check"
)

type PodToServiceInterNodeConnectivityTest struct{}

func init() {
RegisterTest("pod-to-service-internode-connectivity", &PodToServiceInterNodeConnectivityTest{})
}

func (t *PodToServiceInterNodeConnectivityTest) Run(ctx context.Context, testContext *testContext) error {
if testContext.echoOtherNodePod == nil {
return newNotRunnableError("Inter-Node test requires multiple Nodes")
}
service := echoOtherNodeDeploymentName
for _, clientPod := range testContext.clientPods {
testContext.Log("Validating from Pod %s to Service %s in Namespace %s...", clientPod.Name, service, testContext.namespace)
_, _, err := check.ExecInPod(ctx, testContext.client, testContext.config, testContext.namespace, clientPod.Name, "", agnhostConnectCommand(service, "80"))
if err != nil {
return fmt.Errorf("client Pod %s was not able to communicate with Service %s", clientPod.Name, service)
}
testContext.Log("client Pod %s was able to communicate with Service %s", clientPod.Name, service)
}
return nil
}
41 changes: 41 additions & 0 deletions pkg/antctl/raw/check/installation/test_podtoserviceintranode.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2024 Antrea Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package installation

import (
"context"
"fmt"

"antrea.io/antrea/pkg/antctl/raw/check"
)

type PodToServiceIntraNodeConnectivityTest struct{}

func init() {
RegisterTest("pod-to-service-intranode-connectivity", &PodToServiceIntraNodeConnectivityTest{})
}

func (t *PodToServiceIntraNodeConnectivityTest) Run(ctx context.Context, testContext *testContext) error {
service := echoSameNodeDeploymentName
for _, clientPod := range testContext.clientPods {
testContext.Log("Validating from Pod %s to Service %s in Namespace %s...", clientPod.Name, service, testContext.namespace)
_, _, err := check.ExecInPod(ctx, testContext.client, testContext.config, testContext.namespace, clientPod.Name, "", agnhostConnectCommand(service, "80"))
if err != nil {
return fmt.Errorf("client Pod %s was not able to communicate with Service %s", clientPod.Name, service)
}
testContext.Log("client Pod %s was able to communicate with Service %s", clientPod.Name, service)
}
return nil
}

0 comments on commit 1b0cf55

Please sign in to comment.