From 4aa7a8f8f8efc94086c5ef6be2af2dbfe6087076 Mon Sep 17 00:00:00 2001 From: Markus Lehtonen Date: Fri, 4 Aug 2023 15:34:13 +0300 Subject: [PATCH] source/local: support comments in input Lines starting with '#' are treated as comments and ignored when parsing feature files and hook output. --- docs/usage/customization-guide.md | 3 +++ source/local/local.go | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/docs/usage/customization-guide.md b/docs/usage/customization-guide.md index 7eaf788fac..773e0dffec 100644 --- a/docs/usage/customization-guide.md +++ b/docs/usage/customization-guide.md @@ -306,6 +306,7 @@ The hook stdout and feature files are expected to contain features in simple key-value pairs, separated by newlines: ```plaintext +# This is a comment [=] ``` @@ -313,6 +314,8 @@ The label value defaults to `true`, if not specified. Label namespace may be specified with `/[=]`. +Comment lines (starting with `#`) are ignored. + ### Mounts The standard NFD deployments contain `hostPath` mounts for diff --git a/source/local/local.go b/source/local/local.go index abb1ad0bb2..9d14595727 100644 --- a/source/local/local.go +++ b/source/local/local.go @@ -150,6 +150,11 @@ func parseFeatures(lines [][]byte) map[string]string { for _, l := range lines { line := strings.TrimSpace(string(l)) if len(line) > 0 { + // Skip comment lines + if strings.HasPrefix(line, "#") { + continue + } + lineSplit := strings.SplitN(line, "=", 2) key := lineSplit[0]