Merge pull request #4959 from XiShanYongYe-Chang/add-empty-judgement

[Cleanup] Add empty judgment for placement in taint-manager
This commit is contained in:
karmada-bot 2024-05-21 21:24:43 +08:00 committed by GitHub
commit 21b3ffec82
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 20 additions and 2 deletions

View File

@ -144,6 +144,8 @@ func (tc *NoExecuteTaintManager) syncBindingEviction(key util.QueueKey) error {
return fmt.Errorf("invalid key") return fmt.Errorf("invalid key")
} }
cluster := fedKey.Cluster cluster := fedKey.Cluster
klog.V(4).Infof("Begin to sync ResourceBinding(%s) with taintManager for Cluster(%s)",
fedKey.ClusterWideKey.NamespaceKey(), cluster)
binding := &workv1alpha2.ResourceBinding{} binding := &workv1alpha2.ResourceBinding{}
if err := tc.Client.Get(context.TODO(), types.NamespacedName{Namespace: fedKey.Namespace, Name: fedKey.Name}, binding); err != nil { if err := tc.Client.Get(context.TODO(), types.NamespacedName{Namespace: fedKey.Namespace, Name: fedKey.Name}, binding); err != nil {
@ -179,6 +181,8 @@ func (tc *NoExecuteTaintManager) syncBindingEviction(key util.QueueKey) error {
klog.ErrorS(err, "Failed to update binding", "binding", klog.KObj(binding)) klog.ErrorS(err, "Failed to update binding", "binding", klog.KObj(binding))
return err return err
} }
klog.V(2).Infof("Success to evict Cluster(%s) from ResourceBinding(%s) schedule result",
fedKey.ClusterWideKey.NamespaceKey(), fedKey.Cluster)
if !features.FeatureGate.Enabled(features.GracefulEviction) { if !features.FeatureGate.Enabled(features.GracefulEviction) {
helper.EmitClusterEvictionEventForResourceBinding(binding, cluster, tc.EventRecorder, nil) helper.EmitClusterEvictionEventForResourceBinding(binding, cluster, tc.EventRecorder, nil)
} }
@ -196,6 +200,8 @@ func (tc *NoExecuteTaintManager) syncClusterBindingEviction(key util.QueueKey) e
return fmt.Errorf("invalid key") return fmt.Errorf("invalid key")
} }
cluster := fedKey.Cluster cluster := fedKey.Cluster
klog.V(4).Infof("Begin to sync ClusterResourceBinding(%s) with taintManager for Cluster(%s)",
fedKey.ClusterWideKey.NamespaceKey(), cluster)
binding := &workv1alpha2.ClusterResourceBinding{} binding := &workv1alpha2.ClusterResourceBinding{}
if err := tc.Client.Get(context.TODO(), types.NamespacedName{Name: fedKey.Name}, binding); err != nil { if err := tc.Client.Get(context.TODO(), types.NamespacedName{Name: fedKey.Name}, binding); err != nil {
@ -231,6 +237,8 @@ func (tc *NoExecuteTaintManager) syncClusterBindingEviction(key util.QueueKey) e
klog.ErrorS(err, "Failed to update cluster binding", "binding", binding.Name) klog.ErrorS(err, "Failed to update cluster binding", "binding", binding.Name)
return err return err
} }
klog.V(2).Infof("Success to evict Cluster(%s) from ClusterResourceBinding(%s) schedule result",
fedKey.ClusterWideKey.NamespaceKey(), fedKey.Cluster)
if !features.FeatureGate.Enabled(features.GracefulEviction) { if !features.FeatureGate.Enabled(features.GracefulEviction) {
helper.EmitClusterEvictionEventForClusterResourceBinding(binding, cluster, tc.EventRecorder, nil) helper.EmitClusterEvictionEventForClusterResourceBinding(binding, cluster, tc.EventRecorder, nil)
} }
@ -245,11 +253,17 @@ func (tc *NoExecuteTaintManager) syncClusterBindingEviction(key util.QueueKey) e
// needEviction returns whether the binding should be evicted from target cluster right now. // needEviction returns whether the binding should be evicted from target cluster right now.
// If a toleration time is found, we return false along with a minimum toleration time as the // If a toleration time is found, we return false along with a minimum toleration time as the
// second return value. // second return value.
func (tc *NoExecuteTaintManager) needEviction(clusterName string, appliedPlacement map[string]string) (bool, time.Duration, error) { func (tc *NoExecuteTaintManager) needEviction(clusterName string, annotations map[string]string) (bool, time.Duration, error) {
placement, err := helper.GetAppliedPlacement(appliedPlacement) placement, err := helper.GetAppliedPlacement(annotations)
if err != nil { if err != nil {
return false, -1, err return false, -1, err
} }
// Under normal circumstances, placement will not be empty,
// but when the default scheduler is not used, coordination problems may occur.
// Therefore, in order to make the method more robust, add the empty judgement.
if placement == nil {
return false, -1, fmt.Errorf("the applied placement for ResourceBining can not be empty")
}
cluster := &clusterv1alpha1.Cluster{} cluster := &clusterv1alpha1.Cluster{}
if err = tc.Client.Get(context.TODO(), types.NamespacedName{Name: clusterName}, cluster); err != nil { if err = tc.Client.Get(context.TODO(), types.NamespacedName{Name: clusterName}, cluster); err != nil {

View File

@ -92,6 +92,8 @@ func (c *CRBGracefulEvictionController) syncBinding(binding *workv1alpha2.Cluste
} }
for _, cluster := range evictedClusters { for _, cluster := range evictedClusters {
klog.V(2).Infof("Success to evict Cluster(%s) from ClusterResourceBinding(%s) gracefulEvictionTasks",
cluster, binding.Name)
helper.EmitClusterEvictionEventForClusterResourceBinding(binding, cluster, c.EventRecorder, err) helper.EmitClusterEvictionEventForClusterResourceBinding(binding, cluster, c.EventRecorder, err)
} }
return nextRetry(keptTask, c.GracefulEvictionTimeout, metav1.Now().Time), nil return nextRetry(keptTask, c.GracefulEvictionTimeout, metav1.Now().Time), nil

View File

@ -92,6 +92,8 @@ func (c *RBGracefulEvictionController) syncBinding(binding *workv1alpha2.Resourc
} }
for _, cluster := range evictedCluster { for _, cluster := range evictedCluster {
klog.V(2).Infof("Success to evict Cluster(%s) from ResourceBinding(%s/%s) gracefulEvictionTasks",
cluster, binding.Namespace, binding.Name)
helper.EmitClusterEvictionEventForResourceBinding(binding, cluster, c.EventRecorder, err) helper.EmitClusterEvictionEventForResourceBinding(binding, cluster, c.EventRecorder, err)
} }
return nextRetry(keptTask, c.GracefulEvictionTimeout, metav1.Now().Time), nil return nextRetry(keptTask, c.GracefulEvictionTimeout, metav1.Now().Time), nil