Skip to content

Commit

Permalink
Make it possible to override config options from command line
Browse files Browse the repository at this point in the history
Implement new '--options' command line flag that can be used to specify
config options from command line. Options specified via this command
line flag will override those read from the config file. The same format
as in the config file must be used, that is, the flag value must be
valid YAML or JSON.
  • Loading branch information
marquiz committed Sep 26, 2018
1 parent 84c0b8b commit 700a90c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ node-feature-discovery.
Usage:
node-feature-discovery [--no-publish] [--sources=<sources>] [--label-whitelist=<pattern>]
[--oneshot | --sleep-interval=<seconds>] [--config=<path>]
[--options=<config>]
node-feature-discovery -h | --help
node-feature-discovery --version
Expand All @@ -47,6 +48,11 @@ node-feature-discovery.
--version Output version and exit.
--config=<path> Config file to use.
[Default: /etc/kubernetes/node-feature-discovery/node-feature-discovery.conf]
--options=<config> Specify config options from command line. Config
options are specified in the same format as in the
config file (i.e. json or yaml). These options
will override settings read from the config file.
[Default: ]
--sources=<sources> Comma separated list of feature sources.
[Default: cpuid,iommu,memory,network,pstate,rdt,selinux,storage]
--no-publish Do not publish discovered features to the
Expand Down Expand Up @@ -224,18 +230,25 @@ For example, if some node is tainted NoSchedule or fails to start a job for some

[![asciicast](https://asciinema.org/a/11wir751y89617oemwnsgli4a.png)](https://asciinema.org/a/11wir751y89617oemwnsgli4a)

### Configuration file
### Configuration options

NFD supports a configuration file. The default location is
`/etc/kubernetes/node-feature-discovery/node-feature-discovery.conf`
,but, this can be changed by
specifying the`--config` command line flag. The file is read inside the Docker
image. Thus, Volumes and VolumeMounts are needed, or, a custom Docker image
must be built in order to specify your settings.
must be built in order to specify your settings via a configuration file.
The (empty) [example config](https://github.com/kubernetes-incubator/node-feature-discovery/blob/master/node-feature-discovery.conf.example)
is available in the NFD Docker image, which can be used as base in custom-built
images.

Configuration options can also be specified via the `--options` command line
flag, in which case no mounts need to be used. The same format as in the config
file must be used, i.e. YAML or JSON.

Configuration options specified from the command line will override those read
from the config file.

## Building from source

Download the source code.
Expand Down
15 changes: 15 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ type Args struct {
labelWhiteList string
configFile string
noPublish bool
options string
oneshot bool
sleepInterval time.Duration
sources []string
Expand All @@ -108,6 +109,12 @@ func main() {
stderrLogger.Printf("Failed to read config file: %v", err)
}

// Parse config overrides from command line
err = yaml.Unmarshal([]byte(args.options), &config)
if err != nil {
stderrLogger.Printf("Failed to parse --options: %v", err)
}

// Configure the parameters for feature discovery.
enabledSources, labelWhiteList, err := configureParameters(args.sources, args.labelWhiteList)
if err != nil {
Expand Down Expand Up @@ -147,6 +154,7 @@ func argsParse(argv []string) (args Args) {
Usage:
%s [--no-publish] [--sources=<sources>] [--label-whitelist=<pattern>]
[--oneshot | --sleep-interval=<seconds>] [--config=<path>]
[--options=<config>]
%s -h | --help
%s --version
Expand All @@ -155,6 +163,11 @@ func argsParse(argv []string) (args Args) {
--version Output version and exit.
--config=<path> Config file to use.
[Default: /etc/kubernetes/node-feature-discovery/node-feature-discovery.conf]
--options=<config> Specify config options from command line. Config
options are specified in the same format as in the
config file (i.e. json or yaml). These options
will override settings read from the config file.
[Default: ]
--sources=<sources> Comma separated list of feature sources.
[Default: cpuid,iommu,memory,network,pstate,rdt,selinux,storage]
--no-publish Do not publish discovered features to the
Expand All @@ -178,6 +191,7 @@ func argsParse(argv []string) (args Args) {
var err error
args.configFile = arguments["--config"].(string)
args.noPublish = arguments["--no-publish"].(bool)
args.options = arguments["--options"].(string)
args.sources = strings.Split(arguments["--sources"].(string), ",")
args.labelWhiteList = arguments["--label-whitelist"].(string)
args.oneshot = arguments["--oneshot"].(bool)
Expand All @@ -202,6 +216,7 @@ func configParse(filepath string) error {
return err
}

// Read config file
err = yaml.Unmarshal(data, &config)
if err != nil {
return err
Expand Down

0 comments on commit 700a90c

Please sign in to comment.