Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nfd-worker: drop deprecated command line flags #968

Merged
merged 1 commit into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions cmd/nfd-worker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,6 @@ func parseArgs(flags *flag.FlagSet, osArgs ...string) *worker.Args {
args.Overrides.FeatureSources = overrides.FeatureSources
case "label-sources":
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
}
})

Expand Down Expand Up @@ -124,7 +115,6 @@ func initFlags(flagset *flag.FlagSet) (*worker.Args, *worker.ConfigOverrideArgs)

// Flags overlapping with config file options
overrides := &worker.ConfigOverrideArgs{
LabelWhiteList: &utils.RegexpVal{},
FeatureSources: &utils.StringSliceVal{},
LabelSources: &utils.StringSliceVal{},
}
Expand All @@ -136,17 +126,6 @@ func initFlags(flagset *flag.FlagSet) (*worker.Args, *worker.ConfigOverrideArgs)
flagset.Var(overrides.LabelSources, "label-sources",
"Comma separated list of label sources. Special value 'all' enables all sources. "+
"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
}
Expand Down
9 changes: 1 addition & 8 deletions cmd/nfd-worker/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package main
import (
"flag"
"testing"
"time"

. "github.com/smartystreets/goconvey/convey"

Expand All @@ -36,8 +35,6 @@ func TestParseArgs(t *testing.T) {
Convey("overrides should be nil", func() {
So(args.Oneshot, ShouldBeTrue)
So(args.Overrides.NoPublish, ShouldBeNil)
So(args.Overrides.LabelWhiteList, ShouldBeNil)
So(args.Overrides.SleepInterval, ShouldBeNil)
So(args.Overrides.FeatureSources, ShouldBeNil)
So(args.Overrides.LabelSources, ShouldBeNil)
})
Expand All @@ -46,18 +43,14 @@ func TestParseArgs(t *testing.T) {
Convey("When all override args are specified", func() {
args := parseArgs(flags,
"-no-publish",
"-label-whitelist=.*rdt.*",
"-feature-sources=cpu",
"-label-sources=fake1,fake2,fake3",
"-sleep-interval=30s")
"-label-sources=fake1,fake2,fake3")

Convey("args.sources is set to appropriate values", func() {
So(args.Oneshot, ShouldBeFalse)
So(*args.Overrides.NoPublish, ShouldBeTrue)
So(*args.Overrides.SleepInterval, ShouldEqual, 30*time.Second)
So(*args.Overrides.FeatureSources, ShouldResemble, utils.StringSliceVal{"cpu"})
So(*args.Overrides.LabelSources, ShouldResemble, utils.StringSliceVal{"fake1", "fake2", "fake3"})
So(args.Overrides.LabelWhiteList.Regexp.String(), ShouldResemble, ".*rdt.*")
})
})
})
Expand Down
47 changes: 0 additions & 47 deletions docs/reference/worker-commandline-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,6 @@ Example:
nfd-worker -label-sources=kernel,system,local
```

### -sources

**DEPRECATED**: use [`-label-sources`](#-label-sources) instead.

### -no-publish

The `-no-publish` flag disables all communication with the nfd-master, making
Expand All @@ -196,29 +192,6 @@ Example:
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

The `-oneshot` flag causes nfd-worker to exit after one pass of feature
Expand All @@ -232,26 +205,6 @@ Example:
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

The following logging-related flags are inherited from the
Expand Down
10 changes: 2 additions & 8 deletions docs/reference/worker-configuration-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
re-labeling is done.

Note: Overridden by the deprecated `-sleep-interval` command line flag (if
specified).

Default: `60s`

Example:
Expand Down Expand Up @@ -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
used e.g. in custom/`NodeFeatureRule` rules.

Note: Overridden by the `-label-sources` and `-sources` command line flags and
the `core.sources` configurations option (if any of them is specified).
Note: Overridden by the `-label-sources` command line flag and
the `core.sources` configurations option (if either of them is specified).

Default: `[all]`

Expand Down Expand Up @@ -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)
is omitted.

Note: Overridden by the deprecated `-label-whitelist` command line flag (if
specified).

Default: `null`

Example:
Expand Down
4 changes: 1 addition & 3 deletions docs/usage/customization-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@ labels, accordingly.
is received from nfd-worker. That is, in practice rules are evaluated and
labels for each node are created on intervals specified by the
[`core.sleepInterval`](../reference/worker-configuration-reference#coresleepinterval)
configuration option (or
[`-sleep-interval`](../reference/worker-commandline-reference#-sleep-interval)
command line flag) of nfd-worker instances. This means that modification or
configuration option of nfd-worker instances. This means that modification or
creation of `NodeFeatureRule` objects does not instantly cause the node labels
to be updated. Instead, the changes only come visible in node labels as
nfd-worker instances send their labelling requests.
Expand Down
8 changes: 6 additions & 2 deletions docs/usage/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@ have the following format.
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
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

Expand Down
4 changes: 1 addition & 3 deletions docs/usage/nfd-worker.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
This can be changed by using the
[`core.sleepInterval`](../reference/worker-configuration-reference.html#coresleepinterval)
config option (or
[`-sleep-interval`](../reference/worker-commandline-reference.html#-sleep-interval)
command line flag).
config option.

The worker configuration file is watched and re-read on every change which
provides a simple mechanism of dynamic run-time reconfiguration. See
Expand Down
22 changes: 3 additions & 19 deletions pkg/nfd-client/worker/nfd-worker-internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,18 +170,16 @@ sources:
})

Convey("and a proper config file and overrides are given", func() {
sleepIntervalArg := 15 * time.Second
worker.args = Args{Overrides: ConfigOverrideArgs{SleepInterval: &sleepIntervalArg}}
worker.args = Args{Overrides: ConfigOverrideArgs{FeatureSources: &utils.StringSliceVal{"cpu"}}}
overrides := `{"core": {"labelSources": ["fake"],"noPublish": true},"sources": {"pci": {"deviceClassWhitelist": ["03"]}}}`
So(worker.configure(f.Name(), overrides), ShouldBeNil)

Convey("overrides should take precedence over the config file", func() {
// Verify core config
So(worker.config.Core.NoPublish, ShouldBeTrue)
So(worker.config.Core.FeatureSources, ShouldResemble, []string{"memory", "storage"})
So(worker.config.Core.LabelSources, ShouldResemble, []string{"fake"}) // from overrides
So(worker.config.Core.FeatureSources, ShouldResemble, []string{"cpu"}) // from cmdline
So(worker.config.Core.LabelSources, ShouldResemble, []string{"fake"}) // from overrides
So(worker.config.Core.LabelWhiteList.String(), ShouldEqual, "foo")
So(worker.config.Core.SleepInterval.Duration, ShouldEqual, 15*time.Second) // from cmdline

// Verify feature source config
So(err, ShouldBeNil)
Expand Down Expand Up @@ -339,20 +337,6 @@ func TestNewNfdWorker(t *testing.T) {
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)
})
})
})
}

Expand Down
9 changes: 0 additions & 9 deletions pkg/nfd-client/worker/nfd-worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,6 @@ type Args struct {
type ConfigOverrideArgs struct {
NoPublish *bool

// Deprecated
LabelWhiteList *utils.RegexpVal
SleepInterval *time.Duration
FeatureSources *utils.StringSliceVal
LabelSources *utils.StringSliceVal
}
Expand Down Expand Up @@ -415,15 +412,9 @@ func (w *nfdWorker) configure(filepath string, overrides string) error {
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 {
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 {
c.Core.FeatureSources = *w.args.Overrides.FeatureSources
}
Expand Down