Skip to content

Commit 17754df

Browse files
committed
WIP: flag plumbing
Notes: - Some of these parse into a map in their config and then call SetFrom Map -- need to retain ability to pass in via config - Should env enablement be part of "AddFlags" in these components? ``` $ for f in _output/bin/*; do X=$($f --help 2>&1 | grep gates); if [[ -n "$X" ]]; then echo; echo "$f"; echo "$X"; fi; done _output/bin/apiextensions-apiserver --feature-gates mapStringBool 4444 A set of key=value pairs that describe feature gates for alpha/experimental features. Options are: --new-feature-gates mapStringBool A set of key=value pairs that describe feature gates for alpha/experimental features. Options are: _output/bin/e2e_node.test --feature-gates mapStringBool 6666 A set of key=value pairs that describe feature gates for alpha/experimental features. --service-feature-gates mapStringBool 7777 A set of key=value pairs that describe feature gates for alpha/experimental features for API service. _output/bin/kube-aggregator --feature-gates mapStringBool 4444 A set of key=value pairs that describe feature gates for alpha/experimental features. Options are: --new-feature-gates mapStringBool A set of key=value pairs that describe feature gates for alpha/experimental features. Options are: _output/bin/kube-apiserver --feature-gates mapStringBool 4444 A set of key=value pairs that describe feature gates for alpha/experimental features. Options are: --new-feature-gates mapStringBool A set of key=value pairs that describe feature gates for alpha/experimental features. Options are: _output/bin/kube-controller-manager --feature-gates mapStringBool 4444 A set of key=value pairs that describe feature gates for alpha/experimental features. Options are: --new-feature-gates mapStringBool A set of key=value pairs that describe feature gates for alpha/experimental features. Options are: _output/bin/kubelet --feature-gates mapStringBool 3333 A set of key=value pairs that describe feature gates for alpha/experimental features. Options are: --new-feature-gates mapStringBool A set of key=value pairs that describe feature gates for alpha/experimental features. Options are: _output/bin/kube-proxy --feature-gates mapStringBool 1111 A set of key=value pairs that describe feature gates for alpha/experimental features. Options are: --new-feature-gates mapStringBool A set of key=value pairs that describe feature gates for alpha/experimental features. Options are: _output/bin/kube-scheduler --feature-gates mapStringBool 4444 A set of key=value pairs that describe feature gates for alpha/experimental features. Options are: --new-feature-gates mapStringBool A set of key=value pairs that describe feature gates for alpha/experimental features. Options are: ```
1 parent ae307ea commit 17754df

File tree

6 files changed

+17
-0
lines changed

6 files changed

+17
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import (
4545
kubectrlmgrconfigscheme "k8s.io/kubernetes/pkg/controller/apis/config/scheme"
4646
"k8s.io/kubernetes/pkg/controller/garbagecollector"
4747
garbagecollectorconfig "k8s.io/kubernetes/pkg/controller/garbagecollector/config"
48+
"k8s.io/kubernetes/pkg/features"
4849
netutils "k8s.io/utils/net"
4950

5051
// add the kubernetes feature gates
@@ -274,6 +275,8 @@ func (s *KubeControllerManagerOptions) Flags(allControllers []string, disabledBy
274275
fs.StringVar(&s.Master, "master", s.Master, "The address of the Kubernetes API server (overrides any value in kubeconfig).")
275276
fs.StringVar(&s.Generic.ClientConnection.Kubeconfig, "kubeconfig", s.Generic.ClientConnection.Kubeconfig, "Path to kubeconfig file with authorization and master location information (the master location can be overridden by the master flag).")
276277
utilfeature.DefaultMutableFeatureGate.AddFlag(fss.FlagSet("generic"))
278+
features.KubernetesGates().EnablePFlagControl("new-feature-gates", fss.FlagSet("generic"))
279+
features.KubernetesGates().EnableEnvControl("KUBE_FEATURE_", func(err error) { panic(err.Error()) })
277280

278281
return fss
279282
}

cmd/kube-proxy/app/server.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,10 @@ with the apiserver API to configure the proxy.`,
576576
opts.AddFlags(fs)
577577
fs.AddGoFlagSet(goflag.CommandLine) // for --boot-id-file and --machine-id-file
578578

579+
// Enable feature gates
580+
features.KubernetesGates().EnablePFlagControl("new-feature-gates", fs)
581+
features.KubernetesGates().EnableEnvControl("KUBE_FEATURE_", func(err error) { panic(err.Error()) })
582+
579583
_ = cmd.MarkFlagFilename("config", "yaml", "yml", "json")
580584

581585
return cmd

cmd/kube-scheduler/app/options/options.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import (
4545
"k8s.io/component-base/metrics"
4646
"k8s.io/klog/v2"
4747
schedulerappconfig "k8s.io/kubernetes/cmd/kube-scheduler/app/config"
48+
"k8s.io/kubernetes/pkg/features"
4849
"k8s.io/kubernetes/pkg/scheduler"
4950
kubeschedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
5051
"k8s.io/kubernetes/pkg/scheduler/apis/config/validation"
@@ -190,6 +191,8 @@ func (o *Options) initFlags() {
190191
o.Deprecated.AddFlags(nfs.FlagSet("deprecated"))
191192
options.BindLeaderElectionFlags(o.LeaderElection, nfs.FlagSet("leader election"))
192193
utilfeature.DefaultMutableFeatureGate.AddFlag(nfs.FlagSet("feature gate"))
194+
features.KubernetesGates().EnablePFlagControl("new-feature-gates", nfs.FlagSet("generic"))
195+
features.KubernetesGates().EnableEnvControl("KUBE_FEATURE_", func(err error) { panic(err.Error()) })
193196
o.Metrics.AddFlags(nfs.FlagSet("metrics"))
194197
logsapi.AddFlags(o.Logs, nfs.FlagSet("logs"))
195198

cmd/kubelet/app/server.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,10 @@ is checked every 20 seconds (also configurable with a flag).`,
289289
options.AddGlobalFlags(cleanFlagSet)
290290
cleanFlagSet.BoolP("help", "h", false, fmt.Sprintf("help for %s", cmd.Name()))
291291

292+
// Enable feature gates
293+
features.KubernetesGates().EnablePFlagControl("new-feature-gates", cleanFlagSet)
294+
features.KubernetesGates().EnableEnvControl("KUBE_FEATURE_", func(err error) { panic(err.Error()) })
295+
292296
// ugly, but necessary, because Cobra's default UsageFunc and HelpFunc pollute the flagset with global flags
293297
const usageFmt = "Usage:\n %s\n\nFlags:\n%s"
294298
cmd.SetUsageFunc(func(cmd *cobra.Command) error {
@@ -373,6 +377,7 @@ func kubeletConfigFlagPrecedence(kc *kubeletconfiginternal.KubeletConfiguration,
373377
fs := newFakeFlagSet(newFlagSetWithGlobals())
374378
// register throwaway KubeletFlags
375379
options.NewKubeletFlags().AddFlags(fs)
380+
features.KubernetesGates().EnablePFlagControl("new-feature-gates", fs)
376381
// register new KubeletConfiguration
377382
options.AddKubeletConfigFlags(fs, kc)
378383
// Remember original feature gates, so we can merge with flag gates later

staging/src/k8s.io/cloud-provider/options/options.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ func (o *CloudControllerManagerOptions) Flags(allControllers []string, disabledB
165165
fs.StringVar(&o.Generic.ClientConnection.Kubeconfig, "kubeconfig", o.Generic.ClientConnection.Kubeconfig, "Path to kubeconfig file with authorization and master location information (the master location can be overridden by the master flag).")
166166
fs.DurationVar(&o.NodeStatusUpdateFrequency.Duration, "node-status-update-frequency", o.NodeStatusUpdateFrequency.Duration, "Specifies how often the controller updates nodes' status.")
167167
utilfeature.DefaultMutableFeatureGate.AddFlag(fss.FlagSet("generic"))
168+
//FIXME: what gateset(s) should this use?
168169

169170
return fss
170171
}

staging/src/k8s.io/sample-apiserver/pkg/cmd/server/start.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ func NewCommandStartWardleServer(ctx context.Context, defaults *WardleServerOpti
9595
flags := cmd.Flags()
9696
o.RecommendedOptions.AddFlags(flags)
9797
utilfeature.DefaultMutableFeatureGate.AddFlag(flags)
98+
//FIXME: what gateset(s) should this use?
9899

99100
return cmd
100101
}

0 commit comments

Comments
 (0)