| 172 | } |
| 173 | |
| 174 | func (cr *containerReference) GetHealth(ctx context.Context) Health { |
| 175 | inspectResult, err := cr.cli.ContainerInspect(ctx, cr.id, client.ContainerInspectOptions{}) |
| 176 | logger := common.Logger(ctx) |
| 177 | if err != nil { |
| 178 | logger.Errorf("failed to query container health %s", err) |
| 179 | return HealthUnHealthy |
| 180 | } |
| 181 | resp := inspectResult.Container |
| 182 | if resp.Config == nil || resp.Config.Healthcheck == nil || resp.State == nil || resp.State.Health == nil || len(resp.Config.Healthcheck.Test) == 1 && strings.EqualFold(resp.Config.Healthcheck.Test[0], "NONE") { |
| 183 | logger.Debugf("no container health check defined") |
| 184 | return HealthHealthy |
| 185 | } |
| 186 | |
| 187 | logger.Infof("container health of %s (%s) is %s", cr.id, resp.Config.Image, resp.State.Health.Status) |
| 188 | switch resp.State.Health.Status { |
| 189 | case "starting": |
| 190 | return HealthStarting |
| 191 | case "healthy": |
| 192 | return HealthHealthy |
| 193 | case "unhealthy": |
| 194 | return HealthUnHealthy |
| 195 | } |
| 196 | return HealthUnHealthy |
| 197 | } |
| 198 | |
| 199 | func (cr *containerReference) ReplaceLogWriter(stdout io.Writer, stderr io.Writer) (io.Writer, io.Writer) { |
| 200 | out := cr.input.Stdout |