Add an e2e test for exec liveness probes. Fix the docker exec integration.

This commit is contained in:
Brendan Burns 2014-12-16 13:06:58 -08:00
parent 56ee66831b
commit 3a0d16ff35
4 changed files with 53 additions and 26 deletions

View File

@ -0,0 +1,22 @@
apiVersion: v1beta1
desiredState:
manifest:
containers:
- image: busybox
name: liveness
livenessProbe:
exec:
command:
- "cat"
- "/tmp/health"
initialDelaySeconds: 15
command:
- "/bin/sh"
- "-c"
- "echo ok > /tmp/health; sleep 10; echo fail > /tmp/health; sleep 600"
id: liveness-exec
version: v1beta1
id: liveness-exec
kind: Pod
labels:
test: liveness

View File

@ -28,6 +28,7 @@ source "${KUBE_ROOT}/cluster/$KUBERNETES_PROVIDER/util.sh"
function teardown() {
echo "Cleaning up test artifacts"
${KUBECFG} delete pods/liveness-http
${KUBECFG} delete pods/liveness-exec
}
function waitForNotPending() {
@ -57,26 +58,30 @@ function waitForNotPending() {
trap "teardown" EXIT
${KUBECFG} -c ${KUBE_ROOT}/examples/liveness/http-liveness.yaml create pods
waitForNotPending
for test in http exec; do
echo "Liveness test: ${test}"
${KUBECFG} -c ${KUBE_ROOT}/examples/liveness/${test}-liveness.yaml create pods
waitForNotPending
before=$(${KUBECFG} '-template={{.currentState.info.liveness.restartCount}}' get pods/liveness-http)
before=$(${KUBECFG} '-template={{.currentState.info.liveness.restartCount}}' get pods/liveness-${test})
echo "Waiting for restarts."
for i in $(seq 1 24); do
sleep 10
after=$(${KUBECFG} '-template={{.currentState.info.liveness.restartCount}}' get pods/liveness-${test})
echo "Restarts: ${after} > ${before}"
if [[ "${after}" > "${before}" ]]; then
break
fi
done
echo "Waiting for restarts."
for i in $(seq 1 24); do
sleep 10
after=$(${KUBECFG} '-template={{.currentState.info.liveness.restartCount}}' get pods/liveness-http)
echo "Restarts: ${after} > ${before}"
if [[ "${after}" > "${before}" ]]; then
break
if [[ "${before}" < "${after}" ]]; then
continue
fi
echo "Unexpected absence of failures in ${test}"
echo "Restarts before: ${before}."
echo "Restarts after: ${after}"
exit 1
done
if [[ "${before}" < "${after}" ]]; then
exit 0
fi
echo "Unexpected absence of failures."
echo "Restarts before: ${before}."
echo "Restarts after: ${after}"
exit 1
exit 0

View File

@ -92,8 +92,8 @@ type dockerContainerCommandRunner struct {
client DockerInterface
}
// The first version of docker that supports exec natively is 1.3.0
var dockerVersionWithExec = []uint{1, 3, 0}
// The first version of docker that supports exec natively is 1.3.0 == API 1.15
var dockerAPIVersionWithExec = []uint{1, 15}
// Returns the major and minor version numbers of docker server.
func (d *dockerContainerCommandRunner) getDockerServerVersion() ([]uint, error) {
@ -103,7 +103,7 @@ func (d *dockerContainerCommandRunner) getDockerServerVersion() ([]uint, error)
}
version := []uint{}
for _, entry := range *env {
if strings.Contains(strings.ToLower(entry), "server version") {
if strings.Contains(strings.ToLower(entry), "apiversion") || strings.Contains(strings.ToLower(entry), "api version") {
elems := strings.Split(strings.Split(entry, "=")[1], ".")
for _, elem := range elems {
val, err := strconv.ParseUint(elem, 10, 32)
@ -123,10 +123,10 @@ func (d *dockerContainerCommandRunner) nativeExecSupportExists() (bool, error) {
if err != nil {
return false, err
}
if len(dockerVersionWithExec) != len(version) {
return false, fmt.Errorf("unexpected docker version format. Expecting %v format, got %v", dockerVersionWithExec, version)
if len(dockerAPIVersionWithExec) != len(version) {
return false, fmt.Errorf("unexpected docker version format. Expecting %v format, got %v", dockerAPIVersionWithExec, version)
}
for idx, val := range dockerVersionWithExec {
for idx, val := range dockerAPIVersionWithExec {
if version[idx] < val {
return false, nil
}

View File

@ -130,7 +130,7 @@ func TestGetDockerServerVersion(t *testing.T) {
if err != nil {
t.Errorf("got error while getting docker server version - %s", err)
}
expectedVersion := []uint{1, 1, 3}
expectedVersion := []uint{1, 15}
if len(expectedVersion) != len(version) {
t.Errorf("invalid docker server version. expected: %v, got: %v", expectedVersion, version)
} else {
@ -155,7 +155,7 @@ func TestExecSupportExists(t *testing.T) {
}
func TestExecSupportNotExists(t *testing.T) {
fakeDocker := &FakeDockerClient{VersionInfo: docker.Env{"Client version=1.2", "Server version=1.1.2", "Server API version=1.15"}}
fakeDocker := &FakeDockerClient{VersionInfo: docker.Env{"Client version=1.2", "Server version=1.1.2", "Server API version=1.14"}}
runner := dockerContainerCommandRunner{fakeDocker}
useNativeExec, _ := runner.nativeExecSupportExists()
if useNativeExec {