Skip to content

Commit

Permalink
Failover controllers now build eviction tasks for purgemode immediately
Browse files Browse the repository at this point in the history
  • Loading branch information
mszacillo committed Nov 25, 2024
1 parent 72cfef5 commit 813f011
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,11 @@ func (c *CRBApplicationFailoverController) evictBinding(binding *workv1alpha2.Cl
switch binding.Spec.Failover.Application.PurgeMode {
case policyv1alpha1.Graciously:
if features.FeatureGate.Enabled(features.GracefulEviction) {
binding.Spec.GracefulEvictCluster(cluster, workv1alpha2.NewTaskOptions(workv1alpha2.WithProducer(CRBApplicationFailoverControllerName), workv1alpha2.WithReason(workv1alpha2.EvictionReasonApplicationFailure), workv1alpha2.WithGracePeriodSeconds(binding.Spec.Failover.Application.GracePeriodSeconds)))
binding.Spec.GracefulEvictCluster(cluster, workv1alpha2.NewTaskOptions(
workv1alpha2.WithPurgeMode(binding.Spec.Failover.Application.PurgeMode),
workv1alpha2.WithProducer(CRBApplicationFailoverControllerName),
workv1alpha2.WithReason(workv1alpha2.EvictionReasonApplicationFailure),
workv1alpha2.WithGracePeriodSeconds(binding.Spec.Failover.Application.GracePeriodSeconds)))
} else {
err := fmt.Errorf("GracefulEviction featureGate must be enabled when purgeMode is %s", policyv1alpha1.Graciously)
klog.Error(err)
Expand All @@ -172,7 +176,11 @@ func (c *CRBApplicationFailoverController) evictBinding(binding *workv1alpha2.Cl
return err
}
case policyv1alpha1.Immediately:
binding.Spec.RemoveCluster(cluster)
binding.Spec.GracefulEvictCluster(cluster, workv1alpha2.NewTaskOptions(
workv1alpha2.WithPurgeMode(binding.Spec.Failover.Application.PurgeMode),
workv1alpha2.WithProducer(CRBApplicationFailoverControllerName),
workv1alpha2.WithReason(workv1alpha2.EvictionReasonApplicationFailure),
workv1alpha2.WithGracePeriodSeconds(binding.Spec.Failover.Application.GracePeriodSeconds)))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,11 @@ func (c *RBApplicationFailoverController) evictBinding(binding *workv1alpha2.Res
switch binding.Spec.Failover.Application.PurgeMode {
case policyv1alpha1.Graciously:
if features.FeatureGate.Enabled(features.GracefulEviction) {
binding.Spec.GracefulEvictCluster(cluster, workv1alpha2.NewTaskOptions(workv1alpha2.WithProducer(RBApplicationFailoverControllerName),
workv1alpha2.WithReason(workv1alpha2.EvictionReasonApplicationFailure), workv1alpha2.WithGracePeriodSeconds(binding.Spec.Failover.Application.GracePeriodSeconds)))
binding.Spec.GracefulEvictCluster(cluster, workv1alpha2.NewTaskOptions(
workv1alpha2.WithPurgeMode(policyv1alpha1.Graciously),
workv1alpha2.WithProducer(RBApplicationFailoverControllerName),
workv1alpha2.WithReason(workv1alpha2.EvictionReasonApplicationFailure),
workv1alpha2.WithGracePeriodSeconds(binding.Spec.Failover.Application.GracePeriodSeconds)))
} else {
err := fmt.Errorf("GracefulEviction featureGate must be enabled when purgeMode is %s", policyv1alpha1.Graciously)
klog.Error(err)
Expand All @@ -174,7 +177,11 @@ func (c *RBApplicationFailoverController) evictBinding(binding *workv1alpha2.Res
return err
}
case policyv1alpha1.Immediately:
binding.Spec.RemoveCluster(cluster)
binding.Spec.GracefulEvictCluster(cluster, workv1alpha2.NewTaskOptions(
workv1alpha2.WithPurgeMode(policyv1alpha1.Immediately),
workv1alpha2.WithProducer(RBApplicationFailoverControllerName),
workv1alpha2.WithReason(workv1alpha2.EvictionReasonApplicationFailure),
workv1alpha2.WithGracePeriodSeconds(binding.Spec.Failover.Application.GracePeriodSeconds)))
}
}

Expand Down
11 changes: 9 additions & 2 deletions pkg/util/helper/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,15 @@ func SetReplicaDivisionPreferenceWeighted(placement *policyv1alpha1.Placement) {
}

// SetDefaultGracePeriodSeconds sets the default value of GracePeriodSeconds in ApplicationFailoverBehavior
// Graciously will default to 600 if a grace period has not been set.
// Immediately will automatically set a grace period of 0 seconds.
func SetDefaultGracePeriodSeconds(behavior *policyv1alpha1.ApplicationFailoverBehavior) {
if behavior.PurgeMode == policyv1alpha1.Graciously && behavior.GracePeriodSeconds == nil {
behavior.GracePeriodSeconds = ptr.To[int32](600)
switch behavior.PurgeMode {
case policyv1alpha1.Graciously:
if behavior.GracePeriodSeconds == nil {
behavior.GracePeriodSeconds = ptr.To[int32](600)
}
case policyv1alpha1.Immediately:
behavior.GracePeriodSeconds = ptr.To[int32](0)
}
}

0 comments on commit 813f011

Please sign in to comment.