Skip to content

Commit

Permalink
Add an e2e test for exec liveness probes. Fix the docker exec integra…
Browse files Browse the repository at this point in the history
…tion.
  • Loading branch information
brendandburns committed Dec 16, 2014
1 parent 56ee668 commit 3a0d16f
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 26 deletions.
22 changes: 22 additions & 0 deletions examples/liveness/exec-liveness.yaml
Original file line number Diff line number Diff line change
@@ -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
41 changes: 23 additions & 18 deletions hack/e2e-suite/liveness.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
done

if [[ "${before}" < "${after}" ]]; then
exit 0
fi
echo "Unexpected absence of failures in ${test}"
echo "Restarts before: ${before}."
echo "Restarts after: ${after}"
exit 1
done

echo "Unexpected absence of failures."
echo "Restarts before: ${before}."
echo "Restarts after: ${after}"
exit 1
exit 0
12 changes: 6 additions & 6 deletions pkg/kubelet/dockertools/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
Expand All @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/kubelet/dockertools/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 3a0d16f

Please sign in to comment.