mirror of
https://github.com/kubernetes/node-problem-detector.git
synced 2026-02-14 18:09:57 +00:00
enabled and fixed the errcheck linter rule
This commit is contained in:
@@ -39,11 +39,18 @@ func main() {
|
||||
}
|
||||
})
|
||||
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
|
||||
pflag.CommandLine.MarkHidden("vmodule")
|
||||
pflag.CommandLine.MarkHidden("logtostderr")
|
||||
if err := pflag.CommandLine.MarkHidden("vmodule"); err != nil {
|
||||
klog.Fatalf("Failed to mark hidden flag 'vmodule': %v", err)
|
||||
}
|
||||
if err := pflag.CommandLine.MarkHidden("logtostderr"); err != nil {
|
||||
klog.Fatalf("Failed to mark hidden flag 'logtostderr': %v", err)
|
||||
}
|
||||
|
||||
hco := options.NewHealthCheckerOptions()
|
||||
hco.AddFlags(pflag.CommandLine)
|
||||
if err := hco.AddFlags(pflag.CommandLine); err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(int(types.Unknown))
|
||||
}
|
||||
pflag.Parse()
|
||||
hco.SetDefaults()
|
||||
if err := hco.IsValid(); err != nil {
|
||||
|
||||
@@ -47,12 +47,14 @@ type HealthCheckerOptions struct {
|
||||
}
|
||||
|
||||
// AddFlags adds health checker command line options to pflag.
|
||||
func (hco *HealthCheckerOptions) AddFlags(fs *pflag.FlagSet) {
|
||||
func (hco *HealthCheckerOptions) AddFlags(fs *pflag.FlagSet) error {
|
||||
fs.StringVar(&hco.Component, "component", types.KubeletComponent,
|
||||
"The component to check health for. Supports kubelet, docker, kube-proxy, and cri")
|
||||
// Deprecated: For backward compatibility on linux environment. Going forward "service" will be used instead of systemd-service
|
||||
if runtime.GOOS == "linux" {
|
||||
fs.MarkDeprecated("systemd-service", "please use --service flag instead")
|
||||
if err := fs.MarkDeprecated("systemd-service", "please use --service flag instead"); err != nil {
|
||||
return fmt.Errorf("failed to mark deprecated flag 'systemd-service': %w", err)
|
||||
}
|
||||
fs.StringVar(&hco.Service, "systemd-service", "",
|
||||
"The underlying service responsible for the component. Set to the corresponding component for docker and kubelet, containerd for cri.")
|
||||
}
|
||||
@@ -73,6 +75,7 @@ func (hco *HealthCheckerOptions) AddFlags(fs *pflag.FlagSet) {
|
||||
"The time to wait before marking the component as unhealthy.")
|
||||
fs.Var(&hco.LogPatterns, "log-pattern",
|
||||
"The log pattern to look for in service journald logs. The format for flag value <failureThresholdCount>:<logPattern>")
|
||||
return nil
|
||||
}
|
||||
|
||||
// IsValid validates health checker command line options.
|
||||
|
||||
@@ -96,7 +96,9 @@ func writeTempFile(t *testing.T, ext string, contents string) (string, error) {
|
||||
fileName := f.Name()
|
||||
|
||||
if err := os.WriteFile(fileName, []byte(contents), 0o644); err != nil {
|
||||
os.Remove(fileName)
|
||||
if err := os.Remove(fileName); err != nil {
|
||||
t.Logf("Failed to remove temporary file %s: %v", fileName, err)
|
||||
}
|
||||
return "", fmt.Errorf("cannot write config to temp file %s, %v", fileName, err)
|
||||
}
|
||||
|
||||
@@ -106,7 +108,9 @@ func writeTempFile(t *testing.T, ext string, contents string) (string, error) {
|
||||
func setupNPD(t *testing.T) (*options.NodeProblemDetectorOptions, func()) {
|
||||
fakeLogFileName, err := writeTempFile(t, "log", "")
|
||||
if err != nil {
|
||||
os.Remove(fakeLogFileName)
|
||||
if err := os.Remove(fakeLogFileName); err != nil {
|
||||
t.Logf("Failed to remove temporary file %s: %v", fakeLogFileName, err)
|
||||
}
|
||||
t.Fatalf("cannot create temp config file, %v", err)
|
||||
}
|
||||
|
||||
@@ -114,8 +118,12 @@ func setupNPD(t *testing.T) (*options.NodeProblemDetectorOptions, func()) {
|
||||
|
||||
fakeConfigFileName, err := writeTempFile(t, "json", fakeConfigFileContents)
|
||||
if err != nil {
|
||||
os.Remove(fakeLogFileName)
|
||||
os.Remove(fakeConfigFileName)
|
||||
if err := os.Remove(fakeLogFileName); err != nil {
|
||||
t.Logf("Failed to remove temporary file %s: %v", fakeLogFileName, err)
|
||||
}
|
||||
if err := os.Remove(fakeConfigFileName); err != nil {
|
||||
t.Logf("Failed to remove temporary file %s: %v", fakeConfigFileName, err)
|
||||
}
|
||||
t.Fatalf("cannot create temp config file, %v", err)
|
||||
}
|
||||
|
||||
@@ -126,7 +134,11 @@ func setupNPD(t *testing.T) (*options.NodeProblemDetectorOptions, func()) {
|
||||
},
|
||||
},
|
||||
}, func() {
|
||||
os.Remove(fakeLogFileName)
|
||||
os.Remove(fakeConfigFileName)
|
||||
if err := os.Remove(fakeLogFileName); err != nil {
|
||||
t.Logf("Failed to remove temporary file %s: %v", fakeLogFileName, err)
|
||||
}
|
||||
if err := os.Remove(fakeConfigFileName); err != nil {
|
||||
t.Logf("Failed to remove temporary file %s: %v", fakeConfigFileName, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,11 +38,17 @@ func main() {
|
||||
}
|
||||
})
|
||||
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
|
||||
pflag.CommandLine.MarkHidden("vmodule")
|
||||
pflag.CommandLine.MarkHidden("logtostderr")
|
||||
if err := pflag.CommandLine.MarkHidden("vmodule"); err != nil {
|
||||
klog.Fatalf("Failed to mark hidden flag 'vmodule': %v", err)
|
||||
}
|
||||
if err := pflag.CommandLine.MarkHidden("logtostderr"); err != nil {
|
||||
klog.Fatalf("Failed to mark hidden flag 'logtostderr': %v", err)
|
||||
}
|
||||
|
||||
npdo := options.NewNodeProblemDetectorOptions()
|
||||
npdo.AddFlags(pflag.CommandLine)
|
||||
if err := npdo.AddFlags(pflag.CommandLine); err != nil {
|
||||
klog.Fatalf("Failed to add flags: %v", err)
|
||||
}
|
||||
|
||||
pflag.Parse()
|
||||
if err := npdMain(context.Background(), npdo); err != nil {
|
||||
|
||||
@@ -53,11 +53,17 @@ func main() {
|
||||
}
|
||||
})
|
||||
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
|
||||
pflag.CommandLine.MarkHidden("vmodule")
|
||||
pflag.CommandLine.MarkHidden("logtostderr")
|
||||
if err := pflag.CommandLine.MarkHidden("vmodule"); err != nil {
|
||||
klog.Fatalf("Failed to mark hidden flag 'vmodule': %v", err)
|
||||
}
|
||||
if err := pflag.CommandLine.MarkHidden("logtostderr"); err != nil {
|
||||
klog.Fatalf("Failed to mark hidden flag 'logtostderr': %v", err)
|
||||
}
|
||||
|
||||
npdo := options.NewNodeProblemDetectorOptions()
|
||||
npdo.AddFlags(pflag.CommandLine)
|
||||
if err := npdo.AddFlags(pflag.CommandLine); err != nil {
|
||||
klog.Fatalf("Failed to add flags: %v", err)
|
||||
}
|
||||
|
||||
pflag.Parse()
|
||||
|
||||
|
||||
@@ -106,13 +106,17 @@ func NewNodeProblemDetectorOptions() *NodeProblemDetectorOptions {
|
||||
}
|
||||
|
||||
// AddFlags adds node problem detector command line options to pflag.
|
||||
func (npdo *NodeProblemDetectorOptions) AddFlags(fs *pflag.FlagSet) {
|
||||
func (npdo *NodeProblemDetectorOptions) AddFlags(fs *pflag.FlagSet) error {
|
||||
fs.StringSliceVar(&npdo.SystemLogMonitorConfigPaths, "system-log-monitors",
|
||||
[]string{}, "List of paths to system log monitor config files, comma separated.")
|
||||
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.")
|
||||
if err := 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."); err != nil {
|
||||
return fmt.Errorf("failed to mark 'system-log-monitors' as deprecated: %w", err)
|
||||
}
|
||||
fs.StringSliceVar(&npdo.CustomPluginMonitorConfigPaths, "custom-plugin-monitors",
|
||||
[]string{}, "List of paths to custom plugin monitor config files, comma separated.")
|
||||
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.")
|
||||
if err := 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."); err != nil {
|
||||
return fmt.Errorf("failed to mark 'custom-plugin-monitors' as deprecated: %w", err)
|
||||
}
|
||||
fs.BoolVar(&npdo.EnableK8sExporter, "enable-k8s-exporter", true, "Enables reporting to Kubernetes API server.")
|
||||
fs.StringVar(&npdo.EventNamespace, "event-namespace", "", "Namespace for recorded Kubernetes events.")
|
||||
fs.StringVar(&npdo.ApiServerOverride, "apiserver-override",
|
||||
@@ -149,6 +153,7 @@ func (npdo *NodeProblemDetectorOptions) AddFlags(fs *pflag.FlagSet) {
|
||||
problemDaemonName,
|
||||
problemdaemon.GetProblemDaemonHandlerOrDie(problemDaemonName).CmdOptionDescription))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ValidOrDie validates node problem detector command line options.
|
||||
|
||||
Reference in New Issue
Block a user