separate linux/windows health checker files.

This commit is contained in:
michelletandya
2021-04-26 21:45:05 +00:00
parent 744a689454
commit c4e5400ed6
15 changed files with 467 additions and 140 deletions
+1 -1
View File
@@ -55,7 +55,7 @@ func main() {
os.Exit(int(types.Unknown))
}
if !healthy {
fmt.Printf("%v:%v was found unhealthy; repair flag : %v\n", hco.Component, hco.SystemdService, hco.EnableRepair)
fmt.Printf("%v:%v was found unhealthy; repair flag : %v\n", hco.Component, hco.Service, hco.EnableRepair)
os.Exit(int(types.NonOK))
}
os.Exit(int(types.OK))
+16 -9
View File
@@ -19,6 +19,7 @@ package options
import (
"flag"
"fmt"
"runtime"
"time"
"github.com/spf13/pflag"
@@ -34,7 +35,7 @@ func NewHealthCheckerOptions() *HealthCheckerOptions {
// HealthCheckerOptions are the options used to configure the health checker.
type HealthCheckerOptions struct {
Component string
SystemdService string
Service string
EnableRepair bool
CriCtlPath string
CriSocketPath string
@@ -47,8 +48,14 @@ type HealthCheckerOptions struct {
func (hco *HealthCheckerOptions) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&hco.Component, "component", types.KubeletComponent,
"The component to check health for. Supports kubelet, docker and cri")
fs.StringVar(&hco.SystemdService, "systemd-service", "",
"The underlying systemd service responsible for the component. Set to the corresponding component for docker and kubelet, containerd for 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")
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.")
}
fs.StringVar(&hco.Service, "service", "",
"The underlying service responsible for the component. Set to the corresponding component for docker and kubelet, containerd for cri.")
fs.BoolVar(&hco.EnableRepair, "enable-repair", true, "Flag to enable/disable repair attempt for the component.")
fs.StringVar(&hco.CriCtlPath, "crictl-path", types.DefaultCriCtl,
"The path to the crictl binary. This is used to check health of cri component.")
@@ -69,9 +76,9 @@ func (hco *HealthCheckerOptions) IsValid() error {
if hco.Component != types.KubeletComponent && hco.Component != types.DockerComponent && hco.Component != types.CRIComponent {
return fmt.Errorf("the component specified is not supported. Supported components are : <kubelet/docker/cri>")
}
// Make sure the systemd service is specified if repair is enabled.
if hco.EnableRepair && hco.SystemdService == "" {
return fmt.Errorf("systemd-service cannot be empty when repair is enabled")
// Make sure the service is specified if repair is enabled.
if hco.EnableRepair && hco.Service == "" {
return fmt.Errorf("service cannot be empty when repair is enabled")
}
// Skip checking further if the component is not cri.
if hco.Component != types.CRIComponent {
@@ -90,14 +97,14 @@ func (hco *HealthCheckerOptions) IsValid() error {
// SetDefaults sets the defaults values for the dependent flags.
func (hco *HealthCheckerOptions) SetDefaults() {
if hco.SystemdService != "" {
if hco.Service != "" {
return
}
if hco.Component != types.CRIComponent {
hco.SystemdService = hco.Component
hco.Service = hco.Component
return
}
hco.SystemdService = types.ContainerdService
hco.Service = types.ContainerdService
}
func init() {
+3 -3
View File
@@ -56,9 +56,9 @@ func TestIsValid(t *testing.T) {
{
name: "empty systemd-service and repair enabled",
hco: HealthCheckerOptions{
Component: types.KubeletComponent,
EnableRepair: true,
SystemdService: "",
Component: types.KubeletComponent,
EnableRepair: true,
Service: "",
},
expectError: true,
},
@@ -1,3 +1,5 @@
// +build !disable_system_log_monitor
/*
Copyright 2021 The Kubernetes Authors All rights reserved.
@@ -1,3 +1,5 @@
// +build !disable_system_log_monitor
/*
Copyright 2021 The Kubernetes Authors All rights reserved.