Implement dynamic problemdaemon registration and initialization.

Added package problemdaemon. All future problem daemons should be
registered by calling problemdaemon.register().

CLI interfaces will be automatically generated for all registered
problem daemons in the form of "--config.DAEMON_NAME"
This commit is contained in:
Xuewei Zhang
2019-06-12 18:29:18 -07:00
parent 5814195ad5
commit 63f0e35e56
4 changed files with 194 additions and 7 deletions
+32 -7
View File
@@ -24,18 +24,15 @@ import (
"net/url"
"github.com/spf13/pflag"
"k8s.io/node-problem-detector/pkg/problemdaemon"
"k8s.io/node-problem-detector/pkg/types"
)
// NodeProblemDetectorOptions contains node problem detector command line and application options.
type NodeProblemDetectorOptions struct {
// command line options
// SystemLogMonitorConfigPaths specifies the list of paths to system log monitor configuration
// files.
SystemLogMonitorConfigPaths []string
// CustomPluginMonitorConfigPaths specifies the list of paths to custom plugin monitor configuration
// files.
CustomPluginMonitorConfigPaths []string
// PrintVersion is the flag determining whether version information is printed.
PrintVersion bool
// HostnameOverride specifies custom node name used to override hostname.
@@ -53,6 +50,17 @@ type NodeProblemDetectorOptions struct {
// ApiServerOverride is the custom URI used to connect to Kubernetes ApiServer.
ApiServerOverride string
// problem daemon options
// SystemLogMonitorConfigPaths specifies the list of paths to system log monitor configuration
// files.
SystemLogMonitorConfigPaths []string
// CustomPluginMonitorConfigPaths specifies the list of paths to custom plugin monitor configuration
// files.
CustomPluginMonitorConfigPaths []string
// MonitorConfigPaths specifies the list of paths to configuration files for each monitor.
MonitorConfigPaths types.ProblemDaemonConfigPathMap
// application options
// NodeName is the node name used to communicate with Kubernetes ApiServer.
@@ -60,7 +68,7 @@ type NodeProblemDetectorOptions struct {
}
func NewNodeProblemDetectorOptions() *NodeProblemDetectorOptions {
return &NodeProblemDetectorOptions{}
return &NodeProblemDetectorOptions{MonitorConfigPaths: types.ProblemDaemonConfigPathMap{}}
}
// AddFlags adds node problem detector command line options to pflag.
@@ -79,6 +87,17 @@ func (npdo *NodeProblemDetectorOptions) AddFlags(fs *pflag.FlagSet) {
20256, "The port to bind the node problem detector server. Use 0 to disable.")
fs.StringVar(&npdo.ServerAddress, "address",
"127.0.0.1", "The address to bind the node problem detector server.")
for _, problemDaemonName := range problemdaemon.GetProblemDaemonNames() {
npdo.MonitorConfigPaths[problemDaemonName] = &[]string{}
fs.StringSliceVar(
npdo.MonitorConfigPaths[problemDaemonName],
"config."+string(problemDaemonName),
[]string{},
fmt.Sprintf("Comma separated configurations for %v monitor. %v",
problemDaemonName,
problemdaemon.GetProblemDaemonHandlerOrDie(problemDaemonName).CmdOptionDescription))
}
}
// ValidOrDie validates node problem detector command line options.
@@ -90,6 +109,12 @@ func (npdo *NodeProblemDetectorOptions) ValidOrDie() {
if len(npdo.SystemLogMonitorConfigPaths) == 0 && len(npdo.CustomPluginMonitorConfigPaths) == 0 {
panic(fmt.Sprintf("Either --system-log-monitors or --custom-plugin-monitors is required"))
}
for problemDaemonName, configs := range npdo.MonitorConfigPaths {
if configs == nil {
panic(fmt.Sprintf("nil config for problem daemon %q. This should never happen, might indicates bug in pflag.", problemDaemonName))
}
}
}
// SetNodeNameOrDie sets `NodeName` field with valid value.