Merge pull request #5030 from XiShanYongYe-Chang/remedy-e2e-errors

fixes an issue where the cluster-status-controller overwrites the remedyActions field
This commit is contained in:
karmada-bot 2024-06-12 16:12:40 +08:00 committed by GitHub
commit 2ed4d77a06
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 24 additions and 9 deletions

View File

@ -79,7 +79,7 @@ func (c *RemedyController) Reconcile(ctx context.Context, req controllerruntime.
klog.Errorf("Failed to sync cluster(%s) remedy actions: %v", cluster.Name, err)
return controllerruntime.Result{}, err
}
klog.V(4).Infof("Success to sync cluster(%s) remedy actions", cluster.Name)
klog.V(4).Infof("Success to sync cluster(%s) remedy actions: %v", cluster.Name, actions)
return controllerruntime.Result{}, nil
}

View File

@ -278,7 +278,11 @@ func (c *ClusterStatusController) updateStatusIfNeeded(cluster *clusterv1alpha1.
klog.V(4).Infof("Start to update cluster status: %s", cluster.Name)
err := retry.RetryOnConflict(retry.DefaultRetry, func() (err error) {
_, err = helper.UpdateStatus(context.Background(), c.Client, cluster, func() error {
cluster.Status = currentClusterStatus
cluster.Status.KubernetesVersion = currentClusterStatus.KubernetesVersion
cluster.Status.APIEnablements = currentClusterStatus.APIEnablements
cluster.Status.Conditions = currentClusterStatus.Conditions
cluster.Status.NodeSummary = currentClusterStatus.NodeSummary
cluster.Status.ResourceSummary = currentClusterStatus.ResourceSummary
return nil
})
return err

View File

@ -45,6 +45,9 @@ var _ = framework.SerialDescribe("remedy testing", func() {
remedy = &remedyv1alpha1.Remedy{
ObjectMeta: metav1.ObjectMeta{Name: remedyName},
Spec: remedyv1alpha1.RemedySpec{
ClusterAffinity: &remedyv1alpha1.ClusterAffinity{
ClusterNames: []string{targetCluster},
},
DecisionMatches: []remedyv1alpha1.DecisionMatch{
{
ClusterConditionMatch: &remedyv1alpha1.ClusterConditionRequirement{
@ -74,9 +77,10 @@ var _ = framework.SerialDescribe("remedy testing", func() {
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
})
ginkgo.By("wait cluster status has TrafficControl RemedyAction", func() {
ginkgo.By(fmt.Sprintf("wait Cluster(%s) status has TrafficControl RemedyAction", targetCluster), func() {
framework.WaitClusterFitWith(controlPlaneClient, targetCluster, func(cluster *clusterv1alpha1.Cluster) bool {
actions := sets.NewString(cluster.Status.RemedyActions...)
fmt.Printf("Cluster(%s) remedyActions: %v\n", cluster.Name, actions)
return actions.Has(string(remedyv1alpha1.TrafficControl))
})
})
@ -93,9 +97,10 @@ var _ = framework.SerialDescribe("remedy testing", func() {
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
})
ginkgo.By("wait cluster status doesn't has TrafficControl RemedyAction", func() {
ginkgo.By(fmt.Sprintf("wait Cluster(%s) status doesn't has TrafficControl RemedyAction", targetCluster), func() {
framework.WaitClusterFitWith(controlPlaneClient, targetCluster, func(cluster *clusterv1alpha1.Cluster) bool {
actions := sets.NewString(cluster.Status.RemedyActions...)
fmt.Printf("Cluster(%s) remedyActions: %v\n", cluster.Name, actions)
return !actions.Has(string(remedyv1alpha1.TrafficControl))
})
})
@ -118,9 +123,10 @@ var _ = framework.SerialDescribe("remedy testing", func() {
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
})
ginkgo.By("wait cluster status has TrafficControl RemedyAction", func() {
ginkgo.By(fmt.Sprintf("wait Cluster(%s) status has TrafficControl RemedyAction", targetCluster), func() {
framework.WaitClusterFitWith(controlPlaneClient, targetCluster, func(cluster *clusterv1alpha1.Cluster) bool {
actions := sets.NewString(cluster.Status.RemedyActions...)
fmt.Printf("Cluster(%s) remedyActions: %v\n", cluster.Name, actions)
return actions.Has(string(remedyv1alpha1.TrafficControl))
})
})
@ -129,9 +135,10 @@ var _ = framework.SerialDescribe("remedy testing", func() {
karmadaresource.RemoveRemedy(karmadaClient, remedyName)
})
ginkgo.By("wait cluster status doesn't has TrafficControl RemedyAction", func() {
ginkgo.By(fmt.Sprintf("wait Cluster(%s) status doesn't has TrafficControl RemedyAction", targetCluster), func() {
framework.WaitClusterFitWith(controlPlaneClient, targetCluster, func(cluster *clusterv1alpha1.Cluster) bool {
actions := sets.NewString(cluster.Status.RemedyActions...)
fmt.Printf("Cluster(%s) remedyActions: %v\n", cluster.Name, actions)
return !actions.Has(string(remedyv1alpha1.TrafficControl))
})
})
@ -157,10 +164,12 @@ var _ = framework.SerialDescribe("remedy testing", func() {
remedy = &remedyv1alpha1.Remedy{
ObjectMeta: metav1.ObjectMeta{Name: remedyName},
Spec: remedyv1alpha1.RemedySpec{
ClusterAffinity: &remedyv1alpha1.ClusterAffinity{
ClusterNames: []string{targetCluster},
},
Actions: []remedyv1alpha1.RemedyAction{remedyv1alpha1.TrafficControl},
},
}
})
ginkgo.It("Create an immediately type remedy, then remove it", func() {
@ -168,9 +177,10 @@ var _ = framework.SerialDescribe("remedy testing", func() {
karmadaresource.CreateRemedy(karmadaClient, remedy)
})
ginkgo.By("wait cluster status has TrafficControl RemedyAction", func() {
ginkgo.By(fmt.Sprintf("wait Cluster(%s) status has TrafficControl RemedyAction", targetCluster), func() {
framework.WaitClusterFitWith(controlPlaneClient, targetCluster, func(cluster *clusterv1alpha1.Cluster) bool {
actions := sets.NewString(cluster.Status.RemedyActions...)
fmt.Printf("Cluster(%s) remedyActions: %v\n", cluster.Name, actions)
return actions.Has(string(remedyv1alpha1.TrafficControl))
})
})
@ -179,9 +189,10 @@ var _ = framework.SerialDescribe("remedy testing", func() {
karmadaresource.RemoveRemedy(karmadaClient, remedyName)
})
ginkgo.By("wait cluster status doesn't has TrafficControl RemedyAction", func() {
ginkgo.By(fmt.Sprintf("wait Cluster(%s) status doesn't has TrafficControl RemedyAction", targetCluster), func() {
framework.WaitClusterFitWith(controlPlaneClient, targetCluster, func(cluster *clusterv1alpha1.Cluster) bool {
actions := sets.NewString(cluster.Status.RemedyActions...)
fmt.Printf("Cluster(%s) remedyActions: %v\n", cluster.Name, actions)
return !actions.Has(string(remedyv1alpha1.TrafficControl))
})
})