-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: bzsuni <[email protected]>
- Loading branch information
Showing
10 changed files
with
707 additions
and
0 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,5 @@ | ||
# E2E Cases for EgressEndpointSlice | ||
|
||
| Case ID | Title | Priority | Smoke | Status | Other | | ||
|---------|--------------------------------------------------------------------------------------------------------------------------------------|----------|-------|--------|-------| | ||
| S00001 | After repeatedly creating and deleting `pods` matched by a specific `policy`, check the egress IP addresses of all `pods` | p2 | false | | | |
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,14 @@ | ||
<!-- | ||
# E2E Cases for EgressEndpointSlice | ||
| Case ID | Title | Priority | Smoke | Status | Other | | ||
|---------|--------------------------------------------------------------------------------------------------------------------------------------|----------|-------|--------|-------| | ||
| S00001 | After repeatedly creating and deleting `pods` matched by a specific `policy`, check the egress IP addresses of all `pods` | p2 | false | | | | ||
--> | ||
|
||
# EgressEndpointSlice E2E 用例 | ||
|
||
| Case ID | Title | Priority | Smoke | Status | Other | | ||
|---------|----------------------------------------------------------------------------------------|----------|-------|--------|-------| | ||
| S00001 | 不断增删 `policy` 所匹配到的 `pods`,几轮增删后,判断所有 `pods` 的出口 `IP` | p2 | false | | | |
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
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,107 @@ | ||
// Copyright 2022 Authors of spidernet-io | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package common | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"time" | ||
|
||
appsv1 "k8s.io/api/apps/v1" | ||
corev1 "k8s.io/api/core/v1" | ||
apiserrors "k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/types" | ||
"k8s.io/utils/ptr" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
|
||
e2eerr "github.com/spidernet-io/egressgateway/test/e2e/err" | ||
) | ||
|
||
func CreateDeploy(ctx context.Context, cli client.Client, name string, image string, repolicas int) (*appsv1.Deployment, error) { | ||
ctx, cancel := context.WithTimeout(ctx, time.Second*20) | ||
defer cancel() | ||
|
||
var terminationGracePeriodSeconds int64 = 0 | ||
|
||
label := map[string]string{"app": name} | ||
res := &appsv1.Deployment{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Namespace: "default", | ||
Name: name, | ||
Labels: label, | ||
}, | ||
Spec: appsv1.DeploymentSpec{ | ||
Replicas: ptr.To[int32](int32(repolicas)), | ||
Selector: &metav1.LabelSelector{MatchLabels: label}, | ||
Template: corev1.PodTemplateSpec{ | ||
ObjectMeta: metav1.ObjectMeta{Labels: label}, | ||
Spec: corev1.PodSpec{ | ||
TerminationGracePeriodSeconds: &terminationGracePeriodSeconds, | ||
Containers: []corev1.Container{{Name: name, | ||
Image: image, | ||
ImagePullPolicy: corev1.PullIfNotPresent, | ||
Command: []string{"/bin/sh", "-c", "sleep infinity"}, | ||
}}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
err := cli.Create(ctx, res) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for { | ||
select { | ||
case <-ctx.Done(): | ||
_ = DeleteObj(context.Background(), cli, res) | ||
return nil, fmt.Errorf("create DaemonSet time out") | ||
default: | ||
err := cli.Get(ctx, types.NamespacedName{Namespace: res.Namespace, Name: res.Name}, res) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
a := *res.Spec.Replicas | ||
b := res.Status.ReadyReplicas | ||
|
||
if a == b && b > 0 { | ||
return res, nil | ||
} | ||
|
||
time.Sleep(time.Second / 2) | ||
} | ||
} | ||
} | ||
|
||
func WaitDeployDeleted(ctx context.Context, cli client.Client, deploy *appsv1.Deployment, timeout time.Duration) error { | ||
ctx, cancel := context.WithTimeout(ctx, timeout) | ||
defer cancel() | ||
|
||
err := DeleteObj(ctx, cli, deploy) | ||
if err != nil { | ||
if apiserrors.IsNotFound(err) { | ||
return nil | ||
} | ||
return err | ||
} | ||
|
||
dp := new(appsv1.Deployment) | ||
|
||
for { | ||
select { | ||
case <-ctx.Done(): | ||
return e2eerr.ErrTimeout | ||
default: | ||
err = cli.Get(ctx, types.NamespacedName{Name: deploy.Name, Namespace: deploy.Namespace}, dp) | ||
if !apiserrors.IsNotFound(err) { | ||
time.Sleep(time.Second / 2) | ||
continue | ||
} | ||
return nil | ||
} | ||
} | ||
} |
Oops, something went wrong.