Skip to content

Commit 0cdd003

Browse files
committed
WIP: flag plumbing
Notes: Some of these parse into a map in their config and then call SetFromMap -- need to retain ability to pass in via config. Option 1: make a `feature.EnableMapControl()` Option 2: pass map into `feature.EnablePFlagControl()` Option 3: `feature.GetAllGates(feature.FromFlags(flagName), feature.FromEnv(prefix))` This is probablay most correct today and makes validation easy, since we do it exactly once. A little awkward with any dynamic source (e.g. API). Should env enablement be part of "AddFlags" logic in these components? It's a little muddy how apps are configured. ``` $ for f in _output/bin/*; do X=$($f --help 2>&1 | grep gates); if [[ -z "$X" ]]; then X=$($f init --help 2>&1 | grep gates); fi; 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/kubeadm --feature-gates string 2222 A set of key=value pairs that describe feature gates for various 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-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 0cdd003

File tree

9 files changed

+37
-0
lines changed

9 files changed

+37
-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/kubeadm/app/cmd/init.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ func newCmdInit(out io.Writer, initOptions *initOptions) *cobra.Command {
139139
initOptions.bto.AddTTLFlag(cmd.Flags())
140140
options.AddImageMetaFlags(cmd.Flags(), &initOptions.externalClusterCfg.ImageRepository)
141141

142+
// Enable feature gates
143+
features.Gates().EnablePFlagControl("new-feature-gates", cmd.Flags())
144+
features.Gates().EnableEnvControl("KUBE_FEATURE_", func(err error) { panic(err.Error()) })
145+
142146
// defines additional flag that are not used by the init command but that could be eventually used
143147
// by the sub-commands automatically generated for phases
144148
initRunner.SetAdditionalFlags(func(flags *flag.FlagSet) {

cmd/kubeadm/app/cmd/upgrade/upgrade.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/options"
2626
cmdutil "k8s.io/kubernetes/cmd/kubeadm/app/cmd/util"
2727
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
28+
"k8s.io/kubernetes/cmd/kubeadm/app/features"
2829
)
2930

3031
// applyPlanFlags holds the values for the common flags in `kubeadm upgrade apply` and `kubeadm upgrade plan`
@@ -73,4 +74,8 @@ func addApplyPlanFlags(fs *pflag.FlagSet, flags *applyPlanFlags) {
7374
fs.BoolVar(&flags.printConfig, "print-config", flags.printConfig, "Specifies whether the configuration file that will be used in the upgrade should be printed or not.")
7475
options.AddFeatureGatesStringFlag(fs, &flags.featureGatesString)
7576
options.AddIgnorePreflightErrorsFlag(fs, &flags.ignorePreflightErrors)
77+
78+
// Enable feature gates
79+
features.Gates().EnablePFlagControl("new-feature-gates", fs)
80+
features.Gates().EnableEnvControl("KUBE_FEATURE_", func(err error) { panic(err.Error()) })
7681
}

cmd/kubeadm/app/features/features.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"k8s.io/apimachinery/pkg/util/version"
2828
"k8s.io/component-base/featuregate"
2929
"k8s.io/klog/v2"
30+
"k8s.io/utils/feature"
3031
)
3132

3233
const (
@@ -42,6 +43,16 @@ const (
4243
WaitForAllControlPlaneComponents = "WaitForAllControlPlaneComponents"
4344
)
4445

46+
var (
47+
// This is the composed set of gates that kubadm exposes.
48+
kubeadmGates = &feature.GateSet{}
49+
)
50+
51+
// Gates returns the set of feature gates exposed by this library.
52+
func Gates() *feature.GateSet {
53+
return kubeadmGates
54+
}
55+
4556
// InitFeatureGates are the default feature gates for the init command
4657
var InitFeatureGates = FeatureList{
4758
PublicKeysECDSA: {

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)