Skip to content

Commit 26abce8

Browse files
add e2e for remedy
Signed-off-by: changzhen <[email protected]>
1 parent a8c6723 commit 26abce8

File tree

3 files changed

+149
-0
lines changed

3 files changed

+149
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
Copyright 2024 The Karmada Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package karmada
18+
19+
import (
20+
"context"
21+
"fmt"
22+
23+
"github.com/onsi/ginkgo/v2"
24+
"github.com/onsi/gomega"
25+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
26+
27+
remedyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/remedy/v1alpha1"
28+
karmada "github.com/karmada-io/karmada/pkg/generated/clientset/versioned"
29+
)
30+
31+
// CreateRemedy create Remedy with karmada client.
32+
func CreateRemedy(client karmada.Interface, remedy *remedyv1alpha1.Remedy) {
33+
ginkgo.By(fmt.Sprintf("Creating Remedy(%s)", remedy.Name), func() {
34+
_, err := client.RemedyV1alpha1().Remedies().Create(context.TODO(), remedy, metav1.CreateOptions{})
35+
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
36+
})
37+
}
38+
39+
// RemoveRemedy delete Remedy with karmada client.
40+
func RemoveRemedy(client karmada.Interface, name string) {
41+
err := client.RemedyV1alpha1().Remedies().Delete(context.TODO(), name, metav1.DeleteOptions{})
42+
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
43+
}

test/e2e/remedy_test.go

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
Copyright 2024 The Karmada Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package e2e
18+
19+
import (
20+
"context"
21+
22+
"github.com/onsi/ginkgo/v2"
23+
"github.com/onsi/gomega"
24+
"k8s.io/apimachinery/pkg/api/meta"
25+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
26+
"k8s.io/apimachinery/pkg/util/rand"
27+
28+
clusterv1alpha1 "github.com/karmada-io/karmada/pkg/apis/cluster/v1alpha1"
29+
remedyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/remedy/v1alpha1"
30+
"github.com/karmada-io/karmada/test/e2e/framework"
31+
karmadaresource "github.com/karmada-io/karmada/test/e2e/framework/resource/karmada"
32+
)
33+
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
39+
40+
ginkgo.BeforeEach(func() {
41+
targetCluster = framework.ClusterNames()[0]
42+
remedyName = remedyNamePrefix + rand.String(RandomStrLength)
43+
remedy = &remedyv1alpha1.Remedy{
44+
ObjectMeta: metav1.ObjectMeta{Name: remedyName},
45+
Spec: remedyv1alpha1.RemedySpec{
46+
DecisionMatches: []remedyv1alpha1.DecisionMatch{
47+
{
48+
ClusterConditionMatch: &remedyv1alpha1.ClusterConditionRequirement{
49+
ConditionType: remedyv1alpha1.ServiceDomainNameResolutionReady,
50+
Operator: remedyv1alpha1.ClusterConditionEqual,
51+
ConditionStatus: string(metav1.ConditionFalse),
52+
},
53+
},
54+
},
55+
Actions: []remedyv1alpha1.RemedyAction{remedyv1alpha1.TrafficControl},
56+
},
57+
}
58+
59+
karmadaresource.CreateRemedy(karmadaClient, remedy)
60+
})
61+
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+
clusterObj, err := karmadaClient.ClusterV1alpha1().Clusters().Get(context.TODO(), targetCluster, metav1.GetOptions{})
65+
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
66+
67+
meta.SetStatusCondition(&clusterObj.Status.Conditions, metav1.Condition{
68+
Type: string(remedyv1alpha1.ServiceDomainNameResolutionReady),
69+
Status: metav1.ConditionFalse,
70+
})
71+
_, err = karmadaClient.ClusterV1alpha1().Clusters().UpdateStatus(context.TODO(), clusterObj, metav1.UpdateOptions{})
72+
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
73+
})
74+
75+
ginkgo.By("wait cluster status has TrafficControl RemedyAction", func() {
76+
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
83+
})
84+
})
85+
86+
ginkgo.By("recover cluster ServiceDomainNameResolutionReady to true", func() {
87+
clusterObj, err := karmadaClient.ClusterV1alpha1().Clusters().Get(context.TODO(), targetCluster, metav1.GetOptions{})
88+
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
89+
90+
meta.SetStatusCondition(&clusterObj.Status.Conditions, metav1.Condition{
91+
Type: string(remedyv1alpha1.ServiceDomainNameResolutionReady),
92+
Status: metav1.ConditionFalse,
93+
})
94+
_, err = karmadaClient.ClusterV1alpha1().Clusters().UpdateStatus(context.TODO(), clusterObj, metav1.UpdateOptions{})
95+
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
96+
})
97+
})
98+
99+
ginkgo.It("The domain name resolution function of the cluster encounters an exception, then remove the remedy resource", func() {})
100+
})
101+
102+
ginkgo.Context("test with nil decision matches remedy", func() {
103+
104+
})
105+
})

test/e2e/suite_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ const (
8181
ppNamePrefix = "pp-"
8282
cppNamePrefix = "cpp-"
8383
workloadRebalancerPrefix = "rebalancer-"
84+
remedyNamePrefix = "remedy-"
8485

8586
updateDeploymentReplicas = 2
8687
updateStatefulSetReplicas = 2

0 commit comments

Comments
 (0)