-
Notifications
You must be signed in to change notification settings - Fork 360
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
antctl: improve Pod-To-Service connectivity check (#6411)
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
Showing
3 changed files
with
66 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
41
pkg/antctl/raw/check/installation/test_podtoserviceinternode.go
This file was deleted.
Oops, something went wrong.
38 changes: 0 additions & 38 deletions
38
pkg/antctl/raw/check/installation/test_podtoserviceintranode.go
This file was deleted.
Oops, something went wrong.