Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabling service connectivity tests in Post-installation testing framework #6313

Merged
merged 2 commits into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Loading