getHealthCheckFunc returns the health check function based on the component.
(hco *options.HealthCheckerOptions)
| 150 | |
| 151 | // getHealthCheckFunc returns the health check function based on the component. |
| 152 | func getHealthCheckFunc(hco *options.HealthCheckerOptions) func() (bool, error) { |
| 153 | switch hco.Component { |
| 154 | case types.KubeletComponent: |
| 155 | return healthCheckEndpointOKFunc(types.KubeletHealthCheckEndpoint(), hco.HealthCheckTimeout) |
| 156 | case types.KubeProxyComponent: |
| 157 | return healthCheckEndpointOKFunc(types.KubeProxyHealthCheckEndpoint(), hco.HealthCheckTimeout) |
| 158 | case types.DockerComponent: |
| 159 | return func() (bool, error) { |
| 160 | if _, err := execCommand(hco.HealthCheckTimeout, getDockerPath(), "ps"); err != nil { |
| 161 | return false, nil |
| 162 | } |
| 163 | return true, nil |
| 164 | } |
| 165 | case types.CRIComponent: |
| 166 | return func() (bool, error) { |
| 167 | _, err := execCommand( |
| 168 | hco.HealthCheckTimeout, |
| 169 | hco.CriCtlPath, |
| 170 | "--timeout="+hco.CriTimeout.String(), |
| 171 | "--runtime-endpoint="+hco.CriSocketPath, |
| 172 | "pods", |
| 173 | "--latest", |
| 174 | ) |
| 175 | if err != nil { |
| 176 | return false, nil |
| 177 | } |
| 178 | return true, nil |
| 179 | } |
| 180 | default: |
| 181 | klog.Warningf("Unsupported component: %v", hco.Component) |
| 182 | } |
| 183 | |
| 184 | return nil |
| 185 | } |
| 186 | |
| 187 | // execCommand executes the bash command and returns the (output, error) from command, error if timeout occurs. |
| 188 | func execCommand(timeout time.Duration, command string, args ...string) (string, error) { |