|
| 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 | +}) |
0 commit comments