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: Add an option to disable setting the owner references #1860

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions cmd/nfd-worker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ func initFlags(flagset *flag.FlagSet) (*worker.Args, *worker.ConfigOverrideArgs)
" DEPRECATED: will be removed in a future release along with the deprecated gRPC API.")
flagset.StringVar(&args.Kubeconfig, "kubeconfig", "",
"Kubeconfig to use")
flagset.BoolVar(&args.NoOwnerRefs, "no-owner-refs", false,
"Do not set owner references for NodeFeature object")
flagset.BoolVar(&args.Oneshot, "oneshot", false,
"Do not publish feature labels")
flagset.IntVar(&args.MetricsPort, "metrics", 8081,
Expand Down
17 changes: 17 additions & 0 deletions docs/reference/worker-commandline-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,23 @@ Example:
nfd-worker -no-publish
```

### -no-owner-refs

The `-no-owner-refs` flag disables setting the owner references to Pod
for NodeFeature object.

> **NOTE:** This flag takes precedence over the
> [`core.noOwnerRefs`](worker-configuration-reference.md#corenoownerrefs)
> configuration file option.

Default: *false*

Example:

```bash
nfd-worker -no-owner-refs
```

### -oneshot

The `-oneshot` flag causes nfd-worker to exit after one pass of feature
Expand Down
18 changes: 18 additions & 0 deletions docs/reference/worker-configuration-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,24 @@ core:
noPublish: true
```

### core.noOwnerRefs

Setting `core.noOwnerRefs` to `true` disables setting the owner references
to Pod for NodeFeature object.
Comment on lines +154 to +155
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @ozhuraki for the improvement! Just one nit about the wording (we don't just mark to pod as the owner but also the parent owner of the pod). E.g.

Suggested change
Setting `core.noOwnerRefs` to `true` disables setting the owner references
to Pod for NodeFeature object.
Setting `core.noOwnerRefs` to `true` disables setting the owner references
of the NodeFeature object created by the nfd-worker.

Ditto the cmdline reference


> **NOTE:** Overridden by the
> [`-no-owner-refs`](worker-commandline-reference.md#-no-owner-refs)
> command line flag (if specified).

Default: `false`

Example:

```yaml
core:
noOwnerRefs: true
```

### core.klog

The following options specify the logger configuration.
Expand Down
63 changes: 38 additions & 25 deletions pkg/nfd-worker/nfd-worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ type coreConfig struct {
Klog klogutils.KlogConfigOpts
LabelWhiteList utils.RegexpVal
NoPublish bool
NoOwnerRefs bool
FeatureSources []string
Sources *[]string
LabelSources []string
Expand All @@ -103,6 +104,7 @@ type Args struct {
KeyFile string
Klog map[string]*utils.KlogFlagVal
Kubeconfig string
NoOwnerRefs bool
Oneshot bool
Options string
Server string
Expand Down Expand Up @@ -292,32 +294,9 @@ func (w *nfdWorker) runFeatureDiscovery() error {
return nil
}

// Run NfdWorker client. Returns if a fatal error is encountered, or, after
// one request if OneShot is set to 'true' in the worker args.
func (w *nfdWorker) Run() error {
klog.InfoS("Node Feature Discovery Worker", "version", version.Get(), "nodeName", utils.NodeName(), "namespace", w.kubernetesNamespace)

// Read configuration file
err := w.configure(w.configFilePath, w.args.Options)
if err != nil {
return err
}

// Create watcher for TLS certificates
w.certWatch, err = utils.CreateFsWatcher(time.Second, w.args.CaFile, w.args.CertFile, w.args.KeyFile)
if err != nil {
return err
}

defer w.grpcDisconnect()

// Create ticker for feature discovery and run feature discovery once before the loop.
labelTrigger := infiniteTicker{Ticker: time.NewTicker(1)}
labelTrigger.Reset(w.config.Core.SleepInterval.Duration)
defer labelTrigger.Stop()

// Create owner ref
func (w *nfdWorker) addOwnerReference() error {
ownerReference := []metav1.OwnerReference{}

// Get pod owner reference
podName := os.Getenv("POD_NAME")

Expand Down Expand Up @@ -347,6 +326,40 @@ func (w *nfdWorker) Run() error {

w.ownerReference = ownerReference

return nil
}

// Run NfdWorker client. Returns if a fatal error is encountered, or, after
// one request if OneShot is set to 'true' in the worker args.
func (w *nfdWorker) Run() error {
klog.InfoS("Node Feature Discovery Worker", "version", version.Get(), "nodeName", utils.NodeName(), "namespace", w.kubernetesNamespace)

// Read configuration file
err := w.configure(w.configFilePath, w.args.Options)
if err != nil {
return err
}

// Create watcher for TLS certificates
w.certWatch, err = utils.CreateFsWatcher(time.Second, w.args.CaFile, w.args.CertFile, w.args.KeyFile)
if err != nil {
return err
}

defer w.grpcDisconnect()

// Create ticker for feature discovery and run feature discovery once before the loop.
labelTrigger := infiniteTicker{Ticker: time.NewTicker(1)}
labelTrigger.Reset(w.config.Core.SleepInterval.Duration)
defer labelTrigger.Stop()

if !w.config.Core.NoOwnerRefs {
err := w.addOwnerReference()
if err != nil {
return err
}
}

// Register to metrics server
if w.args.MetricsPort > 0 {
m := utils.CreateMetricsServer(w.args.MetricsPort,
Expand Down