mirror of
https://github.com/kubernetes-sigs/node-feature-discovery.git
synced 2024-12-14 11:57:51 +00:00
Merge pull request #1860 from ozhuraki/no-owner-refs
nfd-worker: Add an option to disable setting the owner references
This commit is contained in:
commit
caaac59eba
7 changed files with 93 additions and 34 deletions
|
@ -94,6 +94,8 @@ func parseArgs(flags *flag.FlagSet, osArgs ...string) *worker.Args {
|
|||
args.Overrides.FeatureSources = overrides.FeatureSources
|
||||
case "label-sources":
|
||||
args.Overrides.LabelSources = overrides.LabelSources
|
||||
case "no-owner-refs":
|
||||
args.Overrides.NoOwnerRefs = overrides.NoOwnerRefs
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -126,6 +128,8 @@ func initFlags(flagset *flag.FlagSet) (*worker.Args, *worker.ConfigOverrideArgs)
|
|||
}
|
||||
overrides.NoPublish = flagset.Bool("no-publish", false,
|
||||
"Do not publish discovered features, disable connection to nfd-master and don't create NodeFeature object.")
|
||||
overrides.NoOwnerRefs = flagset.Bool("no-owner-refs", false,
|
||||
"Do not set owner references for NodeFeature object.")
|
||||
flagset.Var(overrides.FeatureSources, "feature-sources",
|
||||
"Comma separated list of feature sources. Special value 'all' enables all sources. "+
|
||||
"Prefix the source name with '-' to disable it.")
|
||||
|
|
|
@ -43,12 +43,14 @@ func TestParseArgs(t *testing.T) {
|
|||
Convey("When all override args are specified", func() {
|
||||
args := parseArgs(flags,
|
||||
"-no-publish",
|
||||
"-no-owner-refs",
|
||||
"-feature-sources=cpu",
|
||||
"-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.NoOwnerRefs, ShouldBeTrue)
|
||||
So(*args.Overrides.FeatureSources, ShouldResemble, utils.StringSliceVal{"cpu"})
|
||||
So(*args.Overrides.LabelSources, ShouldResemble, utils.StringSliceVal{"fake1", "fake2", "fake3"})
|
||||
})
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#core:
|
||||
# labelWhiteList:
|
||||
# noPublish: false
|
||||
# noOwnerRefs: false
|
||||
# sleepInterval: 60s
|
||||
# featureSources: [all]
|
||||
# labelSources: [all]
|
||||
|
|
|
@ -182,6 +182,7 @@ worker:
|
|||
#core:
|
||||
# labelWhiteList:
|
||||
# noPublish: false
|
||||
# noOwnerRefs: false
|
||||
# sleepInterval: 60s
|
||||
# featureSources: [all]
|
||||
# labelSources: [all]
|
||||
|
|
|
@ -162,6 +162,23 @@ Example:
|
|||
nfd-worker -no-publish
|
||||
```
|
||||
|
||||
### -no-owner-refs
|
||||
|
||||
The `-no-owner-refs` flag disables setting the owner references to Pod
|
||||
of the 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
|
||||
|
|
|
@ -149,6 +149,24 @@ core:
|
|||
noPublish: true
|
||||
```
|
||||
|
||||
### core.noOwnerRefs
|
||||
|
||||
Setting `core.noOwnerRefs` to `true` disables setting the owner references
|
||||
of the NodeFeature object created by the nfd-worker.
|
||||
|
||||
> **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.
|
||||
|
|
|
@ -78,6 +78,7 @@ type coreConfig struct {
|
|||
Klog klogutils.KlogConfigOpts
|
||||
LabelWhiteList utils.RegexpVal
|
||||
NoPublish bool
|
||||
NoOwnerRefs bool
|
||||
FeatureSources []string
|
||||
Sources *[]string
|
||||
LabelSources []string
|
||||
|
@ -98,6 +99,7 @@ type Args struct {
|
|||
Options string
|
||||
MetricsPort int
|
||||
GrpcHealthPort int
|
||||
NoOwnerRefs bool
|
||||
|
||||
Overrides ConfigOverrideArgs
|
||||
}
|
||||
|
@ -105,7 +107,7 @@ type Args struct {
|
|||
// ConfigOverrideArgs are args that override config file options
|
||||
type ConfigOverrideArgs struct {
|
||||
NoPublish *bool
|
||||
|
||||
NoOwnerRefs *bool
|
||||
FeatureSources *utils.StringSliceVal
|
||||
LabelSources *utils.StringSliceVal
|
||||
}
|
||||
|
@ -265,27 +267,13 @@ 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 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
|
||||
// Set owner ref
|
||||
func (w *nfdWorker) setOwnerReference() error {
|
||||
ownerReference := []metav1.OwnerReference{}
|
||||
|
||||
if !w.config.Core.NoOwnerRefs {
|
||||
// Get pod owner reference
|
||||
podName := os.Getenv("POD_NAME")
|
||||
|
||||
// Add pod owner reference if it exists
|
||||
if podName != "" {
|
||||
if selfPod, err := w.k8sClient.CoreV1().Pods(w.kubernetesNamespace).Get(context.TODO(), podName, metav1.GetOptions{}); err != nil {
|
||||
|
@ -309,9 +297,29 @@ func (w *nfdWorker) Run() error {
|
|||
} else {
|
||||
klog.InfoS("Cannot set NodeFeature owner references, POD_NAME not specified")
|
||||
}
|
||||
}
|
||||
|
||||
w.ownerReference = ownerReference
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Run NfdWorker client. Returns an error 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 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()
|
||||
|
||||
// Register to metrics server
|
||||
if w.args.MetricsPort > 0 {
|
||||
m := utils.CreateMetricsServer(w.args.MetricsPort,
|
||||
|
@ -466,6 +474,11 @@ func (w *nfdWorker) configureCore(c coreConfig) error {
|
|||
klogV.InfoS("enabled label sources", "labelSources", n)
|
||||
}
|
||||
|
||||
err = w.setOwnerReference()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -511,6 +524,9 @@ func (w *nfdWorker) configure(filepath string, overrides string) error {
|
|||
if w.args.Overrides.NoPublish != nil {
|
||||
c.Core.NoPublish = *w.args.Overrides.NoPublish
|
||||
}
|
||||
if w.args.Overrides.NoOwnerRefs != nil {
|
||||
c.Core.NoOwnerRefs = *w.args.Overrides.NoOwnerRefs
|
||||
}
|
||||
if w.args.Overrides.FeatureSources != nil {
|
||||
c.Core.FeatureSources = *w.args.Overrides.FeatureSources
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue