1
0
Fork 0
mirror of https://github.com/kubernetes-sigs/node-feature-discovery.git synced 2025-03-05 16:27:05 +00:00

nfd-worker: drop deprecated command line flags

Drop the following flags that were deprecated already in v0.8.0:

-sleep-interval  (replaced by core.sleepInterval config file option)
-label-whitelist (replaced by core.labelWhiteList config file option)
-sources         (replaced by -label-sources flag)
This commit is contained in:
Markus Lehtonen 2022-11-22 12:36:32 +02:00
parent ef2c498a6f
commit eb8e29c80a
9 changed files with 14 additions and 120 deletions

View file

@ -84,15 +84,6 @@ func parseArgs(flags *flag.FlagSet, osArgs ...string) *worker.Args {
args.Overrides.FeatureSources = overrides.FeatureSources args.Overrides.FeatureSources = overrides.FeatureSources
case "label-sources": case "label-sources":
args.Overrides.LabelSources = overrides.LabelSources args.Overrides.LabelSources = overrides.LabelSources
case "label-whitelist":
klog.Warningf("-label-whitelist is deprecated, use 'core.labelWhiteList' option in the config file, instead")
args.Overrides.LabelWhiteList = overrides.LabelWhiteList
case "sleep-interval":
klog.Warningf("-sleep-interval is deprecated, use 'core.sleepInterval' option in the config file, instead")
args.Overrides.SleepInterval = overrides.SleepInterval
case "sources":
klog.Warningf("-sources is deprecated, use '-label-sources' flag, instead")
args.Overrides.LabelSources = overrides.LabelSources
} }
}) })
@ -124,7 +115,6 @@ func initFlags(flagset *flag.FlagSet) (*worker.Args, *worker.ConfigOverrideArgs)
// Flags overlapping with config file options // Flags overlapping with config file options
overrides := &worker.ConfigOverrideArgs{ overrides := &worker.ConfigOverrideArgs{
LabelWhiteList: &utils.RegexpVal{},
FeatureSources: &utils.StringSliceVal{}, FeatureSources: &utils.StringSliceVal{},
LabelSources: &utils.StringSliceVal{}, LabelSources: &utils.StringSliceVal{},
} }
@ -136,17 +126,6 @@ func initFlags(flagset *flag.FlagSet) (*worker.Args, *worker.ConfigOverrideArgs)
flagset.Var(overrides.LabelSources, "label-sources", flagset.Var(overrides.LabelSources, "label-sources",
"Comma separated list of label sources. Special value 'all' enables all sources. "+ "Comma separated list of label sources. Special value 'all' enables all sources. "+
"Prefix the source name with '-' to disable it.") "Prefix the source name with '-' to disable it.")
flagset.Var(overrides.LabelWhiteList, "label-whitelist",
"Regular expression to filter label names to publish to the Kubernetes API server. "+
"NB: the label namespace is omitted i.e. the filter is only applied to the name part after '/'. "+
"DEPRECATED: This parameter should be set via the config file.")
overrides.SleepInterval = flagset.Duration("sleep-interval", 0,
"Time to sleep between re-labeling. Non-positive value implies no re-labeling (i.e. infinite sleep). "+
"DEPRECATED: This parameter should be set via the config file")
flagset.Var(overrides.LabelSources, "sources",
"Comma separated list of label sources. Special value 'all' enables all feature sources. "+
"Prefix the source name with '-' to disable it. "+
"DEPRECATED: use -label-sources instead")
return args, overrides return args, overrides
} }

View file

@ -19,7 +19,6 @@ package main
import ( import (
"flag" "flag"
"testing" "testing"
"time"
. "github.com/smartystreets/goconvey/convey" . "github.com/smartystreets/goconvey/convey"
@ -36,8 +35,6 @@ func TestParseArgs(t *testing.T) {
Convey("overrides should be nil", func() { Convey("overrides should be nil", func() {
So(args.Oneshot, ShouldBeTrue) So(args.Oneshot, ShouldBeTrue)
So(args.Overrides.NoPublish, ShouldBeNil) So(args.Overrides.NoPublish, ShouldBeNil)
So(args.Overrides.LabelWhiteList, ShouldBeNil)
So(args.Overrides.SleepInterval, ShouldBeNil)
So(args.Overrides.FeatureSources, ShouldBeNil) So(args.Overrides.FeatureSources, ShouldBeNil)
So(args.Overrides.LabelSources, ShouldBeNil) So(args.Overrides.LabelSources, ShouldBeNil)
}) })
@ -46,18 +43,14 @@ func TestParseArgs(t *testing.T) {
Convey("When all override args are specified", func() { Convey("When all override args are specified", func() {
args := parseArgs(flags, args := parseArgs(flags,
"-no-publish", "-no-publish",
"-label-whitelist=.*rdt.*",
"-feature-sources=cpu", "-feature-sources=cpu",
"-label-sources=fake1,fake2,fake3", "-label-sources=fake1,fake2,fake3")
"-sleep-interval=30s")
Convey("args.sources is set to appropriate values", func() { Convey("args.sources is set to appropriate values", func() {
So(args.Oneshot, ShouldBeFalse) So(args.Oneshot, ShouldBeFalse)
So(*args.Overrides.NoPublish, ShouldBeTrue) So(*args.Overrides.NoPublish, ShouldBeTrue)
So(*args.Overrides.SleepInterval, ShouldEqual, 30*time.Second)
So(*args.Overrides.FeatureSources, ShouldResemble, utils.StringSliceVal{"cpu"}) So(*args.Overrides.FeatureSources, ShouldResemble, utils.StringSliceVal{"cpu"})
So(*args.Overrides.LabelSources, ShouldResemble, utils.StringSliceVal{"fake1", "fake2", "fake3"}) So(*args.Overrides.LabelSources, ShouldResemble, utils.StringSliceVal{"fake1", "fake2", "fake3"})
So(args.Overrides.LabelWhiteList.Regexp.String(), ShouldResemble, ".*rdt.*")
}) })
}) })
}) })

View file

@ -178,10 +178,6 @@ Example:
nfd-worker -label-sources=kernel,system,local nfd-worker -label-sources=kernel,system,local
``` ```
### -sources
**DEPRECATED**: use [`-label-sources`](#-label-sources) instead.
### -no-publish ### -no-publish
The `-no-publish` flag disables all communication with the nfd-master, making The `-no-publish` flag disables all communication with the nfd-master, making
@ -196,29 +192,6 @@ Example:
nfd-worker -no-publish nfd-worker -no-publish
``` ```
### -label-whitelist
The `-label-whitelist` specifies a regular expression for filtering feature
labels based on their name. Each label must match against the given reqular
expression in order to be published.
Note: The regular expression is only matches against the "basename" part of the
label, i.e. to the part of the name after '/'. The label namespace is omitted.
Note: This flag takes precedence over the `core.labelWhiteList` configuration
file option.
Default: *empty*
Example:
```bash
nfd-worker -label-whitelist='.*cpuid\.'
```
**DEPRECATED**: you should use the `core.labelWhiteList` option in the
configuration file, instead.
### -oneshot ### -oneshot
The `-oneshot` flag causes nfd-worker to exit after one pass of feature The `-oneshot` flag causes nfd-worker to exit after one pass of feature
@ -232,26 +205,6 @@ Example:
nfd-worker -oneshot -no-publish nfd-worker -oneshot -no-publish
``` ```
### -sleep-interval
The `-sleep-interval` specifies the interval between feature re-detection (and
node re-labeling). A non-positive value implies infinite sleep interval, i.e.
no re-detection or re-labeling is done.
Note: This flag takes precedence over the `core.sleepInterval` configuration
file option.
Default: 60s
Example:
```bash
nfd-worker -sleep-interval=1h
```
**DEPRECATED**: you should use the `core.sleepInterval` option in the
configuration file, instead.
### Logging ### Logging
The following logging-related flags are inherited from the The following logging-related flags are inherited from the

View file

@ -31,9 +31,6 @@ feature (re-)detection, and thus also the interval between node re-labeling. A
non-positive value implies infinite sleep interval, i.e. no re-detection or non-positive value implies infinite sleep interval, i.e. no re-detection or
re-labeling is done. re-labeling is done.
Note: Overridden by the deprecated `-sleep-interval` command line flag (if
specified).
Default: `60s` Default: `60s`
Example: Example:
@ -82,8 +79,8 @@ conjunction with `all`. This configuration option affects the generation of
node labels but not the actual discovery of the underlying feature data that is node labels but not the actual discovery of the underlying feature data that is
used e.g. in custom/`NodeFeatureRule` rules. used e.g. in custom/`NodeFeatureRule` rules.
Note: Overridden by the `-label-sources` and `-sources` command line flags and Note: Overridden by the `-label-sources` command line flag and
the `core.sources` configurations option (if any of them is specified). the `core.sources` configurations option (if either of them is specified).
Default: `[all]` Default: `[all]`
@ -122,9 +119,6 @@ Note: The regular expression is only matches against the "basename" part of the
label, i.e. to the part of the name after '/'. The label prefix (or namespace) label, i.e. to the part of the name after '/'. The label prefix (or namespace)
is omitted. is omitted.
Note: Overridden by the deprecated `-label-whitelist` command line flag (if
specified).
Default: `null` Default: `null`
Example: Example:

View file

@ -84,9 +84,7 @@ labels, accordingly.
is received from nfd-worker. That is, in practice rules are evaluated and is received from nfd-worker. That is, in practice rules are evaluated and
labels for each node are created on intervals specified by the labels for each node are created on intervals specified by the
[`core.sleepInterval`](../reference/worker-configuration-reference#coresleepinterval) [`core.sleepInterval`](../reference/worker-configuration-reference#coresleepinterval)
configuration option (or configuration option of nfd-worker instances. This means that modification or
[`-sleep-interval`](../reference/worker-commandline-reference#-sleep-interval)
command line flag) of nfd-worker instances. This means that modification or
creation of `NodeFeatureRule` objects does not instantly cause the node labels creation of `NodeFeatureRule` objects does not instantly cause the node labels
to be updated. Instead, the changes only come visible in node labels as to be updated. Instead, the changes only come visible in node labels as
nfd-worker instances send their labelling requests. nfd-worker instances send their labelling requests.

View file

@ -33,10 +33,14 @@ have the following format.
feature.node.kubernetes.io/<feature> = <value> feature.node.kubernetes.io/<feature> = <value>
``` ```
*Note: Consecutive runs of nfd-worker will update the labels on a > NOTE: Consecutive runs of nfd-worker will update the labels on a
given node. If features are not discovered on a consecutive run, the corresponding given node. If features are not discovered on a consecutive run, the corresponding
label will be removed. This includes any restrictions placed on the consecutive run, label will be removed. This includes any restrictions placed on the consecutive run,
such as restricting discovered features with the -label-whitelist option.* such as restricting discovered features with the
[`-label-whitelist`](../reference/master-commandline-reference#-label-whitelist)
flag of nfd-master or
[`core.labelWhiteList`](../reference/worker-configuration-reference#corelabelwhitelist)
option of nfd-worker.
### CPU ### CPU

View file

@ -23,9 +23,7 @@ Worker connects to the nfd-master service to advertise hardware features.
When run as a daemonset, nodes are re-labeled at an default interval of 60s. When run as a daemonset, nodes are re-labeled at an default interval of 60s.
This can be changed by using the This can be changed by using the
[`core.sleepInterval`](../reference/worker-configuration-reference.html#coresleepinterval) [`core.sleepInterval`](../reference/worker-configuration-reference.html#coresleepinterval)
config option (or config option.
[`-sleep-interval`](../reference/worker-commandline-reference.html#-sleep-interval)
command line flag).
The worker configuration file is watched and re-read on every change which The worker configuration file is watched and re-read on every change which
provides a simple mechanism of dynamic run-time reconfiguration. See provides a simple mechanism of dynamic run-time reconfiguration. See

View file

@ -170,18 +170,16 @@ sources:
}) })
Convey("and a proper config file and overrides are given", func() { Convey("and a proper config file and overrides are given", func() {
sleepIntervalArg := 15 * time.Second worker.args = Args{Overrides: ConfigOverrideArgs{FeatureSources: &utils.StringSliceVal{"cpu"}}}
worker.args = Args{Overrides: ConfigOverrideArgs{SleepInterval: &sleepIntervalArg}}
overrides := `{"core": {"labelSources": ["fake"],"noPublish": true},"sources": {"pci": {"deviceClassWhitelist": ["03"]}}}` overrides := `{"core": {"labelSources": ["fake"],"noPublish": true},"sources": {"pci": {"deviceClassWhitelist": ["03"]}}}`
So(worker.configure(f.Name(), overrides), ShouldBeNil) So(worker.configure(f.Name(), overrides), ShouldBeNil)
Convey("overrides should take precedence over the config file", func() { Convey("overrides should take precedence over the config file", func() {
// Verify core config // Verify core config
So(worker.config.Core.NoPublish, ShouldBeTrue) So(worker.config.Core.NoPublish, ShouldBeTrue)
So(worker.config.Core.FeatureSources, ShouldResemble, []string{"memory", "storage"}) So(worker.config.Core.FeatureSources, ShouldResemble, []string{"cpu"}) // from cmdline
So(worker.config.Core.LabelSources, ShouldResemble, []string{"fake"}) // from overrides So(worker.config.Core.LabelSources, ShouldResemble, []string{"fake"}) // from overrides
So(worker.config.Core.LabelWhiteList.String(), ShouldEqual, "foo") So(worker.config.Core.LabelWhiteList.String(), ShouldEqual, "foo")
So(worker.config.Core.SleepInterval.Duration, ShouldEqual, 15*time.Second) // from cmdline
// Verify feature source config // Verify feature source config
So(err, ShouldBeNil) So(err, ShouldBeNil)
@ -339,20 +337,6 @@ func TestNewNfdWorker(t *testing.T) {
So(worker.config.Core.LabelWhiteList, ShouldResemble, emptyRegexp) So(worker.config.Core.LabelWhiteList, ShouldResemble, emptyRegexp)
}) })
}) })
Convey("with valid LabelWhiteListStr arg specified", func() {
args := &Args{Overrides: ConfigOverrideArgs{LabelWhiteList: &utils.RegexpVal{Regexp: *regexp.MustCompile(".*rdt.*")}}}
w, err := NewNfdWorker(args)
Convey("no error should be returned", func() {
So(err, ShouldBeNil)
})
worker := w.(*nfdWorker)
So(worker.configure("", ""), ShouldBeNil)
expectRegexp := utils.RegexpVal{Regexp: *regexp.MustCompile(".*rdt.*")}
Convey("proper labelWhiteList regexp should be produced", func() {
So(worker.config.Core.LabelWhiteList, ShouldResemble, expectRegexp)
})
})
}) })
} }

View file

@ -88,9 +88,6 @@ type Args struct {
type ConfigOverrideArgs struct { type ConfigOverrideArgs struct {
NoPublish *bool NoPublish *bool
// Deprecated
LabelWhiteList *utils.RegexpVal
SleepInterval *time.Duration
FeatureSources *utils.StringSliceVal FeatureSources *utils.StringSliceVal
LabelSources *utils.StringSliceVal LabelSources *utils.StringSliceVal
} }
@ -415,15 +412,9 @@ func (w *nfdWorker) configure(filepath string, overrides string) error {
return fmt.Errorf("failed to parse -options: %s", err) return fmt.Errorf("failed to parse -options: %s", err)
} }
if w.args.Overrides.LabelWhiteList != nil {
c.Core.LabelWhiteList = *w.args.Overrides.LabelWhiteList
}
if w.args.Overrides.NoPublish != nil { if w.args.Overrides.NoPublish != nil {
c.Core.NoPublish = *w.args.Overrides.NoPublish c.Core.NoPublish = *w.args.Overrides.NoPublish
} }
if w.args.Overrides.SleepInterval != nil {
c.Core.SleepInterval = duration{*w.args.Overrides.SleepInterval}
}
if w.args.Overrides.FeatureSources != nil { if w.args.Overrides.FeatureSources != nil {
c.Core.FeatureSources = *w.args.Overrides.FeatureSources c.Core.FeatureSources = *w.args.Overrides.FeatureSources
} }