From 3200f3e4c3467164be39421d93e74806d9db00f6 Mon Sep 17 00:00:00 2001 From: Icarus9913 Date: Tue, 30 Jan 2024 11:25:12 +0800 Subject: [PATCH] fix coordinator e2e V00003 Signed-off-by: Icarus9913 --- go.mod | 2 +- go.sum | 4 +-- .../spidercoordinator_test.go | 31 ++++++------------- .../e2eframework/framework/configmap.go | 3 +- .../e2eframework/framework/daemonset.go | 3 +- .../e2eframework/framework/deployment.go | 3 +- .../e2eframework/framework/error.go | 2 +- .../e2eframework/framework/events.go | 4 +-- .../e2eframework/framework/job.go | 3 +- .../e2eframework/framework/replicaset.go | 3 +- .../e2eframework/framework/statefulset.go | 3 +- vendor/modules.txt | 2 +- 12 files changed, 27 insertions(+), 36 deletions(-) diff --git a/go.mod b/go.mod index b415eab0ca..006fd068ec 100644 --- a/go.mod +++ b/go.mod @@ -34,7 +34,7 @@ require ( github.com/sasha-s/go-deadlock v0.3.1 github.com/spf13/cobra v1.7.0 github.com/spf13/pflag v1.0.5 - github.com/spidernet-io/e2eframework v0.0.0-20240127082814-64fbda07e655 + github.com/spidernet-io/e2eframework v0.0.0-20240130031916-71bf7b1ddd00 github.com/tigera/operator v1.32.4 github.com/vishvananda/netlink v1.2.1-beta.2.0.20230621221334-77712cff8739 go.opentelemetry.io/otel v1.21.0 diff --git a/go.sum b/go.sum index 7d10682404..a7f60e8eba 100644 --- a/go.sum +++ b/go.sum @@ -509,8 +509,8 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/viper v1.16.0 h1:rGGH0XDZhdUOryiDWjmIvUSWpbNqisK8Wk0Vyefw8hc= github.com/spf13/viper v1.16.0/go.mod h1:yg78JgCJcbrQOvV9YLXgkLaZqUidkY9K+Dd1FofRzQg= -github.com/spidernet-io/e2eframework v0.0.0-20240127082814-64fbda07e655 h1:l0ZpCKTS/rj1RF0TnbtJBOMyKRt7iurvn7tHm3RUBQM= -github.com/spidernet-io/e2eframework v0.0.0-20240127082814-64fbda07e655/go.mod h1:k0KYxyNjZYyEG1bsGzSbMx5Q+Z1H6oOjEq5qz9UlBzY= +github.com/spidernet-io/e2eframework v0.0.0-20240130031916-71bf7b1ddd00 h1:e6+I4kKloty0a6bV9y1s8lF+Xb3AX+yUdj53J9EsfJw= +github.com/spidernet-io/e2eframework v0.0.0-20240130031916-71bf7b1ddd00/go.mod h1:k0KYxyNjZYyEG1bsGzSbMx5Q+Z1H6oOjEq5qz9UlBzY= github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= diff --git a/test/e2e/spidercoordinator/spidercoordinator_test.go b/test/e2e/spidercoordinator/spidercoordinator_test.go index 72d0433e5c..35656fbf84 100644 --- a/test/e2e/spidercoordinator/spidercoordinator_test.go +++ b/test/e2e/spidercoordinator/spidercoordinator_test.go @@ -6,19 +6,19 @@ import ( "context" "fmt" "reflect" - "strings" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + corev1 "k8s.io/api/core/v1" + networkingv1 "k8s.io/api/networking/v1alpha1" + "k8s.io/utils/ptr" + "sigs.k8s.io/controller-runtime/pkg/client" + "github.com/spidernet-io/spiderpool/pkg/constant" "github.com/spidernet-io/spiderpool/pkg/coordinatormanager" "github.com/spidernet-io/spiderpool/pkg/ip" spiderpoolv2beta1 "github.com/spidernet-io/spiderpool/pkg/k8s/apis/spiderpool.spidernet.io/v2beta1" "github.com/spidernet-io/spiderpool/test/e2e/common" - corev1 "k8s.io/api/core/v1" - networkingv1 "k8s.io/api/networking/v1alpha1" - "k8s.io/utils/ptr" - "sigs.k8s.io/controller-runtime/pkg/client" ) var _ = Describe("SpiderCoordinator", Label("spidercoordinator", "overlay"), Serial, func() { @@ -257,28 +257,15 @@ var _ = Describe("SpiderCoordinator", Label("spidercoordinator", "overlay"), Ser deployObject.Spec.Template.Annotations = annotations ctx, cancel := context.WithTimeout(context.Background(), common.PodStartTimeout) defer cancel() - podList, err := common.CreateDeployUntilExpectedReplicas(frame, deployObject, ctx) Expect(err).NotTo(HaveOccurred()) - ctx, cancel = context.WithTimeout(context.Background(), common.EventOccurTimeout) - defer cancel() + eventCtx, cancel := context.WithTimeout(context.Background(), common.EventOccurTimeout) + defer cancel() errLog := "spidercoordinator: default no ready" for _, pod := range podList.Items { - events, err := frame.GetEvents(ctx, common.OwnerPod, pod.Name, pod.Namespace) - Expect(err).To(Succeed(), "Failed to get pod events: %v", err) - - found := false - for _, event := range events.Items { - if strings.Contains(event.Message, errLog) { - found = true - break - } - } - - if !found { - return false - } + err = frame.WaitExceptEventOccurred(eventCtx, common.OwnerPod, pod.Name, pod.Namespace, errLog) + Expect(err).NotTo(HaveOccurred()) } return true diff --git a/vendor/github.com/spidernet-io/e2eframework/framework/configmap.go b/vendor/github.com/spidernet-io/e2eframework/framework/configmap.go index 4ffd6bedee..78d249e158 100644 --- a/vendor/github.com/spidernet-io/e2eframework/framework/configmap.go +++ b/vendor/github.com/spidernet-io/e2eframework/framework/configmap.go @@ -3,6 +3,7 @@ package framework import ( + "fmt" "github.com/spidernet-io/e2eframework/tools" corev1 "k8s.io/api/core/v1" api_errors "k8s.io/apimachinery/pkg/api/errors" @@ -41,7 +42,7 @@ func (f *Framework) CreateConfigmap(configMap *corev1.ConfigMap, opts ...client. existing := &corev1.ConfigMap{} e := f.GetResource(key, existing) if e == nil && existing.ObjectMeta.DeletionTimestamp == nil { - return ErrAlreadyExisted + return fmt.Errorf("%w: configmap '%s/%s'", ErrAlreadyExisted, existing.Namespace, existing.Name) } t := func() bool { existing := &corev1.ConfigMap{} diff --git a/vendor/github.com/spidernet-io/e2eframework/framework/daemonset.go b/vendor/github.com/spidernet-io/e2eframework/framework/daemonset.go index bd09793050..9c7a7bad49 100644 --- a/vendor/github.com/spidernet-io/e2eframework/framework/daemonset.go +++ b/vendor/github.com/spidernet-io/e2eframework/framework/daemonset.go @@ -4,6 +4,7 @@ package framework import ( "context" + "fmt" "time" "github.com/spidernet-io/e2eframework/tools" @@ -30,7 +31,7 @@ func (f *Framework) CreateDaemonSet(ds *appsv1.DaemonSet, opts ...client.CreateO existing := &appsv1.DaemonSet{} e := f.GetResource(key, existing) if e == nil && existing.ObjectMeta.DeletionTimestamp == nil { - return ErrAlreadyExisted + return fmt.Errorf("%w: daemonset '%s/%s'", ErrAlreadyExisted, existing.Namespace, existing.Name) } t := func() bool { existing := &appsv1.DaemonSet{} diff --git a/vendor/github.com/spidernet-io/e2eframework/framework/deployment.go b/vendor/github.com/spidernet-io/e2eframework/framework/deployment.go index 515f2cc163..f617d9c651 100644 --- a/vendor/github.com/spidernet-io/e2eframework/framework/deployment.go +++ b/vendor/github.com/spidernet-io/e2eframework/framework/deployment.go @@ -5,6 +5,7 @@ package framework import ( "context" "errors" + "fmt" "time" "github.com/spidernet-io/e2eframework/tools" @@ -32,7 +33,7 @@ func (f *Framework) CreateDeployment(dpm *appsv1.Deployment, opts ...client.Crea existing := &appsv1.Deployment{} e := f.GetResource(key, existing) if e == nil && existing.ObjectMeta.DeletionTimestamp == nil { - return ErrAlreadyExisted + return fmt.Errorf("%w: deployment '%s/%s'", ErrAlreadyExisted, existing.Namespace, existing.Name) } t := func() bool { existing := &appsv1.Deployment{} diff --git a/vendor/github.com/spidernet-io/e2eframework/framework/error.go b/vendor/github.com/spidernet-io/e2eframework/framework/error.go index 333219d4f3..21d249655d 100644 --- a/vendor/github.com/spidernet-io/e2eframework/framework/error.go +++ b/vendor/github.com/spidernet-io/e2eframework/framework/error.go @@ -11,4 +11,4 @@ var ErrWatch = errors.New("failed to Watch") var ErrEvent = errors.New("received error event") var ErrResDel = errors.New("resource is deleted") var ErrGetObj = errors.New("failed to get metaObject") -var ErrAlreadyExisted = errors.New("failed to create , a same Controller %v/%v exist") +var ErrAlreadyExisted = errors.New("resource already exists") diff --git a/vendor/github.com/spidernet-io/e2eframework/framework/events.go b/vendor/github.com/spidernet-io/e2eframework/framework/events.go index b92d9d5ff5..aaf7f6a13e 100644 --- a/vendor/github.com/spidernet-io/e2eframework/framework/events.go +++ b/vendor/github.com/spidernet-io/e2eframework/framework/events.go @@ -39,8 +39,6 @@ func (f *Framework) WaitExceptEventOccurred(ctx context.Context, eventKind, objN } f.Log("watch event object %v", event.Object) switch event.Type { - case watch.Error: - return ErrEvent case watch.Deleted: return ErrResDel default: @@ -48,7 +46,7 @@ func (f *Framework) WaitExceptEventOccurred(ctx context.Context, eventKind, objN if !ok { return ErrGetObj } - f.Log("Event occurred message is %v \n", event.Message) + f.Log("Event occurred message is %s/%v \n", event.Type, event.Message) if strings.Contains(event.Message, message) { return nil } diff --git a/vendor/github.com/spidernet-io/e2eframework/framework/job.go b/vendor/github.com/spidernet-io/e2eframework/framework/job.go index c72fd0ccd8..ff58066759 100644 --- a/vendor/github.com/spidernet-io/e2eframework/framework/job.go +++ b/vendor/github.com/spidernet-io/e2eframework/framework/job.go @@ -4,6 +4,7 @@ package framework import ( "context" + "fmt" "time" "github.com/spidernet-io/e2eframework/tools" @@ -30,7 +31,7 @@ func (f *Framework) CreateJob(jb *batchv1.Job, opts ...client.CreateOption) erro existing := &batchv1.Job{} e := f.GetResource(key, existing) if e == nil && existing.ObjectMeta.DeletionTimestamp == nil { - return ErrAlreadyExisted + return fmt.Errorf("%w: job '%s/%s'", ErrAlreadyExisted, existing.Namespace, existing.Name) } t := func() bool { existing := &batchv1.Job{} diff --git a/vendor/github.com/spidernet-io/e2eframework/framework/replicaset.go b/vendor/github.com/spidernet-io/e2eframework/framework/replicaset.go index edfff46ed4..31fa664dfe 100644 --- a/vendor/github.com/spidernet-io/e2eframework/framework/replicaset.go +++ b/vendor/github.com/spidernet-io/e2eframework/framework/replicaset.go @@ -4,6 +4,7 @@ package framework import ( "context" + "fmt" "time" "github.com/spidernet-io/e2eframework/tools" @@ -30,7 +31,7 @@ func (f *Framework) CreateReplicaSet(rs *appsv1.ReplicaSet, opts ...client.Creat existing := &appsv1.ReplicaSet{} e := f.GetResource(key, existing) if e == nil && existing.ObjectMeta.DeletionTimestamp == nil { - return ErrAlreadyExisted + return fmt.Errorf("%w: replicaset '%s/%s'", ErrAlreadyExisted, existing.Namespace, existing.Name) } t := func() bool { existing := &appsv1.ReplicaSet{} diff --git a/vendor/github.com/spidernet-io/e2eframework/framework/statefulset.go b/vendor/github.com/spidernet-io/e2eframework/framework/statefulset.go index 326a112f1c..336c8987dd 100644 --- a/vendor/github.com/spidernet-io/e2eframework/framework/statefulset.go +++ b/vendor/github.com/spidernet-io/e2eframework/framework/statefulset.go @@ -4,6 +4,7 @@ package framework import ( "context" + "fmt" "time" "k8s.io/utils/ptr" @@ -31,7 +32,7 @@ func (f *Framework) CreateStatefulSet(sts *appsv1.StatefulSet, opts ...client.Cr existing := &appsv1.StatefulSet{} e := f.GetResource(key, existing) if e == nil && existing.ObjectMeta.DeletionTimestamp == nil { - return ErrAlreadyExisted + return fmt.Errorf("%w: statefulset '%s/%s'", ErrAlreadyExisted, existing.Namespace, existing.Name) } t := func() bool { existing := &appsv1.StatefulSet{} diff --git a/vendor/modules.txt b/vendor/modules.txt index 8a0c1b1eba..b370477a3d 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -550,7 +550,7 @@ github.com/spf13/viper/internal/encoding/javaproperties github.com/spf13/viper/internal/encoding/json github.com/spf13/viper/internal/encoding/toml github.com/spf13/viper/internal/encoding/yaml -# github.com/spidernet-io/e2eframework v0.0.0-20240127082814-64fbda07e655 +# github.com/spidernet-io/e2eframework v0.0.0-20240130031916-71bf7b1ddd00 ## explicit; go 1.21 github.com/spidernet-io/e2eframework/framework github.com/spidernet-io/e2eframework/tools