@@ -25,7 +25,9 @@ import (
25
25
26
26
"github.com/spf13/pflag"
27
27
28
+ "k8s.io/node-problem-detector/pkg/custompluginmonitor"
28
29
"k8s.io/node-problem-detector/pkg/problemdaemon"
30
+ "k8s.io/node-problem-detector/pkg/systemlogmonitor"
29
31
"k8s.io/node-problem-detector/pkg/types"
30
32
)
31
33
@@ -54,9 +56,13 @@ type NodeProblemDetectorOptions struct {
54
56
55
57
// SystemLogMonitorConfigPaths specifies the list of paths to system log monitor configuration
56
58
// files.
59
+ // SystemLogMonitorConfigPaths is used by the deprecated option --system-log-monitors. The new
60
+ // option --config.system-log-monitor will stored the config file paths in MonitorConfigPaths.
57
61
SystemLogMonitorConfigPaths []string
58
62
// CustomPluginMonitorConfigPaths specifies the list of paths to custom plugin monitor configuration
59
63
// files.
64
+ // CustomPluginMonitorConfigPaths is used by the deprecated option --custom-plugin-monitors. The
65
+ // new option --config.custom-plugin-monitor will stored the config file paths in MonitorConfigPaths.
60
66
CustomPluginMonitorConfigPaths []string
61
67
// MonitorConfigPaths specifies the list of paths to configuration files for each monitor.
62
68
MonitorConfigPaths types.ProblemDaemonConfigPathMap
@@ -75,8 +81,10 @@ func NewNodeProblemDetectorOptions() *NodeProblemDetectorOptions {
75
81
func (npdo * NodeProblemDetectorOptions ) AddFlags (fs * pflag.FlagSet ) {
76
82
fs .StringSliceVar (& npdo .SystemLogMonitorConfigPaths , "system-log-monitors" ,
77
83
[]string {}, "List of paths to system log monitor config files, comma separated." )
84
+ fs .MarkDeprecated ("system-log-monitors" , "replaced by --config.system-log-monitor. NPD will panic if both --system-log-monitors and --config.system-log-monitor are set." )
78
85
fs .StringSliceVar (& npdo .CustomPluginMonitorConfigPaths , "custom-plugin-monitors" ,
79
86
[]string {}, "List of paths to custom plugin monitor config files, comma separated." )
87
+ fs .MarkDeprecated ("custom-plugin-monitors" , "replaced by --config.custom-plugin-monitor. NPD will panic if both --custom-plugin-monitors and --config.custom-plugin-monitor are set." )
80
88
fs .BoolVar (& npdo .EnableK8sExporter , "enable-k8s-exporter" , true , "Enables reporting to Kubernetes API server." )
81
89
fs .StringVar (& npdo .ApiServerOverride , "apiserver-override" ,
82
90
"" , "Custom URI used to connect to Kubernetes ApiServer. This is ignored if --enable-k8s-exporter is false." )
@@ -106,14 +114,53 @@ func (npdo *NodeProblemDetectorOptions) ValidOrDie() {
106
114
panic (fmt .Sprintf ("apiserver-override %q is not a valid HTTP URI: %v" ,
107
115
npdo .ApiServerOverride , err ))
108
116
}
109
- if len (npdo .SystemLogMonitorConfigPaths ) == 0 && len (npdo .CustomPluginMonitorConfigPaths ) == 0 {
110
- panic (fmt .Sprintf ("Either --system-log-monitors or --custom-plugin-monitors is required" ))
117
+
118
+ if len (npdo .SystemLogMonitorConfigPaths ) != 0 {
119
+ panic ("SystemLogMonitorConfigPaths is deprecated. It should have been reassigned to MonitorConfigPaths. This should not happen." )
120
+ }
121
+ if len (npdo .CustomPluginMonitorConfigPaths ) != 0 {
122
+ panic ("CustomPluginMonitorConfigPaths is deprecated. It should have been reassigned to MonitorConfigPaths. This should not happen." )
123
+ }
124
+
125
+ configCount := 0
126
+ for _ , problemDaemonConfigPaths := range npdo .MonitorConfigPaths {
127
+ configCount += len (* problemDaemonConfigPaths )
111
128
}
129
+ if configCount == 0 {
130
+ panic ("No configuration option for any problem daemon is specified." )
131
+ }
132
+ }
133
+
134
+ // SetConfigFromDeprecatedOptionsOrDie sets NPD option using deprecated options.
135
+ func (npdo * NodeProblemDetectorOptions ) SetConfigFromDeprecatedOptionsOrDie () {
136
+ if len (npdo .SystemLogMonitorConfigPaths ) != 0 {
137
+ if npdo .MonitorConfigPaths [systemlogmonitor .SystemLogMonitorName ] == nil {
138
+ npdo .MonitorConfigPaths [systemlogmonitor .SystemLogMonitorName ] = & []string {}
139
+ }
112
140
113
- for problemDaemonName , configs := range npdo .MonitorConfigPaths {
114
- if configs == nil {
115
- panic (fmt .Sprintf ("nil config for problem daemon %q. This should never happen, might indicates bug in pflag." , problemDaemonName ))
141
+ if len (* npdo .MonitorConfigPaths [systemlogmonitor .SystemLogMonitorName ]) != 0 {
142
+ panic ("Option --system-log-monitors is deprecated in favor of --config.system-log-monitor. They cannot be set at the same time." )
116
143
}
144
+
145
+ * npdo .MonitorConfigPaths [systemlogmonitor .SystemLogMonitorName ] = append (
146
+ * npdo .MonitorConfigPaths [systemlogmonitor .SystemLogMonitorName ],
147
+ npdo .SystemLogMonitorConfigPaths ... )
148
+ npdo .SystemLogMonitorConfigPaths = []string {}
149
+ }
150
+
151
+ if len (npdo .CustomPluginMonitorConfigPaths ) != 0 {
152
+ if npdo .MonitorConfigPaths [custompluginmonitor .CustomPluginMonitorName ] == nil {
153
+ npdo .MonitorConfigPaths [custompluginmonitor .CustomPluginMonitorName ] = & []string {}
154
+ }
155
+
156
+ if len (* npdo .MonitorConfigPaths [custompluginmonitor .CustomPluginMonitorName ]) != 0 {
157
+ panic ("Option --custom-plugin-monitors is deprecated in favor of --config.custom-plugin-monitor. They cannot be set at the same time." )
158
+ }
159
+
160
+ * npdo .MonitorConfigPaths [custompluginmonitor .CustomPluginMonitorName ] = append (
161
+ * npdo .MonitorConfigPaths [custompluginmonitor .CustomPluginMonitorName ],
162
+ npdo .CustomPluginMonitorConfigPaths ... )
163
+ npdo .CustomPluginMonitorConfigPaths = []string {}
117
164
}
118
165
}
119
166
0 commit comments