Skip to content

Commit

Permalink
Merge pull request #822 from vrothberg/healthcheck
Browse files Browse the repository at this point in the history
libimage: inspect: extract healthchecks from configs
  • Loading branch information
openshift-merge-robot authored Nov 9, 2021
2 parents ca3c041 + af5ad62 commit c342e49
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
20 changes: 20 additions & 0 deletions libimage/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,26 @@ func TestImageFunctions(t *testing.T) {
require.Equal(t, image.NamesHistory(), imageData.NamesHistory, "inspect data should match")
}

func TestInspectHealthcheck(t *testing.T) {
runtime, cleanup := testNewRuntime(t)
defer cleanup()
ctx := context.Background()

imageName := "quay.io/libpod/healthcheck:config-only"
pullOptions := &PullOptions{}
pullOptions.Writer = os.Stdout
pulledImages, err := runtime.Pull(ctx, imageName, config.PullPolicyAlways, pullOptions)
require.NoError(t, err)
require.Len(t, pulledImages, 1)
image := pulledImages[0]

// Now compare the inspect data to what we expect.
imageData, err := image.Inspect(ctx, nil)
require.NoError(t, err)
require.NotNil(t, imageData.HealthCheck, "health check should be found in config")
require.Equal(t, []string{"CMD-SHELL", "curl -f http://localhost/ || exit 1"}, imageData.HealthCheck.Test, "health check should be found in config")
}

func TestTag(t *testing.T) {
// Note: this will resolve pull from the GCR registry (see
// testdata/registries.conf).
Expand Down
5 changes: 5 additions & 0 deletions libimage/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,12 @@ func (i *Image) Inspect(ctx context.Context, options *InspectOptions) (*ImageDat
return nil, err
}
data.Comment = dockerManifest.Comment
// NOTE: Health checks may be listed in the container config or
// the config.
data.HealthCheck = dockerManifest.ContainerConfig.Healthcheck
if data.HealthCheck == nil {
data.HealthCheck = dockerManifest.Config.Healthcheck
}
}

if data.Annotations == nil {
Expand Down

0 comments on commit c342e49

Please sign in to comment.