Repository: kubernetes-sigs/node-feature-discovery
Pull request #356 (2020-09-09 08:39:24)

nfd-worker: add special handling for --sources=all
A new special value 'all' is a shortcut for enabling all feature
sources. It should be the only name specified -- if any other names are
specified 'all' does not take effect, but, we only enable the listed
feature sources. E.g.
  --sources=all enables all sources, but
  --sources=all,cpu only enables the cpu source

k8s-ci-robot: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/kubernetes-sigs/node-feature-discovery/pull/356#" title="Author self-approved">marquiz</a>*

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=kubernetes-sigs%2Fnode-feature-discovery).

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

<details >
Needs approval from an approver in each of these files:

- ~~[OWNERS](https://github.com/kubernetes-sigs/node-feature-discovery/blob/master/OWNERS)~~ [marquiz]

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":[]} -->
k8s-ci-robot: @marquiz: The following test **failed**, say `/retest` to rerun all failed tests:

Test name | Commit | Details | Rerun command
--- | --- | --- | ---
pull-node-feature-discovery-build-gh-pages | 6969e7d8ddeea666eebf334687499c2a72ed8115 | [link](https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/kubernetes-sigs_node-feature-discovery/356/pull-node-feature-discovery-build-gh-pages/1319246808584556544) | `/test pull-node-feature-discovery-build-gh-pages`

[Full PR test history](https://prow.k8s.io/pr-history?org=kubernetes-sigs&repo=node-feature-discovery&pr=356). [Your PR dashboard](https://prow.k8s.io/pr?query=is%3Apr%20state%3Aopen%20author%3Amarquiz). Please help us cut down on flakes by [linking to](https://git.k8s.io/community/contributors/devel/sig-testing/flaky-tests.md#filing-issues-for-flaky-tests) an [open issue](https://github.com/kubernetes-sigs/node-feature-discovery/issues?q=is:issue+is:open) when you hit one in your PR.

<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository. I understand the commands that are listed [here](https://go.k8s.io/bot-commands).
</details>
<!-- test report -->
marquiz: Rebased and addressed comments from @Ethyling 
marquiz: /assign @Ethyling 

Patch:
diff --git a/.github/ISSUE_TEMPLATE/new-release.md b/.github/ISSUE_TEMPLATE/new-release.md
index c32702440..5c2985f5d 100644
--- a/.github/ISSUE_TEMPLATE/new-release.md
+++ b/.github/ISSUE_TEMPLATE/new-release.md
@@ -15,8 +15,12 @@ Please do not remove items from the checklist
 - [ ] For major releases (v0.$MAJ.0), an OWNER creates a release branch with
       `git branch release-0.$MAJ master`
 - [ ] Prepare `release-0.$MAJ` release branch
-  - [ ] Run `scripts/prepare-release.sh $VERSION` to turn references to point to the upcoming release
-        (README, deployment templates, docs .md files, docs configuration, test/e2e flags)
+  - [ ] Update the deployment templates to use the new tagged container image:
+        `sed s"|image: .*|image: k8s.gcr.io/nfd/node-feature-discovery:$VERSION|" -i *yaml.template`
+  - [ ] Update quick start instructions in README.md to use $VERSION
+  - [ ] Update version configuration in `docs/_config.yml`:
+        - set `version: $VERSION`
+        - add $VERSION to `versions:` list
   - [ ] An OWNER runs
        `git tag -s $VERSION`
         and inserts the changelog into the tag description.
diff --git a/cmd/nfd-worker/main.go b/cmd/nfd-worker/main.go
index 1b4606782..2b28475a2 100644
--- a/cmd/nfd-worker/main.go
+++ b/cmd/nfd-worker/main.go
@@ -90,8 +90,9 @@ func argsParse(argv []string) (worker.Args, error) {
   --server-name-override=<name> Name (CN) expect from server certificate, useful
                               in testing
                               [Default: ]
-  --sources=<sources>         Comma separated list of feature sources.
-                              [Default: cpu,custom,iommu,kernel,local,memory,network,pci,storage,system,usb]
+  --sources=<sources>         Comma separated list of feature sources. Special
+                              value 'all' enables all feature sources.
+                              [Default: all]
   --no-publish                Do not publish discovered features to the
                               cluster-local Kubernetes API server.
   --label-whitelist=<pattern> Regular expression to filter label names to
diff --git a/docs/advanced/developer-guide.md b/docs/advanced/developer-guide.md
index 81120b489..cf403a632 100644
--- a/docs/advanced/developer-guide.md
+++ b/docs/advanced/developer-guide.md
@@ -222,8 +222,6 @@ Command line flags of nfd-worker:
 ```bash
 $ docker run --rm ${NFD_CONTAINER_IMAGE} nfd-worker --help
 ...
-nfd-worker.
-
   Usage:
   nfd-worker [--no-publish] [--sources=<sources>] [--label-whitelist=<pattern>]
      [--oneshot | --sleep-interval=<seconds>] [--config=<path>]
@@ -253,8 +251,9 @@ nfd-worker.
   --server-name-override=<name> Name (CN) expect from server certificate, useful
                               in testing
                               [Default: ]
-  --sources=<sources>         Comma separated list of feature sources.
-                              [Default: cpu,custom,iommu,kernel,local,memory,network,pci,storage,system,usb]
+  --sources=<sources>         Comma separated list of feature sources. Special
+                              value 'all' enables all feature sources.
+                              [Default: all]
   --no-publish                Do not publish discovered features to the
                               cluster-local Kubernetes API server.
   --label-whitelist=<pattern> Regular expression to filter label names to
@@ -266,6 +265,7 @@ nfd-worker.
   --sleep-interval=<seconds>  Time to sleep between re-labeling. Non-positive
                               value implies no re-labeling (i.e. infinite
                               sleep). [Default: 60s]
+
 ```
 
 **NOTE** Some feature sources need certain directories and/or files from the
diff --git a/docs/advanced/worker-commandline-reference.md b/docs/advanced/worker-commandline-reference.md
index a19fb111b..f28c6fc62 100644
--- a/docs/advanced/worker-commandline-reference.md
+++ b/docs/advanced/worker-commandline-reference.md
@@ -139,9 +139,9 @@ nfd-worker --server-name-override=localhost
 ### --sources
 
 The `--sources` flag specifies a comma-separated list of enabled feature
-sources.
+sources. A special value `all` enables all feature sources.
 
-Default: cpu,custom,iommu,kernel,local,memory,network,pci,storage,system,usb
+Default: all
 
 Example:
 
diff --git a/pkg/nfd-worker/nfd-worker.go b/pkg/nfd-worker/nfd-worker.go
index 780d4d63e..1a95fb18d 100644
--- a/pkg/nfd-worker/nfd-worker.go
+++ b/pkg/nfd-worker/nfd-worker.go
@@ -124,12 +124,10 @@ func NewNfdWorker(args Args) (NfdWorker, error) {
 	// Figure out active sources
 	allSources := []source.FeatureSource{
 		&cpu.Source{},
-		&fake.Source{},
 		&iommu.Source{},
 		&kernel.Source{},
 		&memory.Source{},
 		&network.Source{},
-		&panicfake.Source{},
 		&pci.Source{},
 		&storage.Source{},
 		&system.Source{},
@@ -140,15 +138,33 @@ func NewNfdWorker(args Args) (NfdWorker, error) {
 		&local.Source{},
 	}
 
-	sourceWhiteList := map[string]struct{}{}
-	for _, s := range args.Sources {
-		sourceWhiteList[strings.TrimSpace(s)] = struct{}{}
-	}
+	// Determine enabled feature
+	if len(args.Sources) == 1 && args.Sources[0] == "all" {
+		nfd.sources = allSources
+	} else {
+		// Add fake source which is only meant for testing. It will be enabled
+		// only if listed explicitly.
+		allSources = append(allSources, &fake.Source{})
+		allSources = append(allSources, &panicfake.Source{})
+
+		sourceWhiteList := map[string]struct{}{}
+		for _, s := range args.Sources {
+			sourceWhiteList[strings.TrimSpace(s)] = struct{}{}
+		}
 
-	nfd.sources = []source.FeatureSource{}
-	for _, s := range allSources {
-		if _, enabled := sourceWhiteList[s.Name()]; enabled {
-			nfd.sources = append(nfd.sources, s)
+		nfd.sources = []source.FeatureSource{}
+		for _, s := range allSources {
+			if _, enabled := sourceWhiteList[s.Name()]; enabled {
+				nfd.sources = append(nfd.sources, s)
+				delete(sourceWhiteList, s.Name())
+			}
+		}
+		if len(sourceWhiteList) > 0 {
+			names := make([]string, 0, len(sourceWhiteList))
+			for n := range sourceWhiteList {
+				names = append(names, n)
+			}
+			stderrLogger.Printf("WARNING: skipping unknown source(s) %q specified in --sources", strings.Join(names, ", "))
 		}
 	}
 
diff --git a/scripts/prepare-release.sh b/scripts/prepare-release.sh
deleted file mode 100755
index d95918df3..000000000
--- a/scripts/prepare-release.sh
+++ /dev/null
@@ -1,80 +0,0 @@
-#!/bin/bash -e
-set -o pipefail
-
-this=`basename $0`
-
-usage () {
-cat << EOF
-Usage: $this [-h] RELEASE_VERSION
-
-Options:
-  -h         show this help and exit
-EOF
-}
-
-#
-# Parse command line
-#
-while getopts "h" opt; do
-    case $opt in
-        h)  usage
-            exit 0
-            ;;
-        *)  usage
-            exit 1
-            ;;
-    esac
-done
-shift "$((OPTIND - 1))"
-
-# Check that no extra args were provided
-if [ $# -gt 1 ]; then
-    echo -e "ERROR: unknown arguments: $@\n"
-    usage
-    exit 1
-fi
-
-release=$1
-container_image=k8s.gcr.io/nfd/node-feature-discovery:$release
-
-#
-# Check/parse release number
-#
-if [ -z "$release" ]; then
-    echo -e "ERROR: missing RELEASE_VERSION\n"
-    usage
-    exit 1
-fi
-
-if [[ $release =~ ^(v[0-9]+\.[0-9]+)(\..+)?$ ]]; then
-    docs_version=${BASH_REMATCH[1]}
-else
-    echo -e "ERROR: invalid RELEASE_VERSION '$release'"
-    exit 1
-fi
-
-# Patch docs configuration
-echo Patching docs/_config.yml
-sed -e s"/release:.*/release: $release/"  \
-    -e s"/version:.*/version: $docs_version/" \
-    -i docs/_config.yml
-
-# Patch container image repo
-echo Patching '*.md' files to refer to $container_image
-find . -path ./docs/vendor -prune -o -name '*.md' -print | xargs \
-    sed -i -e s"!gcr.io/k8s-staging-nfd/node-feature-discovery:[[:alnum:]][[:alnum:].-]*!$container_image!" \
-           -e s"!k8s.gcr.io/nfd/node-feature-discovery:[[:alnum:]][[:alnum:].-]*!$container_image!"
-
-# Patch README
-echo Patching README.md to refer to $release
-sed s"!node-feature-discovery/v.*/!node-feature-discovery/$release/!" -i README.md
-
-# Patch deployment templates
-echo Patching '*.yaml.template' to use $container_image
-sed -E s",^([[:space:]]+)image:.+$,\1image: $container_image," -i *yaml.template
-
-# Patch e2e test
-echo Patching test/e2e/node_feature_discovery.go flag defaults to k8s.gcr.io/nfd/node-feature-discovery and $release
-sed -e s'!"nfd\.repo",.*,!"nfd.repo", "k8s.gcr.io/nfd/node-feature-discovery",!' \
-    -e s"!\"nfd\.tag\",.*,!\"nfd.tag\", \"$release\",!" \
-  -i test/e2e/node_feature_discovery.go


Test patch:
diff --git a/cmd/nfd-worker/main_test.go b/cmd/nfd-worker/main_test.go
index f10674fd6..f6cf3e539 100644
--- a/cmd/nfd-worker/main_test.go
+++ b/cmd/nfd-worker/main_test.go
@@ -23,7 +23,7 @@ import (
 	. "github.com/smartystreets/goconvey/convey"
 )
 
-var allSources = []string{"cpu", "custom", "iommu", "kernel", "local", "memory", "network", "pci", "storage", "system", "usb"}
+var allSources = []string{"all"}
 
 func TestArgsParse(t *testing.T) {
 	Convey("When parsing command line arguments", t, func() {