@@ -18,25 +18,27 @@ package e2e
18
18
19
19
import (
20
20
"context"
21
+ "fmt"
21
22
22
23
"github.com/onsi/ginkgo/v2"
23
24
"github.com/onsi/gomega"
24
25
"k8s.io/apimachinery/pkg/api/meta"
25
26
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
26
27
"k8s.io/apimachinery/pkg/util/rand"
28
+ "k8s.io/apimachinery/pkg/util/sets"
27
29
28
30
clusterv1alpha1 "github.com/karmada-io/karmada/pkg/apis/cluster/v1alpha1"
29
31
remedyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/remedy/v1alpha1"
30
32
"github.com/karmada-io/karmada/test/e2e/framework"
31
33
karmadaresource "github.com/karmada-io/karmada/test/e2e/framework/resource/karmada"
32
34
)
33
35
34
- var _ = ginkgo .Describe ("remedy testing" , func () {
35
- ginkgo .Context ("remedy.spec.decisionMatches is not empty" , func () {
36
- var remedyName string
37
- var remedy * remedyv1alpha1.Remedy
38
- var targetCluster string
36
+ var _ = framework .SerialDescribe ("remedy testing" , func () {
37
+ var remedyName string
38
+ var remedy * remedyv1alpha1.Remedy
39
+ var targetCluster string
39
40
41
+ ginkgo .Context ("remedy.spec.decisionMatches is not empty" , func () {
40
42
ginkgo .BeforeEach (func () {
41
43
targetCluster = framework .ClusterNames ()[0 ]
42
44
remedyName = remedyNamePrefix + rand .String (RandomStrLength )
@@ -59,8 +61,8 @@ var _ = ginkgo.Describe("remedy testing", func() {
59
61
karmadaresource .CreateRemedy (karmadaClient , remedy )
60
62
})
61
63
62
- ginkgo .It ("The domain name resolution function of the cluster encounters an exception and recover" , func () {
63
- ginkgo .By ("update cluster ServiceDomainNameResolutionReady condition to false" , func () {
64
+ ginkgo .It ("Cluster domain name resolution function encounters an exception and recover" , func () {
65
+ ginkgo .By (fmt . Sprintf ( "update Cluster(%s) %s condition to false" , targetCluster , remedyv1alpha1 . ServiceDomainNameResolutionReady ) , func () {
64
66
clusterObj , err := karmadaClient .ClusterV1alpha1 ().Clusters ().Get (context .TODO (), targetCluster , metav1.GetOptions {})
65
67
gomega .Expect (err ).ShouldNot (gomega .HaveOccurred ())
66
68
@@ -74,32 +76,115 @@ var _ = ginkgo.Describe("remedy testing", func() {
74
76
75
77
ginkgo .By ("wait cluster status has TrafficControl RemedyAction" , func () {
76
78
framework .WaitClusterFitWith (controlPlaneClient , targetCluster , func (cluster * clusterv1alpha1.Cluster ) bool {
77
- for _ , action := range cluster .Status .RemedyActions {
78
- if action == string (remedyv1alpha1 .TrafficControl ) {
79
- return true
80
- }
81
- }
82
- return false
79
+ actions := sets .NewString (cluster .Status .RemedyActions ... )
80
+ return actions .Has (string (remedyv1alpha1 .TrafficControl ))
83
81
})
84
82
})
85
83
86
- ginkgo .By ("recover cluster ServiceDomainNameResolutionReady to true" , func () {
84
+ ginkgo .By (fmt . Sprintf ( "recover Cluster(%s) %s condition to true" , targetCluster , remedyv1alpha1 . ServiceDomainNameResolutionReady ) , func () {
87
85
clusterObj , err := karmadaClient .ClusterV1alpha1 ().Clusters ().Get (context .TODO (), targetCluster , metav1.GetOptions {})
88
86
gomega .Expect (err ).ShouldNot (gomega .HaveOccurred ())
89
87
90
88
meta .SetStatusCondition (& clusterObj .Status .Conditions , metav1.Condition {
91
89
Type : string (remedyv1alpha1 .ServiceDomainNameResolutionReady ),
92
- Status : metav1 .ConditionFalse ,
90
+ Status : metav1 .ConditionTrue ,
93
91
})
94
92
_ , err = karmadaClient .ClusterV1alpha1 ().Clusters ().UpdateStatus (context .TODO (), clusterObj , metav1.UpdateOptions {})
95
93
gomega .Expect (err ).ShouldNot (gomega .HaveOccurred ())
96
94
})
95
+
96
+ ginkgo .By ("wait cluster status doesn't has TrafficControl RemedyAction" , func () {
97
+ framework .WaitClusterFitWith (controlPlaneClient , targetCluster , func (cluster * clusterv1alpha1.Cluster ) bool {
98
+ actions := sets .NewString (cluster .Status .RemedyActions ... )
99
+ return ! actions .Has (string (remedyv1alpha1 .TrafficControl ))
100
+ })
101
+ })
102
+
103
+ ginkgo .By ("cleanup: remove Remedy resource" , func () {
104
+ karmadaresource .RemoveRemedy (karmadaClient , remedyName )
105
+ })
97
106
})
98
107
99
- ginkgo .It ("The domain name resolution function of the cluster encounters an exception, then remove the remedy resource" , func () {})
108
+ ginkgo .It ("Cluster domain name resolution function encounters an exception, then remove the remedy resource" , func () {
109
+ ginkgo .By (fmt .Sprintf ("update Cluster(%s) %s condition to false" , targetCluster , remedyv1alpha1 .ServiceDomainNameResolutionReady ), func () {
110
+ clusterObj , err := karmadaClient .ClusterV1alpha1 ().Clusters ().Get (context .TODO (), targetCluster , metav1.GetOptions {})
111
+ gomega .Expect (err ).ShouldNot (gomega .HaveOccurred ())
112
+
113
+ meta .SetStatusCondition (& clusterObj .Status .Conditions , metav1.Condition {
114
+ Type : string (remedyv1alpha1 .ServiceDomainNameResolutionReady ),
115
+ Status : metav1 .ConditionFalse ,
116
+ })
117
+ _ , err = karmadaClient .ClusterV1alpha1 ().Clusters ().UpdateStatus (context .TODO (), clusterObj , metav1.UpdateOptions {})
118
+ gomega .Expect (err ).ShouldNot (gomega .HaveOccurred ())
119
+ })
120
+
121
+ ginkgo .By ("wait cluster status has TrafficControl RemedyAction" , func () {
122
+ framework .WaitClusterFitWith (controlPlaneClient , targetCluster , func (cluster * clusterv1alpha1.Cluster ) bool {
123
+ actions := sets .NewString (cluster .Status .RemedyActions ... )
124
+ return actions .Has (string (remedyv1alpha1 .TrafficControl ))
125
+ })
126
+ })
127
+
128
+ ginkgo .By ("remove Remedy resource" , func () {
129
+ karmadaresource .RemoveRemedy (karmadaClient , remedyName )
130
+ })
131
+
132
+ ginkgo .By ("wait cluster status doesn't has TrafficControl RemedyAction" , func () {
133
+ framework .WaitClusterFitWith (controlPlaneClient , targetCluster , func (cluster * clusterv1alpha1.Cluster ) bool {
134
+ actions := sets .NewString (cluster .Status .RemedyActions ... )
135
+ return ! actions .Has (string (remedyv1alpha1 .TrafficControl ))
136
+ })
137
+ })
138
+
139
+ ginkgo .By (fmt .Sprintf ("cleanup: recover Cluster(%s) %s to true" , targetCluster , remedyv1alpha1 .ServiceDomainNameResolutionReady ), func () {
140
+ clusterObj , err := karmadaClient .ClusterV1alpha1 ().Clusters ().Get (context .TODO (), targetCluster , metav1.GetOptions {})
141
+ gomega .Expect (err ).ShouldNot (gomega .HaveOccurred ())
142
+
143
+ meta .SetStatusCondition (& clusterObj .Status .Conditions , metav1.Condition {
144
+ Type : string (remedyv1alpha1 .ServiceDomainNameResolutionReady ),
145
+ Status : metav1 .ConditionTrue ,
146
+ })
147
+ _ , err = karmadaClient .ClusterV1alpha1 ().Clusters ().UpdateStatus (context .TODO (), clusterObj , metav1.UpdateOptions {})
148
+ gomega .Expect (err ).ShouldNot (gomega .HaveOccurred ())
149
+ })
150
+ })
100
151
})
101
152
102
153
ginkgo .Context ("test with nil decision matches remedy" , func () {
154
+ ginkgo .BeforeEach (func () {
155
+ targetCluster = framework .ClusterNames ()[0 ]
156
+ remedyName = remedyNamePrefix + rand .String (RandomStrLength )
157
+ remedy = & remedyv1alpha1.Remedy {
158
+ ObjectMeta : metav1.ObjectMeta {Name : remedyName },
159
+ Spec : remedyv1alpha1.RemedySpec {
160
+ Actions : []remedyv1alpha1.RemedyAction {remedyv1alpha1 .TrafficControl },
161
+ },
162
+ }
163
+
164
+ })
165
+
166
+ ginkgo .It ("Create an immediately type remedy, then remove it" , func () {
167
+ ginkgo .By ("create Remedy resource" , func () {
168
+ karmadaresource .CreateRemedy (karmadaClient , remedy )
169
+ })
170
+
171
+ ginkgo .By ("wait cluster status has TrafficControl RemedyAction" , func () {
172
+ framework .WaitClusterFitWith (controlPlaneClient , targetCluster , func (cluster * clusterv1alpha1.Cluster ) bool {
173
+ actions := sets .NewString (cluster .Status .RemedyActions ... )
174
+ return actions .Has (string (remedyv1alpha1 .TrafficControl ))
175
+ })
176
+ })
177
+
178
+ ginkgo .By ("remove Remedy resource" , func () {
179
+ karmadaresource .RemoveRemedy (karmadaClient , remedyName )
180
+ })
103
181
182
+ ginkgo .By ("wait cluster status doesn't has TrafficControl RemedyAction" , func () {
183
+ framework .WaitClusterFitWith (controlPlaneClient , targetCluster , func (cluster * clusterv1alpha1.Cluster ) bool {
184
+ actions := sets .NewString (cluster .Status .RemedyActions ... )
185
+ return ! actions .Has (string (remedyv1alpha1 .TrafficControl ))
186
+ })
187
+ })
188
+ })
104
189
})
105
190
})
0 commit comments