Skip to content

Commit

Permalink
fix-remedy-e2e-errors
Browse files Browse the repository at this point in the history
Signed-off-by: changzhen <[email protected]>
  • Loading branch information
XiShanYongYe-Chang committed Jun 12, 2024
1 parent 2ad9cbb commit d5a317a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pkg/controllers/remediation/remedy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
6 changes: 5 additions & 1 deletion pkg/controllers/status/cluster_status_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 18 additions & 7 deletions test/e2e/remedy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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))
})
})
Expand All @@ -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))
})
})
Expand All @@ -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))
})
})
Expand All @@ -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))
})
})
Expand All @@ -157,20 +164,23 @@ 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() {
ginkgo.By("create Remedy resource", 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))
})
})
Expand All @@ -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))
})
})
Expand Down

0 comments on commit d5a317a

Please sign in to comment.