aboutsummaryrefslogtreecommitdiff
path: root/pkg/bindings
diff options
context:
space:
mode:
authorBrent Baude <bbaude@redhat.com>2020-02-25 13:51:49 -0600
committerBrent Baude <bbaude@redhat.com>2020-03-13 07:43:12 -0500
commit2099643aa2929e8d394c8b0fb584ad90075ad0b5 (patch)
treea40d66583f16581bcfd0ed2094acf478d151e442 /pkg/bindings
parentc9f148fb154ca45081e3ebfc0c14fa9ee995780d (diff)
downloadpodman-2099643aa2929e8d394c8b0fb584ad90075ad0b5.tar.gz
podman-2099643aa2929e8d394c8b0fb584ad90075ad0b5.tar.bz2
podman-2099643aa2929e8d394c8b0fb584ad90075ad0b5.zip
add apiv2 healthcheck code
reworking binding and endpoint to actually work. added documentation in swagger for and various return code possibilities. add a good start on tests though we need some other container functions not yet implemented for that. Signed-off-by: Brent Baude <bbaude@redhat.com>
Diffstat (limited to 'pkg/bindings')
-rw-r--r--pkg/bindings/containers/healthcheck.go6
-rw-r--r--pkg/bindings/test/containers_test.go45
2 files changed, 48 insertions, 3 deletions
diff --git a/pkg/bindings/containers/healthcheck.go b/pkg/bindings/containers/healthcheck.go
index 3f94fad01..85cc2814c 100644
--- a/pkg/bindings/containers/healthcheck.go
+++ b/pkg/bindings/containers/healthcheck.go
@@ -10,15 +10,15 @@ import (
// RunHealthCheck executes the container's healthcheck and returns the health status of the
// container.
-func RunHealthCheck(ctx context.Context, nameOrID string) (*libpod.HealthCheckStatus, error) {
+func RunHealthCheck(ctx context.Context, nameOrID string) (*libpod.HealthCheckResults, error) {
conn, err := bindings.GetClient(ctx)
if err != nil {
return nil, err
}
var (
- status libpod.HealthCheckStatus
+ status libpod.HealthCheckResults
)
- response, err := conn.DoRequest(nil, http.MethodGet, "/containers/%s/runhealthcheck", nil, nameOrID)
+ response, err := conn.DoRequest(nil, http.MethodGet, "/containers/%s/healthcheck", nil, nameOrID)
if err != nil {
return nil, err
}
diff --git a/pkg/bindings/test/containers_test.go b/pkg/bindings/test/containers_test.go
index e7ef620d4..34a9c3136 100644
--- a/pkg/bindings/test/containers_test.go
+++ b/pkg/bindings/test/containers_test.go
@@ -312,4 +312,49 @@ var _ = Describe("Podman containers ", func() {
Expect(exitCode).To(BeNumerically("==", -1))
})
+ It("run healthcheck", func() {
+ bt.runPodman([]string{"run", "-d", "--name", "hc", "--health-interval", "disable", "--health-retries", "2", "--health-cmd", "ls / || exit 1", alpine.name, "top"})
+
+ // bogus name should result in 404
+ _, err := containers.RunHealthCheck(bt.conn, "foobar")
+ Expect(err).ToNot(BeNil())
+ code, _ := bindings.CheckResponseCode(err)
+ Expect(code).To(BeNumerically("==", http.StatusNotFound))
+
+ // a container that has no healthcheck should be a 409
+ var name = "top"
+ bt.RunTopContainer(&name, &falseFlag, nil)
+ _, err = containers.RunHealthCheck(bt.conn, name)
+ Expect(err).ToNot(BeNil())
+ code, _ = bindings.CheckResponseCode(err)
+ Expect(code).To(BeNumerically("==", http.StatusConflict))
+
+ // TODO for the life of me, i cannot get this to work. maybe another set
+ // of eyes will
+ // successful healthcheck
+ //status := "healthy"
+ //for i:=0; i < 10; i++ {
+ // result, err := containers.RunHealthCheck(connText, "hc")
+ // Expect(err).To(BeNil())
+ // if result.Status != "healthy" {
+ // fmt.Println("Healthcheck container still starting, retrying in 1 second")
+ // time.Sleep(1 * time.Second)
+ // continue
+ // }
+ // status = result.Status
+ // break
+ //}
+ //Expect(status).To(Equal("healthy"))
+
+ // TODO enable this when wait is working
+ // healthcheck on a stopped container should be a 409
+ //err = containers.Stop(connText, "hc", nil)
+ //Expect(err).To(BeNil())
+ //_, err = containers.Wait(connText, "hc")
+ //Expect(err).To(BeNil())
+ //_, err = containers.RunHealthCheck(connText, "hc")
+ //code, _ = bindings.CheckResponseCode(err)
+ //Expect(code).To(BeNumerically("==", http.StatusConflict))
+ })
+
})