MCPcopy
hub / github.com/kubernetes/node-problem-detector / getHealthCheckFunc

Function getHealthCheckFunc

pkg/healthchecker/health_checker.go:152–185  ·  view source on GitHub ↗

getHealthCheckFunc returns the health check function based on the component.

(hco *options.HealthCheckerOptions)

Source from the content-addressed store, hash-verified

150
151// getHealthCheckFunc returns the health check function based on the component.
152func 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.
188func execCommand(timeout time.Duration, command string, args ...string) (string, error) {

Callers 2

NewHealthCheckerFunction · 0.85
TestComponentsSupportedFunction · 0.85

Calls 6

execCommandFunction · 0.85
getDockerPathFunction · 0.70
StringMethod · 0.65

Tested by 1

TestComponentsSupportedFunction · 0.68