Skip to content

Commit 795dca6

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

File tree

6 files changed

+23
-20
lines changed

6 files changed

+23
-20
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: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import (
2121
"k8s.io/apimachinery/pkg/util/validation/field"
2222
)
2323

24-
// FailoverOptions holds the Failover configurations.
25-
type FailoverOptions struct {
24+
// ClusterFailoverOptions holds the Cluster Failover configurations.
25+
type ClusterFailoverOptions struct {
2626
// EnableNoExecuteTaintEviction enables controller response to NoExecute taints on clusters,
2727
// which triggers eviction of workloads without explicit tolerations.
2828
EnableNoExecuteTaintEviction bool
@@ -39,8 +39,8 @@ type FailoverOptions struct {
3939
ResourceEvictionRate float32
4040
}
4141

42-
// AddFlags adds flags related to FailoverOptions for controller manager to the specified FlagSet.
43-
func (o *FailoverOptions) AddFlags(flags *pflag.FlagSet) {
42+
// AddFlags adds flags related to ClusterFailoverOptions for controller manager to the specified FlagSet.
43+
func (o *ClusterFailoverOptions) AddFlags(flags *pflag.FlagSet) {
4444
if o == nil {
4545
return
4646
}
@@ -51,9 +51,9 @@ func (o *FailoverOptions) AddFlags(flags *pflag.FlagSet) {
5151
}
5252

5353
// Validate checks FailoverOptions and return a slice of found errs.
54-
func (o *FailoverOptions) Validate() field.ErrorList {
54+
func (o *ClusterFailoverOptions) Validate() field.ErrorList {
5555
errs := field.ErrorList{}
56-
rootPath := field.NewPath("FailoverOptions")
56+
rootPath := field.NewPath("ClusterFailoverOptions")
5757

5858
if o.EnableNoExecuteTaintEviction &&
5959
o.NoExecuteTaintEvictionPurgeMode != "Gracefully" &&

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)