diff --git a/README.md b/README.md index b37cd01db..ac831a316 100644 --- a/README.md +++ b/README.md @@ -124,7 +124,7 @@ the only label value published for features is the string `"true"`._ "feature.node.kubernetes.io/nfd-rdt-": "true", "feature.node.kubernetes.io/nfd-selinux-": "true", "feature.node.kubernetes.io/nfd-storage-": "true", - "feature.node.kubernetes.io/-": "true" + "feature.node.kubernetes.io/-": "" } ``` @@ -193,11 +193,15 @@ available inside the Docker image so Volumes and VolumeMounts must be used if standard NFD images are used. The hook files must be executable. When executed, the hooks are supposed to -print all discovered features in `stdout`, one feature per line. The output in -stdout is used in the node label as is. Unlike other feature sources, the -source name (i.e. `local`) is not used as a prefix in the label. The full name -of node label name will conform to the following convention: +print all discovered features in `stdout`, one feature per line. Hook can +advertise both binary and non-binary labels, using either `` or +`=` output format. Unlike other feature sources, +the source name (i.e. `local`) is not used as a prefix. The hook name is used +as the prefix, instead. The full name of node label name will conform to the +following convention: `feature.node.kubernetes.io/-`. +The value of the label is either `true` (for binary labels) or `` +(for non-binary labels). `stderr` output of the hooks is propagated to NFD log so it can be used for debugging and logging. @@ -207,12 +211,12 @@ User has a shell script following `stdout` output: ``` MY_FEATURE_1 -MY_FEATURE_2 +MY_FEATURE_2=myvalue ``` which, in turn, will translate into the following node labels: ``` feature.node.kubernetes.io/my-source-MY_FEATURE_1=true -feature.node.kubernetes.io/my-source-MY_FEATURE_2=true +feature.node.kubernetes.io/my-source-MY_FEATURE_2=myvalue ``` **NOTE!** NFD will blindly run any executables placed/mounted in the hooks diff --git a/source/local/local.go b/source/local/local.go index b983a74a1..cb7b7585c 100644 --- a/source/local/local.go +++ b/source/local/local.go @@ -24,6 +24,7 @@ import ( "os" "os/exec" "path/filepath" + "strings" "github.com/kubernetes-incubator/node-feature-discovery/source" ) @@ -58,8 +59,8 @@ func (s Source) Discover() (source.Features, error) { log.Printf("ERROR: source hook '%v' failed: %v", hook, err) continue } - for _, feature := range hookFeatures { - features[hook+"-"+feature] = true + for feature, value := range hookFeatures { + features[hook+"-"+feature] = value } } @@ -67,8 +68,8 @@ func (s Source) Discover() (source.Features, error) { } // Run one hook -func runHook(file string) ([]string, error) { - var features []string +func runHook(file string) (map[string]string, error) { + features := map[string]string{} path := filepath.Join(hookDir, file) filestat, err := os.Stat(path) @@ -106,7 +107,12 @@ func runHook(file string) ([]string, error) { lines = bytes.Split(stdout.Bytes(), []byte("\n")) for _, line := range lines { if len(line) > 0 { - features = append(features, string(line)) + lineSplit := strings.SplitN(string(line), "=", 2) + if len(lineSplit) == 1 { + features[lineSplit[0]] = "true" + } else { + features[lineSplit[0]] = lineSplit[1] + } } } }