Skip to content

Commit

Permalink
antctl: improve Pod-To-Service connectivity check (#6411)
Browse files Browse the repository at this point in the history
Service is realized asynchronously, retry a few times before failing the
check.

It also reduces code redundancy between intranode and internode checks.

Signed-off-by: Quan Tian <quan.tian@broadcom.com>
  • Loading branch information
tnqn committed Jun 6, 2024
1 parent 0b24ce0 commit 1543dab
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 79 deletions.
66 changes: 66 additions & 0 deletions pkg/antctl/raw/check/installation/test_podtoservice.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// 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"
"time"

"k8s.io/apimachinery/pkg/util/wait"
)

type PodToServiceConnectivityTest struct {
service string
preRun func(ctx context.Context, testContext *testContext) error
}

func init() {
RegisterTest("pod-to-service-intranode-connectivity", &PodToServiceConnectivityTest{
service: echoSameNodeDeploymentName,
})
RegisterTest("pod-to-service-internode-connectivity", &PodToServiceConnectivityTest{
service: echoOtherNodeDeploymentName,
preRun: func(ctx context.Context, testContext *testContext) error {
if testContext.echoOtherNodePod == nil {
return newNotRunnableError("Inter-Node test requires multiple Nodes")
}
return nil
},
})
}

func (t *PodToServiceConnectivityTest) Run(ctx context.Context, testContext *testContext) error {
if t.preRun != nil {
if err := t.preRun(ctx, testContext); err != nil {
return err
}
}
for _, clientPod := range testContext.clientPods {
testContext.Log("Validating from Pod %s to Service %s in Namespace %s...", clientPod.Name, t.service, testContext.namespace)
// Service is realized asynchronously, retry a few times.
if err := wait.PollUntilContextTimeout(ctx, 500*time.Millisecond, 2*time.Second, true, func(ctx context.Context) (bool, error) {
if err := testContext.runAgnhostConnect(ctx, clientPod.Name, "", t.service, 80); err != nil {
testContext.Log("Client Pod %s was not able to communicate with Service %s: %v, retrying...", clientPod.Name, t.service, err)
return false, nil
}
return true, nil
}); err != nil {
return fmt.Errorf("client Pod %s was not able to communicate with Service %s: %w", clientPod.Name, t.service, err)
}
testContext.Log("Client Pod %s was able to communicate with Service %s", clientPod.Name, t.service)
}
return nil
}
41 changes: 0 additions & 41 deletions pkg/antctl/raw/check/installation/test_podtoserviceinternode.go

This file was deleted.

38 changes: 0 additions & 38 deletions pkg/antctl/raw/check/installation/test_podtoserviceintranode.go

This file was deleted.

0 comments on commit 1543dab

Please sign in to comment.