IsServing returns true if the client can successfully connect to the containerd daemon and the healthcheck service returns the SERVING response. This call will block if a transient error is encountered during connection. A timeout can be set in the context to ensure it returns early.
(ctx context.Context)
| 309 | // connection. A timeout can be set in the context to ensure it returns |
| 310 | // early. |
| 311 | func (c *Client) IsServing(ctx context.Context) (bool, error) { |
| 312 | c.connMu.Lock() |
| 313 | if c.conn == nil { |
| 314 | c.connMu.Unlock() |
| 315 | return false, fmt.Errorf("no grpc connection available: %w", errdefs.ErrUnavailable) |
| 316 | } |
| 317 | c.connMu.Unlock() |
| 318 | r, err := c.HealthService().Check(ctx, &grpc_health_v1.HealthCheckRequest{}, grpc.WaitForReady(true)) |
| 319 | if err != nil { |
| 320 | return false, err |
| 321 | } |
| 322 | return r.Status == grpc_health_v1.HealthCheckResponse_SERVING, nil |
| 323 | } |
| 324 | |
| 325 | // Containers returns all containers created in containerd |
| 326 | func (c *Client) Containers(ctx context.Context, filters ...string) ([]Container, error) { |