Bug report
Background
Some command line arguments are SliceSlice type, e.g. the log driver option (--log-driver).
There are 3 (or more?) methods to configure these parameters:
- via configmap (the default way)
- via environment variable
- via command line
Cilium-agent will dump the effective configurations at start, like the following:
level=info msg="Skipped reading configuration file" reason="Config File \"ciliumd\" Not Found in \"[/home/xxx]\"" subsys=daemon
level=info msg=" --access-log=''" subsys=daemon
level=info msg=" --agent-labels=''" subsys=daemon
level=info msg=" --allow-icmp-frag-needed='true'" subsys=daemon
level=info msg=" --allow-localhost='auto'" subsys=daemon
level=info msg=" --annotate-k8s-node='true'" subsys=daemon
level=info msg=" --auto-create-cilium-node-resource='true'" subsys=daemon
level=info msg=" --auto-direct-node-routes='false'" subsys=daemon
level=info msg=" --blacklist-conflicting-routes='true'" subsys=daemon
level=info msg=" --bpf-compile-debug='false'" subsys=daemon
...
Problem
When using the 3rd way, namely, via command line interface, the specified driver will always be empty in dumped message:
$ ./daemon/cilium-agent --kvstore=etcd --log-driver=syslog 2>&1 | grep log-driver
level=info msg=" --log-driver=''" subsys=daemon
The first 2 ways (configmap and env) are OK:
$ cat configmap/log-driver
syslog
$ ./daemon/cilium-agent --kvstore=etcd --config-dir=./configmap 2>&1 | grep log-driver
level=info msg=" --log-driver='syslog'" subsys=daemon
$ CILIUM_LOG_DRIVER=syslog ./daemon/cilium-agent --kvstore=etcd 2>&1 | grep log-driver
level=info msg=" --log-driver='syslog'" subsys=daemon
Other StringSlice CLI arguments also suffer from this.
The good new is that Cilium works correctly regardless of this, in other words, it's just a display problem.
General Information
- Cilium version: 1.7.4
- Kernel version: 4.14/4.19
Dig inside
Look into the code, the empty values are dumped from this line:
https://github.com/cilium/cilium/blob/v1.7.4/pkg/option/config.go#L873
for _, k := range keys {
entry.Infof(" --%s='%s'", k, viper.GetString(k))
}
viper.GetString("log-driver") will return an empty string. As a quick test, i found
viper.GetStringSlice("log-driver") will return the correct value for these keys.
Further digging, the above GetString call stack actually encounted error in https://github.com/cilium/cilium/blob/v1.7.4/vendor/github.com/spf13/cast/caste.go#L799,
but the error message was silently disgarded, just returned an empty string in https://github.com/cilium/cilium/blob/v1.7.4/vendor/github.com/spf13/cast/cast.go#L157:
func ToStringSlice(i interface{}) []string {
v, _ := ToStringSliceE(i)
return v
}
With some searches, it seems related to this issue in viper/cobra.
Bug report
Background
Some command line arguments are
SliceSlicetype, e.g. the log driver option (--log-driver).There are 3 (or more?) methods to configure these parameters:
Cilium-agent will dump the effective configurations at start, like the following:
Problem
When using the
3rdway, namely, via command line interface, the specified driver will always be empty in dumped message:The first 2 ways (configmap and env) are OK:
Other
StringSliceCLI arguments also suffer from this.The good new is that Cilium works correctly regardless of this, in other words, it's just a display problem.
General Information
Dig inside
Look into the code, the empty values are dumped from this line:
https://github.com/cilium/cilium/blob/v1.7.4/pkg/option/config.go#L873
viper.GetString("log-driver")will return an empty string. As a quick test, i foundviper.GetStringSlice("log-driver")will return the correct value for these keys.Further digging, the above
GetStringcall stack actually encounted error in https://github.com/cilium/cilium/blob/v1.7.4/vendor/github.com/spf13/cast/caste.go#L799,but the error message was silently disgarded, just returned an empty string in https://github.com/cilium/cilium/blob/v1.7.4/vendor/github.com/spf13/cast/cast.go#L157:
With some searches, it seems related to this issue in viper/cobra.