Skip to content

Commit 1589cb3

Browse files
group cluster failover flags
Signed-off-by: changzhen <[email protected]>
1 parent d8473e1 commit 1589cb3

File tree

6 files changed

+29
-24
lines changed

6 files changed

+29
-24
lines changed

cmd/controller-manager/app/controllermanager.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ func NewControllerManagerCommand(ctx context.Context) *cobra.Command {
117117
opts := options.NewOptions()
118118
opts.AddFlags(genericFlagSet, controllers.ControllerNames(), sets.List(controllersDisabledByDefault))
119119

120+
clusterFailoverFlagSet := fss.FlagSet("cluster failover")
121+
opts.ClusterFailoverOptions.AddFlags(clusterFailoverFlagSet)
122+
120123
cmd := &cobra.Command{
121124
Use: names.KarmadaControllerManagerComponentName,
122125
Long: "The karmada-controller-manager runs various controllers.\n" +
@@ -149,6 +152,7 @@ func NewControllerManagerCommand(ctx context.Context) *cobra.Command {
149152
cmd.AddCommand(sharedcommand.NewCmdVersion(names.KarmadaControllerManagerComponentName))
150153
cmd.Flags().AddFlagSet(genericFlagSet)
151154
cmd.Flags().AddFlagSet(logsFlagSet)
155+
cmd.Flags().AddFlagSet(clusterFailoverFlagSet)
152156

153157
cols, _, _ := term.TerminalSize(cmd.OutOrStdout())
154158
sharedcli.SetUsageAndHelpFunc(cmd, fss, cols)
@@ -297,10 +301,10 @@ func startClusterController(ctx controllerscontext.Context) (enabled bool, err e
297301
ClusterTaintEvictionRetryFrequency: 10 * time.Second,
298302
ConcurrentReconciles: 3,
299303
RateLimiterOptions: ctx.Opts.RateLimiterOptions,
300-
EnableNoExecuteTaintEviction: ctx.Opts.FailoverConfiguration.EnableNoExecuteTaintEviction,
301-
NoExecuteTaintEvictionPurgeMode: ctx.Opts.FailoverConfiguration.NoExecuteTaintEvictionPurgeMode,
304+
EnableNoExecuteTaintEviction: ctx.Opts.ClusterFailoverConfiguration.EnableNoExecuteTaintEviction,
305+
NoExecuteTaintEvictionPurgeMode: ctx.Opts.ClusterFailoverConfiguration.NoExecuteTaintEvictionPurgeMode,
302306
EvictionQueueOptions: cluster.EvictionQueueOptions{
303-
ResourceEvictionRate: ctx.Opts.FailoverConfiguration.ResourceEvictionRate,
307+
ResourceEvictionRate: ctx.Opts.ClusterFailoverConfiguration.ResourceEvictionRate,
304308
},
305309
}
306310
if err := taintManager.SetupWithManager(mgr); err != nil {
@@ -926,7 +930,7 @@ func setupControllers(ctx context.Context, mgr controllerruntime.Manager, opts *
926930
EnableClusterResourceModeling: opts.EnableClusterResourceModeling,
927931
HPAControllerConfiguration: opts.HPAControllerConfiguration,
928932
FederatedResourceQuotaOptions: opts.FederatedResourceQuotaOptions,
929-
FailoverConfiguration: opts.FailoverOptions,
933+
ClusterFailoverConfiguration: opts.ClusterFailoverOptions,
930934
},
931935
Context: ctx,
932936
DynamicClientSet: dynamicClientSet,

cmd/controller-manager/app/options/failover.go renamed to cmd/controller-manager/app/options/cluster_failover.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ package options
1919
import (
2020
"github.com/spf13/pflag"
2121
"k8s.io/apimachinery/pkg/util/validation/field"
22+
23+
policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
2224
)
2325

24-
// FailoverOptions holds the Failover configurations.
25-
type FailoverOptions struct {
26+
// ClusterFailoverOptions holds the Cluster Failover configurations.
27+
type ClusterFailoverOptions struct {
2628
// EnableNoExecuteTaintEviction enables controller response to NoExecute taints on clusters,
2729
// which triggers eviction of workloads without explicit tolerations.
2830
EnableNoExecuteTaintEviction bool
@@ -39,25 +41,25 @@ type FailoverOptions struct {
3941
ResourceEvictionRate float32
4042
}
4143

42-
// AddFlags adds flags related to FailoverOptions for controller manager to the specified FlagSet.
43-
func (o *FailoverOptions) AddFlags(flags *pflag.FlagSet) {
44+
// AddFlags adds flags related to ClusterFailoverOptions for controller manager to the specified FlagSet.
45+
func (o *ClusterFailoverOptions) AddFlags(flags *pflag.FlagSet) {
4446
if o == nil {
4547
return
4648
}
4749

4850
flags.BoolVar(&o.EnableNoExecuteTaintEviction, "enable-no-execute-taint-eviction", false, "Enables controller response to NoExecute taints on clusters, which triggers eviction of workloads without explicit tolerations. Given the impact of eviction caused by NoExecute Taint, this parameter is designed to remain disabled by default and requires careful evaluation by administrators before being enabled.\n")
49-
flags.StringVar(&o.NoExecuteTaintEvictionPurgeMode, "no-execute-taint-eviction-purge-mode", "Gracefully", "Controls resource cleanup behavior for NoExecute-triggered evictions (only active when --enable-no-execute-taint-eviction=true). Supported values are \"Directly\", and \"Gracefully\". \"Directly\" mode directly evicts workloads first (risking temporary service interruption) and then triggers rescheduling to other clusters, while \"Gracefully\" mode first schedules workloads to new clusters and then cleans up original workloads after successful startup elsewhere to ensure service continuity.")
51+
flags.StringVar(&o.NoExecuteTaintEvictionPurgeMode, "no-execute-taint-eviction-purge-mode", string(policyv1alpha1.PurgeModeGracefully), "Controls resource cleanup behavior for NoExecute-triggered evictions (only active when --enable-no-execute-taint-eviction=true). Supported values are \"Directly\", and \"Gracefully\". \"Directly\" mode directly evicts workloads first (risking temporary service interruption) and then triggers rescheduling to other clusters, while \"Gracefully\" mode first schedules workloads to new clusters and then cleans up original workloads after successful startup elsewhere to ensure service continuity.")
5052
flags.Float32Var(&o.ResourceEvictionRate, "resource-eviction-rate", 0.5, "This is the number of resources to be evicted per second in a cluster failover scenario.")
5153
}
5254

53-
// Validate checks FailoverOptions and return a slice of found errs.
54-
func (o *FailoverOptions) Validate() field.ErrorList {
55+
// Validate checks ClusterFailoverOptions and return a slice of found errs.
56+
func (o *ClusterFailoverOptions) Validate() field.ErrorList {
5557
errs := field.ErrorList{}
56-
rootPath := field.NewPath("FailoverOptions")
58+
rootPath := field.NewPath("ClusterFailoverOptions")
5759

5860
if o.EnableNoExecuteTaintEviction &&
59-
o.NoExecuteTaintEvictionPurgeMode != "Gracefully" &&
60-
o.NoExecuteTaintEvictionPurgeMode != "Directly" {
61+
o.NoExecuteTaintEvictionPurgeMode != string(policyv1alpha1.PurgeModeGracefully) &&
62+
o.NoExecuteTaintEvictionPurgeMode != string(policyv1alpha1.PurgeModeDirectly) {
6163
errs = append(errs, field.Invalid(rootPath.Child("NoExecuteTaintEvictionPurgeMode"),
6264
o.NoExecuteTaintEvictionPurgeMode, "Invalid mode"))
6365
}

cmd/controller-manager/app/options/options.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ type Options struct {
146146
EnableClusterResourceModeling bool
147147
// FederatedResourceQuotaOptions holds configurations for FederatedResourceQuota reconciliation.
148148
FederatedResourceQuotaOptions FederatedResourceQuotaOptions
149-
// FailoverOptions holds the Failover configurations.
150-
FailoverOptions FailoverOptions
149+
// ClusterFailoverOptions holds the cluster failover configurations.
150+
ClusterFailoverOptions ClusterFailoverOptions
151151
}
152152

153153
// NewOptions builds an empty options.
@@ -233,7 +233,6 @@ func (o *Options) AddFlags(flags *pflag.FlagSet, allControllers, disabledByDefau
233233
o.ProfileOpts.AddFlags(flags)
234234
o.HPAControllerConfiguration.AddFlags(flags)
235235
o.FederatedResourceQuotaOptions.AddFlags(flags)
236-
o.FailoverOptions.AddFlags(flags)
237236
features.FeatureGate.AddFlag(flags)
238237
}
239238

cmd/controller-manager/app/options/validation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (o *Options) Validate() field.ErrorList {
5656
}
5757

5858
errs = append(errs, o.FederatedResourceQuotaOptions.Validate()...)
59-
errs = append(errs, o.FailoverOptions.Validate()...)
59+
errs = append(errs, o.ClusterFailoverOptions.Validate()...)
6060

6161
return errs
6262
}

cmd/controller-manager/app/options/validation_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,13 @@ func TestValidateControllerManagerConfiguration(t *testing.T) {
101101
}),
102102
expectedErrs: field.ErrorList{field.Invalid(newPath.Child("ClusterStartupGracePeriod"), metav1.Duration{Duration: 0 * time.Second}, "must be greater than 0")},
103103
},
104-
"invalid FailoverOptions": {
104+
"invalid ClusterFailoverOptions": {
105105
opt: New(func(options *Options) {
106-
options.FailoverOptions.EnableNoExecuteTaintEviction = true
107-
options.FailoverOptions.NoExecuteTaintEvictionPurgeMode = ""
106+
options.ClusterFailoverOptions.EnableNoExecuteTaintEviction = true
107+
options.ClusterFailoverOptions.NoExecuteTaintEvictionPurgeMode = ""
108108
}),
109109
expectedErrs: field.ErrorList{
110-
field.Invalid(field.NewPath("FailoverOptions").Child("NoExecuteTaintEvictionPurgeMode"), "", "Invalid mode"),
110+
field.Invalid(field.NewPath("ClusterFailoverOptions").Child("NoExecuteTaintEvictionPurgeMode"), "", "Invalid mode"),
111111
},
112112
},
113113
}

pkg/controllers/context/context.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ type Options struct {
9898
HPAControllerConfiguration federatehpaconfig.HPAControllerConfiguration
9999
// FederatedResourceQuotaOptions holds configurations for FederatedResourceQuota reconciliation.
100100
FederatedResourceQuotaOptions options.FederatedResourceQuotaOptions
101-
// FailoverConfiguration is the config of failover function.
102-
FailoverConfiguration options.FailoverOptions
101+
// ClusterFailoverConfiguration is the config of cluster failover function.
102+
ClusterFailoverConfiguration options.ClusterFailoverOptions
103103
}
104104

105105
// Context defines the context object for controller.

0 commit comments

Comments
 (0)