2015-01-13 02:11:27 +00:00
|
|
|
/*
|
2015-05-01 16:19:44 +00:00
|
|
|
Copyright 2014 The Kubernetes Authors All rights reserved.
|
2015-01-13 02:11:27 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package e2e
|
|
|
|
|
|
|
|
import (
|
Expose exec and logs via WebSockets
Not all clients and systems can support SPDY protocols. This commit adds
support for two new websocket protocols, one to handle streaming of pod
logs from a pod, and the other to allow exec to be tunneled over
websocket.
Browser support for chunked encoding is still poor, and web consoles
that wish to show pod logs may need to make compromises to display the
output. The /pods/<name>/log endpoint now supports websocket upgrade to
the 'binary.k8s.io' subprotocol, which sends chunks of logs as binary to
the client. Messages are written as logs are streamed from the container
daemon, so flushing should be unaffected.
Browser support for raw communication over SDPY is not possible, and
some languages lack libraries for it and HTTP/2. The Kubelet supports
upgrade to WebSocket instead of SPDY, and will multiplex STDOUT/IN/ERR
over websockets by prepending each binary message with a single byte
representing the channel (0 for IN, 1 for OUT, and 2 for ERR). Because
framing on WebSockets suffers from head-of-line blocking, clients and
other server code should ensure that no particular stream blocks. An
alternative subprotocol 'base64.channel.k8s.io' base64 encodes the body
and uses '0'-'9' to represent the channel for ease of use in browsers.
2015-09-11 20:09:51 +00:00
|
|
|
"bytes"
|
2015-01-30 20:59:13 +00:00
|
|
|
"fmt"
|
Expose exec and logs via WebSockets
Not all clients and systems can support SPDY protocols. This commit adds
support for two new websocket protocols, one to handle streaming of pod
logs from a pod, and the other to allow exec to be tunneled over
websocket.
Browser support for chunked encoding is still poor, and web consoles
that wish to show pod logs may need to make compromises to display the
output. The /pods/<name>/log endpoint now supports websocket upgrade to
the 'binary.k8s.io' subprotocol, which sends chunks of logs as binary to
the client. Messages are written as logs are streamed from the container
daemon, so flushing should be unaffected.
Browser support for raw communication over SDPY is not possible, and
some languages lack libraries for it and HTTP/2. The Kubelet supports
upgrade to WebSocket instead of SPDY, and will multiplex STDOUT/IN/ERR
over websockets by prepending each binary message with a single byte
representing the channel (0 for IN, 1 for OUT, and 2 for ERR). Because
framing on WebSockets suffers from head-of-line blocking, clients and
other server code should ensure that no particular stream blocks. An
alternative subprotocol 'base64.channel.k8s.io' base64 encodes the body
and uses '0'-'9' to represent the channel for ease of use in browsers.
2015-09-11 20:09:51 +00:00
|
|
|
"io"
|
2015-01-13 02:11:27 +00:00
|
|
|
"strconv"
|
Expose exec and logs via WebSockets
Not all clients and systems can support SPDY protocols. This commit adds
support for two new websocket protocols, one to handle streaming of pod
logs from a pod, and the other to allow exec to be tunneled over
websocket.
Browser support for chunked encoding is still poor, and web consoles
that wish to show pod logs may need to make compromises to display the
output. The /pods/<name>/log endpoint now supports websocket upgrade to
the 'binary.k8s.io' subprotocol, which sends chunks of logs as binary to
the client. Messages are written as logs are streamed from the container
daemon, so flushing should be unaffected.
Browser support for raw communication over SDPY is not possible, and
some languages lack libraries for it and HTTP/2. The Kubelet supports
upgrade to WebSocket instead of SPDY, and will multiplex STDOUT/IN/ERR
over websockets by prepending each binary message with a single byte
representing the channel (0 for IN, 1 for OUT, and 2 for ERR). Because
framing on WebSockets suffers from head-of-line blocking, clients and
other server code should ensure that no particular stream blocks. An
alternative subprotocol 'base64.channel.k8s.io' base64 encodes the body
and uses '0'-'9' to represent the channel for ease of use in browsers.
2015-09-11 20:09:51 +00:00
|
|
|
"strings"
|
2015-01-13 02:11:27 +00:00
|
|
|
"time"
|
|
|
|
|
Expose exec and logs via WebSockets
Not all clients and systems can support SPDY protocols. This commit adds
support for two new websocket protocols, one to handle streaming of pod
logs from a pod, and the other to allow exec to be tunneled over
websocket.
Browser support for chunked encoding is still poor, and web consoles
that wish to show pod logs may need to make compromises to display the
output. The /pods/<name>/log endpoint now supports websocket upgrade to
the 'binary.k8s.io' subprotocol, which sends chunks of logs as binary to
the client. Messages are written as logs are streamed from the container
daemon, so flushing should be unaffected.
Browser support for raw communication over SDPY is not possible, and
some languages lack libraries for it and HTTP/2. The Kubelet supports
upgrade to WebSocket instead of SPDY, and will multiplex STDOUT/IN/ERR
over websockets by prepending each binary message with a single byte
representing the channel (0 for IN, 1 for OUT, and 2 for ERR). Because
framing on WebSockets suffers from head-of-line blocking, clients and
other server code should ensure that no particular stream blocks. An
alternative subprotocol 'base64.channel.k8s.io' base64 encodes the body
and uses '0'-'9' to represent the channel for ease of use in browsers.
2015-09-11 20:09:51 +00:00
|
|
|
"golang.org/x/net/websocket"
|
|
|
|
|
2015-08-05 22:03:47 +00:00
|
|
|
"k8s.io/kubernetes/pkg/api"
|
|
|
|
"k8s.io/kubernetes/pkg/api/errors"
|
|
|
|
"k8s.io/kubernetes/pkg/api/resource"
|
2015-08-13 19:01:50 +00:00
|
|
|
client "k8s.io/kubernetes/pkg/client/unversioned"
|
2015-10-15 04:58:20 +00:00
|
|
|
"k8s.io/kubernetes/pkg/kubelet"
|
2015-08-05 22:03:47 +00:00
|
|
|
"k8s.io/kubernetes/pkg/labels"
|
|
|
|
"k8s.io/kubernetes/pkg/util"
|
2015-11-10 06:28:45 +00:00
|
|
|
"k8s.io/kubernetes/pkg/util/intstr"
|
2015-08-05 22:03:47 +00:00
|
|
|
"k8s.io/kubernetes/pkg/util/wait"
|
|
|
|
"k8s.io/kubernetes/pkg/watch"
|
2016-04-07 17:21:31 +00:00
|
|
|
"k8s.io/kubernetes/test/e2e/framework"
|
2015-01-28 00:38:48 +00:00
|
|
|
|
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
. "github.com/onsi/gomega"
|
2015-01-13 02:11:27 +00:00
|
|
|
)
|
|
|
|
|
2015-09-30 00:00:19 +00:00
|
|
|
const (
|
|
|
|
defaultObservationTimeout = time.Minute * 2
|
|
|
|
)
|
|
|
|
|
2015-10-15 04:58:20 +00:00
|
|
|
var (
|
|
|
|
buildBackOffDuration = time.Minute
|
|
|
|
syncLoopFrequency = 10 * time.Second
|
|
|
|
maxBackOffTolerance = time.Duration(1.3 * float64(kubelet.MaxContainerBackOff))
|
|
|
|
)
|
|
|
|
|
2015-09-30 00:00:19 +00:00
|
|
|
func runLivenessTest(c *client.Client, ns string, podDescr *api.Pod, expectNumRestarts int, timeout time.Duration) {
|
2015-02-10 14:03:21 +00:00
|
|
|
By(fmt.Sprintf("Creating pod %s in namespace %s", podDescr.Name, ns))
|
2015-07-09 11:56:19 +00:00
|
|
|
_, err := c.Pods(ns).Create(podDescr)
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.ExpectNoError(err, fmt.Sprintf("creating pod %s", podDescr.Name))
|
2015-02-10 14:03:21 +00:00
|
|
|
|
|
|
|
// At the end of the test, clean up by removing the pod.
|
|
|
|
defer func() {
|
|
|
|
By("deleting the pod")
|
2015-08-20 02:09:57 +00:00
|
|
|
c.Pods(ns).Delete(podDescr.Name, api.NewDeleteOptions(0))
|
2015-02-10 14:03:21 +00:00
|
|
|
}()
|
|
|
|
|
|
|
|
// Wait until the pod is not pending. (Here we need to check for something other than
|
|
|
|
// 'Pending' other than checking for 'Running', since when failures occur, we go to
|
|
|
|
// 'Terminated' which can cause indefinite blocking.)
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.ExpectNoError(framework.WaitForPodNotPending(c, ns, podDescr.Name),
|
2015-02-12 18:37:31 +00:00
|
|
|
fmt.Sprintf("starting pod %s in namespace %s", podDescr.Name, ns))
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Logf("Started pod %s in namespace %s", podDescr.Name, ns)
|
2015-02-10 14:03:21 +00:00
|
|
|
|
|
|
|
// Check the pod's current state and verify that restartCount is present.
|
|
|
|
By("checking the pod's current state and verifying that restartCount is present")
|
|
|
|
pod, err := c.Pods(ns).Get(podDescr.Name)
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.ExpectNoError(err, fmt.Sprintf("getting pod %s in namespace %s", podDescr.Name, ns))
|
2015-03-25 11:09:35 +00:00
|
|
|
initialRestartCount := api.GetExistingContainerStatus(pod.Status.ContainerStatuses, "liveness").RestartCount
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Logf("Initial restart count of pod %s is %d", podDescr.Name, initialRestartCount)
|
2015-02-10 14:03:21 +00:00
|
|
|
|
2015-07-18 01:17:06 +00:00
|
|
|
// Wait for the restart state to be as desired.
|
2015-09-30 00:00:19 +00:00
|
|
|
deadline := time.Now().Add(timeout)
|
2015-08-21 23:46:17 +00:00
|
|
|
lastRestartCount := initialRestartCount
|
2016-04-27 04:35:14 +00:00
|
|
|
observedRestarts := int32(0)
|
2015-07-18 01:17:06 +00:00
|
|
|
for start := time.Now(); time.Now().Before(deadline); time.Sleep(2 * time.Second) {
|
2015-02-10 14:03:21 +00:00
|
|
|
pod, err = c.Pods(ns).Get(podDescr.Name)
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.ExpectNoError(err, fmt.Sprintf("getting pod %s", podDescr.Name))
|
2015-03-25 11:09:35 +00:00
|
|
|
restartCount := api.GetExistingContainerStatus(pod.Status.ContainerStatuses, "liveness").RestartCount
|
2015-08-21 23:46:17 +00:00
|
|
|
if restartCount != lastRestartCount {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Logf("Restart count of pod %s/%s is now %d (%v elapsed)",
|
2016-02-01 21:44:31 +00:00
|
|
|
ns, podDescr.Name, restartCount, time.Since(start))
|
2015-08-21 23:46:17 +00:00
|
|
|
if restartCount < lastRestartCount {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Failf("Restart count should increment monotonically: restart cont of pod %s/%s changed from %d to %d",
|
2015-08-21 23:46:17 +00:00
|
|
|
ns, podDescr.Name, lastRestartCount, restartCount)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
observedRestarts = restartCount - initialRestartCount
|
2016-04-27 04:35:14 +00:00
|
|
|
if expectNumRestarts > 0 && int(observedRestarts) >= expectNumRestarts {
|
2015-08-21 23:46:17 +00:00
|
|
|
// Stop if we have observed more than expectNumRestarts restarts.
|
2015-02-10 14:03:21 +00:00
|
|
|
break
|
|
|
|
}
|
2015-08-21 23:46:17 +00:00
|
|
|
lastRestartCount = restartCount
|
2015-02-10 14:03:21 +00:00
|
|
|
}
|
|
|
|
|
2015-08-21 23:46:17 +00:00
|
|
|
// If we expected 0 restarts, fail if observed any restart.
|
|
|
|
// If we expected n restarts (n > 0), fail if we observed < n restarts.
|
|
|
|
if (expectNumRestarts == 0 && observedRestarts > 0) || (expectNumRestarts > 0 &&
|
2016-04-27 04:35:14 +00:00
|
|
|
int(observedRestarts) < expectNumRestarts) {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Failf("pod %s/%s - expected number of restarts: %t, found restarts: %t",
|
2015-08-21 23:46:17 +00:00
|
|
|
ns, podDescr.Name, expectNumRestarts, observedRestarts)
|
2015-02-10 14:03:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-10 20:00:07 +00:00
|
|
|
// testHostIP tests that a pod gets a host IP
|
2015-07-09 11:56:19 +00:00
|
|
|
func testHostIP(c *client.Client, ns string, pod *api.Pod) {
|
2015-04-10 20:00:07 +00:00
|
|
|
podClient := c.Pods(ns)
|
|
|
|
By("creating pod")
|
2015-08-20 02:09:57 +00:00
|
|
|
defer podClient.Delete(pod.Name, api.NewDeleteOptions(0))
|
|
|
|
if _, err := podClient.Create(pod); err != nil {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Failf("Failed to create pod: %v", err)
|
2015-04-10 20:00:07 +00:00
|
|
|
}
|
|
|
|
By("ensuring that pod is running and has a hostIP")
|
|
|
|
// Wait for the pods to enter the running state. Waiting loops until the pods
|
|
|
|
// are running so non-running pods cause a timeout for this test.
|
2016-04-07 17:21:31 +00:00
|
|
|
err := framework.WaitForPodRunningInNamespace(c, pod.Name, ns)
|
2015-04-10 20:00:07 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
// Try to make sure we get a hostIP for each pod.
|
2015-05-19 18:17:32 +00:00
|
|
|
hostIPTimeout := 2 * time.Minute
|
|
|
|
t := time.Now()
|
|
|
|
for {
|
|
|
|
p, err := podClient.Get(pod.Name)
|
2015-04-10 20:00:07 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2015-05-19 18:17:32 +00:00
|
|
|
if p.Status.HostIP != "" {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Logf("Pod %s has hostIP: %s", p.Name, p.Status.HostIP)
|
2015-05-19 18:17:32 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
if time.Since(t) >= hostIPTimeout {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Failf("Gave up waiting for hostIP of pod %s after %v seconds",
|
2015-05-19 18:17:32 +00:00
|
|
|
p.Name, time.Since(t).Seconds())
|
2015-04-10 20:00:07 +00:00
|
|
|
}
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Logf("Retrying to get the hostIP of pod %s", p.Name)
|
2015-05-19 18:17:32 +00:00
|
|
|
time.Sleep(5 * time.Second)
|
|
|
|
}
|
2015-04-10 20:00:07 +00:00
|
|
|
}
|
|
|
|
|
2016-04-07 17:21:31 +00:00
|
|
|
func runPodFromStruct(f *framework.Framework, pod *api.Pod) {
|
2015-10-15 04:58:20 +00:00
|
|
|
By("submitting the pod to kubernetes")
|
|
|
|
|
2016-04-07 17:21:31 +00:00
|
|
|
podClient := f.Client.Pods(f.Namespace.Name)
|
2015-10-15 04:58:20 +00:00
|
|
|
pod, err := podClient.Create(pod)
|
|
|
|
if err != nil {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Failf("Failed to create pod: %v", err)
|
2015-10-15 04:58:20 +00:00
|
|
|
}
|
|
|
|
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.ExpectNoError(f.WaitForPodRunning(pod.Name))
|
2015-10-15 04:58:20 +00:00
|
|
|
|
|
|
|
By("verifying the pod is in kubernetes")
|
|
|
|
pod, err = podClient.Get(pod.Name)
|
|
|
|
if err != nil {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Failf("failed to get pod: %v", err)
|
2015-10-15 04:58:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-07 17:21:31 +00:00
|
|
|
func startPodAndGetBackOffs(f *framework.Framework, pod *api.Pod, podName string, containerName string, sleepAmount time.Duration) (time.Duration, time.Duration) {
|
|
|
|
runPodFromStruct(f, pod)
|
2015-10-15 04:58:20 +00:00
|
|
|
time.Sleep(sleepAmount)
|
|
|
|
|
|
|
|
By("getting restart delay-0")
|
2016-04-07 17:21:31 +00:00
|
|
|
_, err := getRestartDelay(f.Client, pod, f.Namespace.Name, podName, containerName)
|
2015-10-15 04:58:20 +00:00
|
|
|
if err != nil {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Failf("timed out waiting for container restart in pod=%s/%s", podName, containerName)
|
2015-10-15 04:58:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
By("getting restart delay-1")
|
2016-04-07 17:21:31 +00:00
|
|
|
delay1, err := getRestartDelay(f.Client, pod, f.Namespace.Name, podName, containerName)
|
2015-10-15 04:58:20 +00:00
|
|
|
if err != nil {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Failf("timed out waiting for container restart in pod=%s/%s", podName, containerName)
|
2015-10-15 04:58:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
By("getting restart delay-2")
|
2016-04-07 17:21:31 +00:00
|
|
|
delay2, err := getRestartDelay(f.Client, pod, f.Namespace.Name, podName, containerName)
|
2015-10-15 04:58:20 +00:00
|
|
|
if err != nil {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Failf("timed out waiting for container restart in pod=%s/%s", podName, containerName)
|
2015-10-15 04:58:20 +00:00
|
|
|
}
|
|
|
|
return delay1, delay2
|
|
|
|
}
|
|
|
|
|
|
|
|
func getRestartDelay(c *client.Client, pod *api.Pod, ns string, name string, containerName string) (time.Duration, error) {
|
|
|
|
beginTime := time.Now()
|
|
|
|
for time.Since(beginTime) < (2 * maxBackOffTolerance) { // may just miss the 1st MaxContainerBackOff delay
|
|
|
|
time.Sleep(time.Second)
|
|
|
|
pod, err := c.Pods(ns).Get(name)
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.ExpectNoError(err, fmt.Sprintf("getting pod %s", name))
|
2015-10-15 04:58:20 +00:00
|
|
|
status, ok := api.GetContainerStatus(pod.Status.ContainerStatuses, containerName)
|
|
|
|
if !ok {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Logf("getRestartDelay: status missing")
|
2015-10-15 04:58:20 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if status.State.Waiting == nil && status.State.Running != nil && status.LastTerminationState.Terminated != nil && status.State.Running.StartedAt.Time.After(beginTime) {
|
|
|
|
startedAt := status.State.Running.StartedAt.Time
|
|
|
|
finishedAt := status.LastTerminationState.Terminated.FinishedAt.Time
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Logf("getRestartDelay: restartCount = %d, finishedAt=%s restartedAt=%s (%s)", status.RestartCount, finishedAt, startedAt, startedAt.Sub(finishedAt))
|
2015-10-15 04:58:20 +00:00
|
|
|
return startedAt.Sub(finishedAt), nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0, fmt.Errorf("timeout getting pod restart delay")
|
|
|
|
}
|
|
|
|
|
2016-04-07 17:21:31 +00:00
|
|
|
var _ = framework.KubeDescribe("Pods", func() {
|
|
|
|
f := framework.NewDefaultFramework("pods")
|
2015-01-30 20:59:13 +00:00
|
|
|
|
2016-02-02 19:37:59 +00:00
|
|
|
It("should get a host IP [Conformance]", func() {
|
2015-04-10 20:00:07 +00:00
|
|
|
name := "pod-hostip-" + string(util.NewUUID())
|
2016-04-07 17:21:31 +00:00
|
|
|
testHostIP(f.Client, f.Namespace.Name, &api.Pod{
|
2015-04-10 20:00:07 +00:00
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Name: name,
|
|
|
|
},
|
|
|
|
Spec: api.PodSpec{
|
|
|
|
Containers: []api.Container{
|
|
|
|
{
|
|
|
|
Name: "test",
|
2015-11-04 23:52:49 +00:00
|
|
|
Image: "gcr.io/google_containers/pause:2.0",
|
2015-04-10 20:00:07 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
2015-07-09 11:56:19 +00:00
|
|
|
|
2015-10-07 14:09:24 +00:00
|
|
|
It("should be schedule with cpu and memory limits [Conformance]", func() {
|
2016-04-07 17:21:31 +00:00
|
|
|
podClient := f.Client.Pods(f.Namespace.Name)
|
2015-06-09 21:19:21 +00:00
|
|
|
|
|
|
|
By("creating the pod")
|
|
|
|
name := "pod-update-" + string(util.NewUUID())
|
|
|
|
value := strconv.Itoa(time.Now().Nanosecond())
|
|
|
|
pod := &api.Pod{
|
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Name: name,
|
|
|
|
Labels: map[string]string{
|
|
|
|
"name": "foo",
|
|
|
|
"time": value,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Spec: api.PodSpec{
|
|
|
|
Containers: []api.Container{
|
|
|
|
{
|
|
|
|
Name: "nginx",
|
2015-11-04 23:52:49 +00:00
|
|
|
Image: "gcr.io/google_containers/pause:2.0",
|
2015-06-09 21:19:21 +00:00
|
|
|
Resources: api.ResourceRequirements{
|
|
|
|
Limits: api.ResourceList{
|
|
|
|
api.ResourceCPU: *resource.NewMilliQuantity(100, resource.DecimalSI),
|
|
|
|
api.ResourceMemory: *resource.NewQuantity(10*1024*1024, resource.DecimalSI),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
defer podClient.Delete(pod.Name, nil)
|
|
|
|
_, err := podClient.Create(pod)
|
|
|
|
if err != nil {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Failf("Error creating a pod: %v", err)
|
2015-06-09 21:19:21 +00:00
|
|
|
}
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.ExpectNoError(f.WaitForPodRunning(pod.Name))
|
2015-06-09 21:19:21 +00:00
|
|
|
})
|
2015-07-09 11:56:19 +00:00
|
|
|
|
2015-10-07 14:09:24 +00:00
|
|
|
It("should be submitted and removed [Conformance]", func() {
|
2016-04-07 17:21:31 +00:00
|
|
|
podClient := f.Client.Pods(f.Namespace.Name)
|
2015-01-30 21:00:03 +00:00
|
|
|
|
2015-02-03 20:29:23 +00:00
|
|
|
By("creating the pod")
|
|
|
|
name := "pod-update-" + string(util.NewUUID())
|
2015-01-30 21:00:03 +00:00
|
|
|
value := strconv.Itoa(time.Now().Nanosecond())
|
2015-02-03 20:29:23 +00:00
|
|
|
pod := &api.Pod{
|
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Name: name,
|
|
|
|
Labels: map[string]string{
|
|
|
|
"name": "foo",
|
|
|
|
"time": value,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Spec: api.PodSpec{
|
|
|
|
Containers: []api.Container{
|
|
|
|
{
|
|
|
|
Name: "nginx",
|
2015-04-02 17:15:20 +00:00
|
|
|
Image: "gcr.io/google_containers/nginx:1.7.9",
|
2015-02-23 22:25:56 +00:00
|
|
|
Ports: []api.ContainerPort{{ContainerPort: 80}},
|
2015-02-03 20:29:23 +00:00
|
|
|
LivenessProbe: &api.Probe{
|
|
|
|
Handler: api.Handler{
|
|
|
|
HTTPGet: &api.HTTPGetAction{
|
|
|
|
Path: "/index.html",
|
2015-11-10 06:28:45 +00:00
|
|
|
Port: intstr.FromInt(8080),
|
2015-02-03 20:29:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
InitialDelaySeconds: 30,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2015-01-30 21:00:03 +00:00
|
|
|
|
2015-03-10 08:41:42 +00:00
|
|
|
By("setting up watch")
|
2015-12-02 11:12:57 +00:00
|
|
|
selector := labels.SelectorFromSet(labels.Set(map[string]string{"time": value}))
|
2015-12-10 09:39:03 +00:00
|
|
|
options := api.ListOptions{LabelSelector: selector}
|
2015-12-02 11:12:57 +00:00
|
|
|
pods, err := podClient.List(options)
|
2015-03-10 08:41:42 +00:00
|
|
|
if err != nil {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Failf("Failed to query for pods: %v", err)
|
2015-03-10 08:41:42 +00:00
|
|
|
}
|
|
|
|
Expect(len(pods.Items)).To(Equal(0))
|
2015-12-10 09:39:03 +00:00
|
|
|
options = api.ListOptions{
|
|
|
|
LabelSelector: selector,
|
2015-11-26 15:27:45 +00:00
|
|
|
ResourceVersion: pods.ListMeta.ResourceVersion,
|
|
|
|
}
|
|
|
|
w, err := podClient.Watch(options)
|
2015-03-10 08:41:42 +00:00
|
|
|
if err != nil {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Failf("Failed to set up watch: %v", err)
|
2015-03-10 08:41:42 +00:00
|
|
|
}
|
|
|
|
|
2015-01-30 21:00:03 +00:00
|
|
|
By("submitting the pod to kubernetes")
|
2015-02-19 23:24:38 +00:00
|
|
|
// We call defer here in case there is a problem with
|
|
|
|
// the test so we can ensure that we clean up after
|
|
|
|
// ourselves
|
2015-08-20 02:09:57 +00:00
|
|
|
defer podClient.Delete(pod.Name, api.NewDeleteOptions(0))
|
2015-03-10 08:41:42 +00:00
|
|
|
_, err = podClient.Create(pod)
|
2015-01-30 21:00:03 +00:00
|
|
|
if err != nil {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Failf("Failed to create pod: %v", err)
|
2015-01-30 21:00:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
By("verifying the pod is in kubernetes")
|
2015-12-02 11:12:57 +00:00
|
|
|
selector = labels.SelectorFromSet(labels.Set(map[string]string{"time": value}))
|
2015-12-10 09:39:03 +00:00
|
|
|
options = api.ListOptions{LabelSelector: selector}
|
2015-12-02 11:12:57 +00:00
|
|
|
pods, err = podClient.List(options)
|
2015-01-30 21:00:03 +00:00
|
|
|
if err != nil {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Failf("Failed to query for pods: %v", err)
|
2015-01-30 21:00:03 +00:00
|
|
|
}
|
|
|
|
Expect(len(pods.Items)).To(Equal(1))
|
|
|
|
|
2015-08-20 02:09:57 +00:00
|
|
|
By("verifying pod creation was observed")
|
2015-03-10 08:41:42 +00:00
|
|
|
select {
|
|
|
|
case event, _ := <-w.ResultChan():
|
|
|
|
if event.Type != watch.Added {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Failf("Failed to observe pod creation: %v", event)
|
2015-03-10 08:41:42 +00:00
|
|
|
}
|
2016-04-07 17:21:31 +00:00
|
|
|
case <-time.After(framework.PodStartTimeout):
|
2015-03-10 08:41:42 +00:00
|
|
|
Fail("Timeout while waiting for pod creation")
|
|
|
|
}
|
|
|
|
|
2016-01-27 07:08:50 +00:00
|
|
|
// We need to wait for the pod to be scheduled, otherwise the deletion
|
|
|
|
// will be carried out immediately rather than gracefully.
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.ExpectNoError(f.WaitForPodRunning(pod.Name))
|
2016-01-27 07:08:50 +00:00
|
|
|
|
2015-08-20 02:18:59 +00:00
|
|
|
By("deleting the pod gracefully")
|
2016-01-27 07:08:50 +00:00
|
|
|
if err := podClient.Delete(pod.Name, api.NewDeleteOptions(30)); err != nil {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Failf("Failed to delete pod: %v", err)
|
2015-03-10 08:41:42 +00:00
|
|
|
}
|
|
|
|
|
2016-03-09 23:01:55 +00:00
|
|
|
By("verifying the kubelet observed the termination notice")
|
|
|
|
pod, err = podClient.Get(pod.Name)
|
|
|
|
Expect(wait.Poll(time.Second*5, time.Second*30, func() (bool, error) {
|
2016-04-07 17:21:31 +00:00
|
|
|
podList, err := framework.GetKubeletPods(f.Client, pod.Spec.NodeName)
|
2016-03-09 23:01:55 +00:00
|
|
|
if err != nil {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Logf("Unable to retrieve kubelet pods for node %v: %v", pod.Spec.NodeName, err)
|
2016-03-09 23:01:55 +00:00
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
for _, kubeletPod := range podList.Items {
|
|
|
|
if pod.Name != kubeletPod.Name {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if kubeletPod.ObjectMeta.DeletionTimestamp == nil {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Logf("deletion has not yet been observed")
|
2016-03-09 23:01:55 +00:00
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
return true, nil
|
|
|
|
}
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Logf("no pod exists with the name we were looking for, assuming the termination request was observed and completed")
|
2016-03-09 23:01:55 +00:00
|
|
|
return true, nil
|
|
|
|
})).NotTo(HaveOccurred(), "kubelet never observed the termination notice")
|
|
|
|
|
2015-08-07 16:40:59 +00:00
|
|
|
By("verifying pod deletion was observed")
|
2015-03-10 08:41:42 +00:00
|
|
|
deleted := false
|
|
|
|
timeout := false
|
2015-08-20 02:18:59 +00:00
|
|
|
var lastPod *api.Pod
|
2016-01-27 07:08:50 +00:00
|
|
|
timer := time.After(30 * time.Second)
|
2015-03-10 08:41:42 +00:00
|
|
|
for !deleted && !timeout {
|
|
|
|
select {
|
|
|
|
case event, _ := <-w.ResultChan():
|
|
|
|
if event.Type == watch.Deleted {
|
2015-08-20 02:18:59 +00:00
|
|
|
lastPod = event.Object.(*api.Pod)
|
2015-03-10 08:41:42 +00:00
|
|
|
deleted = true
|
|
|
|
}
|
|
|
|
case <-timer:
|
|
|
|
timeout = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !deleted {
|
|
|
|
Fail("Failed to observe pod deletion")
|
|
|
|
}
|
2015-08-07 16:40:59 +00:00
|
|
|
|
2015-08-20 02:18:59 +00:00
|
|
|
Expect(lastPod.DeletionTimestamp).ToNot(BeNil())
|
|
|
|
Expect(lastPod.Spec.TerminationGracePeriodSeconds).ToNot(BeZero())
|
|
|
|
|
2015-12-02 11:12:57 +00:00
|
|
|
selector = labels.SelectorFromSet(labels.Set(map[string]string{"time": value}))
|
2015-12-10 09:39:03 +00:00
|
|
|
options = api.ListOptions{LabelSelector: selector}
|
2015-12-02 11:12:57 +00:00
|
|
|
pods, err = podClient.List(options)
|
2015-08-07 16:40:59 +00:00
|
|
|
if err != nil {
|
|
|
|
Fail(fmt.Sprintf("Failed to list pods to verify deletion: %v", err))
|
|
|
|
}
|
|
|
|
Expect(len(pods.Items)).To(Equal(0))
|
2015-01-30 21:00:03 +00:00
|
|
|
})
|
|
|
|
|
2015-10-07 14:09:24 +00:00
|
|
|
It("should be updated [Conformance]", func() {
|
2016-04-07 17:21:31 +00:00
|
|
|
podClient := f.Client.Pods(f.Namespace.Name)
|
2015-01-30 20:59:13 +00:00
|
|
|
|
|
|
|
By("creating the pod")
|
|
|
|
name := "pod-update-" + string(util.NewUUID())
|
|
|
|
value := strconv.Itoa(time.Now().Nanosecond())
|
|
|
|
pod := &api.Pod{
|
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Name: name,
|
|
|
|
Labels: map[string]string{
|
|
|
|
"name": "foo",
|
|
|
|
"time": value,
|
|
|
|
},
|
2015-01-30 23:25:56 +00:00
|
|
|
},
|
2015-01-30 20:59:13 +00:00
|
|
|
Spec: api.PodSpec{
|
|
|
|
Containers: []api.Container{
|
|
|
|
{
|
|
|
|
Name: "nginx",
|
2015-04-02 17:15:20 +00:00
|
|
|
Image: "gcr.io/google_containers/nginx:1.7.9",
|
2015-02-23 22:25:56 +00:00
|
|
|
Ports: []api.ContainerPort{{ContainerPort: 80}},
|
2015-01-30 20:59:13 +00:00
|
|
|
LivenessProbe: &api.Probe{
|
|
|
|
Handler: api.Handler{
|
|
|
|
HTTPGet: &api.HTTPGetAction{
|
|
|
|
Path: "/index.html",
|
2015-11-10 06:28:45 +00:00
|
|
|
Port: intstr.FromInt(8080),
|
2015-01-30 20:59:13 +00:00
|
|
|
},
|
2015-01-30 23:25:56 +00:00
|
|
|
},
|
2015-01-30 20:59:13 +00:00
|
|
|
InitialDelaySeconds: 30,
|
2015-01-30 23:25:56 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2015-01-30 20:59:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
By("submitting the pod to kubernetes")
|
|
|
|
defer func() {
|
|
|
|
By("deleting the pod")
|
2015-08-20 02:09:57 +00:00
|
|
|
podClient.Delete(pod.Name, api.NewDeleteOptions(0))
|
2015-01-30 20:59:13 +00:00
|
|
|
}()
|
2015-04-21 00:42:17 +00:00
|
|
|
pod, err := podClient.Create(pod)
|
2015-02-19 23:24:38 +00:00
|
|
|
if err != nil {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Failf("Failed to create pod: %v", err)
|
2015-02-19 23:24:38 +00:00
|
|
|
}
|
2015-01-30 20:59:13 +00:00
|
|
|
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.ExpectNoError(f.WaitForPodRunning(pod.Name))
|
2015-01-30 20:59:13 +00:00
|
|
|
|
|
|
|
By("verifying the pod is in kubernetes")
|
2015-12-02 11:12:57 +00:00
|
|
|
selector := labels.SelectorFromSet(labels.Set(map[string]string{"time": value}))
|
2015-12-10 09:39:03 +00:00
|
|
|
options := api.ListOptions{LabelSelector: selector}
|
2015-12-02 11:12:57 +00:00
|
|
|
pods, err := podClient.List(options)
|
2015-01-30 20:59:13 +00:00
|
|
|
Expect(len(pods.Items)).To(Equal(1))
|
|
|
|
|
2015-04-21 00:42:17 +00:00
|
|
|
// Standard get, update retry loop
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.ExpectNoError(wait.Poll(time.Millisecond*500, time.Second*30, func() (bool, error) {
|
2015-04-21 00:42:17 +00:00
|
|
|
By("updating the pod")
|
|
|
|
value = strconv.Itoa(time.Now().Nanosecond())
|
|
|
|
if pod == nil { // on retries we need to re-get
|
|
|
|
pod, err = podClient.Get(name)
|
|
|
|
if err != nil {
|
|
|
|
return false, fmt.Errorf("failed to get pod: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pod.Labels["time"] = value
|
|
|
|
pod, err = podClient.Update(pod)
|
|
|
|
if err == nil {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Logf("Successfully updated pod")
|
2015-04-21 00:42:17 +00:00
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
if errors.IsConflict(err) {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Logf("Conflicting update to pod, re-get and re-update: %v", err)
|
2015-04-21 00:42:17 +00:00
|
|
|
pod = nil // re-get it when we retry
|
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
return false, fmt.Errorf("failed to update pod: %v", err)
|
|
|
|
}))
|
2015-01-30 20:59:13 +00:00
|
|
|
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.ExpectNoError(f.WaitForPodRunning(pod.Name))
|
2015-01-30 20:59:13 +00:00
|
|
|
|
|
|
|
By("verifying the updated pod is in kubernetes")
|
2015-12-02 11:12:57 +00:00
|
|
|
selector = labels.SelectorFromSet(labels.Set(map[string]string{"time": value}))
|
2015-12-10 09:39:03 +00:00
|
|
|
options = api.ListOptions{LabelSelector: selector}
|
2015-12-02 11:12:57 +00:00
|
|
|
pods, err = podClient.List(options)
|
2015-01-30 20:59:13 +00:00
|
|
|
Expect(len(pods.Items)).To(Equal(1))
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Logf("Pod update OK")
|
2015-01-28 00:38:48 +00:00
|
|
|
})
|
2015-02-02 14:11:06 +00:00
|
|
|
|
2016-01-26 20:52:14 +00:00
|
|
|
It("should allow activeDeadlineSeconds to be updated [Conformance]", func() {
|
2016-04-07 17:21:31 +00:00
|
|
|
podClient := f.Client.Pods(f.Namespace.Name)
|
2016-01-26 20:52:14 +00:00
|
|
|
|
|
|
|
By("creating the pod")
|
|
|
|
name := "pod-update-activedeadlineseconds-" + string(util.NewUUID())
|
|
|
|
value := strconv.Itoa(time.Now().Nanosecond())
|
|
|
|
pod := &api.Pod{
|
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Name: name,
|
|
|
|
Labels: map[string]string{
|
|
|
|
"name": "foo",
|
|
|
|
"time": value,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Spec: api.PodSpec{
|
|
|
|
Containers: []api.Container{
|
|
|
|
{
|
|
|
|
Name: "nginx",
|
|
|
|
Image: "gcr.io/google_containers/nginx:1.7.9",
|
|
|
|
Ports: []api.ContainerPort{{ContainerPort: 80}},
|
|
|
|
LivenessProbe: &api.Probe{
|
|
|
|
Handler: api.Handler{
|
|
|
|
HTTPGet: &api.HTTPGetAction{
|
|
|
|
Path: "/index.html",
|
|
|
|
Port: intstr.FromInt(8080),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
InitialDelaySeconds: 30,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
By("submitting the pod to kubernetes")
|
|
|
|
defer func() {
|
|
|
|
By("deleting the pod")
|
|
|
|
podClient.Delete(pod.Name, api.NewDeleteOptions(0))
|
|
|
|
}()
|
|
|
|
pod, err := podClient.Create(pod)
|
|
|
|
if err != nil {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Failf("Failed to create pod: %v", err)
|
2016-01-26 20:52:14 +00:00
|
|
|
}
|
|
|
|
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.ExpectNoError(f.WaitForPodRunning(pod.Name))
|
2016-01-26 20:52:14 +00:00
|
|
|
|
|
|
|
By("verifying the pod is in kubernetes")
|
|
|
|
selector := labels.SelectorFromSet(labels.Set(map[string]string{"time": value}))
|
|
|
|
options := api.ListOptions{LabelSelector: selector}
|
|
|
|
pods, err := podClient.List(options)
|
|
|
|
Expect(len(pods.Items)).To(Equal(1))
|
|
|
|
|
|
|
|
// Standard get, update retry loop
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.ExpectNoError(wait.Poll(time.Millisecond*500, time.Second*30, func() (bool, error) {
|
2016-01-26 20:52:14 +00:00
|
|
|
By("updating the pod")
|
|
|
|
value = strconv.Itoa(time.Now().Nanosecond())
|
|
|
|
if pod == nil { // on retries we need to re-get
|
|
|
|
pod, err = podClient.Get(name)
|
|
|
|
if err != nil {
|
|
|
|
return false, fmt.Errorf("failed to get pod: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
newDeadline := int64(5)
|
|
|
|
pod.Spec.ActiveDeadlineSeconds = &newDeadline
|
|
|
|
pod, err = podClient.Update(pod)
|
|
|
|
if err == nil {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Logf("Successfully updated pod")
|
2016-01-26 20:52:14 +00:00
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
if errors.IsConflict(err) {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Logf("Conflicting update to pod, re-get and re-update: %v", err)
|
2016-01-26 20:52:14 +00:00
|
|
|
pod = nil // re-get it when we retry
|
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
return false, fmt.Errorf("failed to update pod: %v", err)
|
|
|
|
}))
|
|
|
|
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.ExpectNoError(f.WaitForPodTerminated(pod.Name, "DeadlineExceeded"))
|
2016-01-26 20:52:14 +00:00
|
|
|
})
|
|
|
|
|
2015-10-07 14:09:24 +00:00
|
|
|
It("should contain environment variables for services [Conformance]", func() {
|
2015-02-02 14:11:06 +00:00
|
|
|
// Make a pod that will be a service.
|
|
|
|
// This pod serves its hostname via HTTP.
|
2015-02-03 18:43:14 +00:00
|
|
|
serverName := "server-envvars-" + string(util.NewUUID())
|
|
|
|
serverPod := &api.Pod{
|
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Name: serverName,
|
|
|
|
Labels: map[string]string{"name": serverName},
|
|
|
|
},
|
|
|
|
Spec: api.PodSpec{
|
|
|
|
Containers: []api.Container{
|
|
|
|
{
|
|
|
|
Name: "srv",
|
2016-03-21 19:53:22 +00:00
|
|
|
Image: "gcr.io/google_containers/serve_hostname:v1.4",
|
2015-02-23 22:25:56 +00:00
|
|
|
Ports: []api.ContainerPort{{ContainerPort: 9376}},
|
2015-02-03 18:43:14 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2016-04-07 17:21:31 +00:00
|
|
|
defer f.Client.Pods(f.Namespace.Name).Delete(serverPod.Name, api.NewDeleteOptions(0))
|
|
|
|
_, err := f.Client.Pods(f.Namespace.Name).Create(serverPod)
|
2015-02-02 14:11:06 +00:00
|
|
|
if err != nil {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Failf("Failed to create serverPod: %v", err)
|
2015-02-02 14:11:06 +00:00
|
|
|
}
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.ExpectNoError(f.WaitForPodRunning(serverPod.Name))
|
2015-02-02 14:11:06 +00:00
|
|
|
|
2015-02-03 18:43:14 +00:00
|
|
|
// This service exposes port 8080 of the test pod as a service on port 8765
|
|
|
|
// TODO(filbranden): We would like to use a unique service name such as:
|
|
|
|
// svcName := "svc-envvars-" + randomSuffix()
|
|
|
|
// However, that affects the name of the environment variables which are the capitalized
|
|
|
|
// service name, so that breaks this test. One possibility is to tweak the variable names
|
|
|
|
// to match the service. Another is to rethink environment variable names and possibly
|
|
|
|
// allow overriding the prefix in the service manifest.
|
|
|
|
svcName := "fooservice"
|
|
|
|
svc := &api.Service{
|
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Name: svcName,
|
|
|
|
Labels: map[string]string{
|
|
|
|
"name": svcName,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Spec: api.ServiceSpec{
|
2015-03-13 15:16:41 +00:00
|
|
|
Ports: []api.ServicePort{{
|
|
|
|
Port: 8765,
|
2015-11-10 06:28:45 +00:00
|
|
|
TargetPort: intstr.FromInt(8080),
|
2015-03-13 15:16:41 +00:00
|
|
|
}},
|
2015-02-03 18:43:14 +00:00
|
|
|
Selector: map[string]string{
|
|
|
|
"name": serverName,
|
|
|
|
},
|
|
|
|
},
|
2015-02-02 14:11:06 +00:00
|
|
|
}
|
2016-04-07 17:21:31 +00:00
|
|
|
defer f.Client.Services(f.Namespace.Name).Delete(svc.Name)
|
|
|
|
_, err = f.Client.Services(f.Namespace.Name).Create(svc)
|
2015-02-02 14:11:06 +00:00
|
|
|
if err != nil {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Failf("Failed to create service: %v", err)
|
2015-02-02 14:11:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Make a client pod that verifies that it has the service environment variables.
|
2015-03-31 17:25:14 +00:00
|
|
|
podName := "client-envvars-" + string(util.NewUUID())
|
|
|
|
pod := &api.Pod{
|
2015-02-03 18:43:14 +00:00
|
|
|
ObjectMeta: api.ObjectMeta{
|
2015-03-31 17:25:14 +00:00
|
|
|
Name: podName,
|
|
|
|
Labels: map[string]string{"name": podName},
|
2015-02-03 18:43:14 +00:00
|
|
|
},
|
|
|
|
Spec: api.PodSpec{
|
|
|
|
Containers: []api.Container{
|
|
|
|
{
|
|
|
|
Name: "env3cont",
|
2016-02-08 23:28:55 +00:00
|
|
|
Image: "gcr.io/google_containers/busybox:1.24",
|
2015-03-31 17:25:14 +00:00
|
|
|
Command: []string{"sh", "-c", "env"},
|
2015-02-03 18:43:14 +00:00
|
|
|
},
|
|
|
|
},
|
2015-03-14 01:38:07 +00:00
|
|
|
RestartPolicy: api.RestartPolicyNever,
|
2015-02-03 18:43:14 +00:00
|
|
|
},
|
|
|
|
}
|
2015-02-02 14:11:06 +00:00
|
|
|
|
2016-04-07 17:21:31 +00:00
|
|
|
f.TestContainerOutput("service env", pod, 0, []string{
|
2015-02-02 14:11:06 +00:00
|
|
|
"FOOSERVICE_SERVICE_HOST=",
|
|
|
|
"FOOSERVICE_SERVICE_PORT=",
|
|
|
|
"FOOSERVICE_PORT=",
|
|
|
|
"FOOSERVICE_PORT_8765_TCP_PORT=",
|
|
|
|
"FOOSERVICE_PORT_8765_TCP_PROTO=",
|
|
|
|
"FOOSERVICE_PORT_8765_TCP=",
|
|
|
|
"FOOSERVICE_PORT_8765_TCP_ADDR=",
|
2015-03-31 17:25:14 +00:00
|
|
|
})
|
2015-02-02 14:11:06 +00:00
|
|
|
})
|
2015-02-10 14:03:21 +00:00
|
|
|
|
2015-10-07 14:09:24 +00:00
|
|
|
It("should be restarted with a docker exec \"cat /tmp/health\" liveness probe [Conformance]", func() {
|
2016-04-07 17:21:31 +00:00
|
|
|
runLivenessTest(f.Client, f.Namespace.Name, &api.Pod{
|
2015-02-10 14:03:21 +00:00
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Name: "liveness-exec",
|
|
|
|
Labels: map[string]string{"test": "liveness"},
|
|
|
|
},
|
|
|
|
Spec: api.PodSpec{
|
|
|
|
Containers: []api.Container{
|
|
|
|
{
|
|
|
|
Name: "liveness",
|
2016-02-08 23:28:55 +00:00
|
|
|
Image: "gcr.io/google_containers/busybox:1.24",
|
2015-05-08 16:48:31 +00:00
|
|
|
Command: []string{"/bin/sh", "-c", "echo ok >/tmp/health; sleep 10; rm -rf /tmp/health; sleep 600"},
|
2015-02-10 14:03:21 +00:00
|
|
|
LivenessProbe: &api.Probe{
|
|
|
|
Handler: api.Handler{
|
|
|
|
Exec: &api.ExecAction{
|
|
|
|
Command: []string{"cat", "/tmp/health"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
InitialDelaySeconds: 15,
|
2015-11-05 23:38:46 +00:00
|
|
|
FailureThreshold: 1,
|
2015-02-10 14:03:21 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2015-09-30 00:00:19 +00:00
|
|
|
}, 1, defaultObservationTimeout)
|
2015-05-04 23:19:36 +00:00
|
|
|
})
|
|
|
|
|
2015-10-07 14:09:24 +00:00
|
|
|
It("should *not* be restarted with a docker exec \"cat /tmp/health\" liveness probe [Conformance]", func() {
|
2016-04-07 17:21:31 +00:00
|
|
|
runLivenessTest(f.Client, f.Namespace.Name, &api.Pod{
|
2015-05-04 23:19:36 +00:00
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Name: "liveness-exec",
|
|
|
|
Labels: map[string]string{"test": "liveness"},
|
|
|
|
},
|
|
|
|
Spec: api.PodSpec{
|
|
|
|
Containers: []api.Container{
|
|
|
|
{
|
|
|
|
Name: "liveness",
|
2016-02-08 23:28:55 +00:00
|
|
|
Image: "gcr.io/google_containers/busybox:1.24",
|
2015-05-04 23:19:36 +00:00
|
|
|
Command: []string{"/bin/sh", "-c", "echo ok >/tmp/health; sleep 600"},
|
|
|
|
LivenessProbe: &api.Probe{
|
|
|
|
Handler: api.Handler{
|
|
|
|
Exec: &api.ExecAction{
|
|
|
|
Command: []string{"cat", "/tmp/health"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
InitialDelaySeconds: 15,
|
2015-11-05 23:38:46 +00:00
|
|
|
FailureThreshold: 1,
|
2015-05-04 23:19:36 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2015-09-30 00:00:19 +00:00
|
|
|
}, 0, defaultObservationTimeout)
|
2015-02-10 14:03:21 +00:00
|
|
|
})
|
|
|
|
|
2015-10-07 14:09:24 +00:00
|
|
|
It("should be restarted with a /healthz http liveness probe [Conformance]", func() {
|
2016-04-07 17:21:31 +00:00
|
|
|
runLivenessTest(f.Client, f.Namespace.Name, &api.Pod{
|
2015-02-10 14:03:21 +00:00
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Name: "liveness-http",
|
|
|
|
Labels: map[string]string{"test": "liveness"},
|
|
|
|
},
|
|
|
|
Spec: api.PodSpec{
|
|
|
|
Containers: []api.Container{
|
|
|
|
{
|
|
|
|
Name: "liveness",
|
2016-02-20 04:22:49 +00:00
|
|
|
Image: "gcr.io/google_containers/liveness:e2e",
|
2015-02-10 14:03:21 +00:00
|
|
|
Command: []string{"/server"},
|
|
|
|
LivenessProbe: &api.Probe{
|
|
|
|
Handler: api.Handler{
|
|
|
|
HTTPGet: &api.HTTPGetAction{
|
|
|
|
Path: "/healthz",
|
2015-11-10 06:28:45 +00:00
|
|
|
Port: intstr.FromInt(8080),
|
2015-02-10 14:03:21 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
InitialDelaySeconds: 15,
|
2015-11-05 23:38:46 +00:00
|
|
|
FailureThreshold: 1,
|
2015-02-10 14:03:21 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2015-09-30 00:00:19 +00:00
|
|
|
}, 1, defaultObservationTimeout)
|
2015-08-21 23:46:17 +00:00
|
|
|
})
|
|
|
|
|
2015-12-20 19:00:00 +00:00
|
|
|
// Slow by design (5 min)
|
|
|
|
It("should have monotonically increasing restart count [Conformance] [Slow]", func() {
|
2016-04-07 17:21:31 +00:00
|
|
|
runLivenessTest(f.Client, f.Namespace.Name, &api.Pod{
|
2015-08-21 23:46:17 +00:00
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Name: "liveness-http",
|
|
|
|
Labels: map[string]string{"test": "liveness"},
|
|
|
|
},
|
|
|
|
Spec: api.PodSpec{
|
|
|
|
Containers: []api.Container{
|
|
|
|
{
|
|
|
|
Name: "liveness",
|
2016-02-20 04:22:49 +00:00
|
|
|
Image: "gcr.io/google_containers/liveness:e2e",
|
2015-08-21 23:46:17 +00:00
|
|
|
Command: []string{"/server"},
|
|
|
|
LivenessProbe: &api.Probe{
|
|
|
|
Handler: api.Handler{
|
|
|
|
HTTPGet: &api.HTTPGetAction{
|
|
|
|
Path: "/healthz",
|
2015-11-10 06:28:45 +00:00
|
|
|
Port: intstr.FromInt(8080),
|
2015-08-21 23:46:17 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
InitialDelaySeconds: 5,
|
2015-11-05 23:38:46 +00:00
|
|
|
FailureThreshold: 1,
|
2015-08-21 23:46:17 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2015-09-30 00:00:19 +00:00
|
|
|
}, 5, time.Minute*5)
|
2015-02-10 14:03:21 +00:00
|
|
|
})
|
2015-01-08 20:41:38 +00:00
|
|
|
|
2015-10-07 14:09:24 +00:00
|
|
|
It("should *not* be restarted with a /healthz http liveness probe [Conformance]", func() {
|
2016-04-07 17:21:31 +00:00
|
|
|
runLivenessTest(f.Client, f.Namespace.Name, &api.Pod{
|
2015-08-07 03:59:37 +00:00
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Name: "liveness-http",
|
|
|
|
Labels: map[string]string{"test": "liveness"},
|
|
|
|
},
|
|
|
|
Spec: api.PodSpec{
|
|
|
|
Containers: []api.Container{
|
|
|
|
{
|
|
|
|
Name: "liveness",
|
2016-02-11 23:37:32 +00:00
|
|
|
Image: "gcr.io/google_containers/nettest:1.7",
|
2015-08-07 03:59:37 +00:00
|
|
|
// These args are garbage but the image will exit if they're not there
|
|
|
|
// we just care about /read serving a 200, which it always does.
|
|
|
|
Args: []string{
|
|
|
|
"-service=liveness-http",
|
|
|
|
"-peers=1",
|
2016-04-07 17:21:31 +00:00
|
|
|
"-namespace=" + f.Namespace.Name},
|
2015-08-07 03:59:37 +00:00
|
|
|
Ports: []api.ContainerPort{{ContainerPort: 8080}},
|
|
|
|
LivenessProbe: &api.Probe{
|
|
|
|
Handler: api.Handler{
|
|
|
|
HTTPGet: &api.HTTPGetAction{
|
|
|
|
Path: "/read",
|
2015-11-10 06:28:45 +00:00
|
|
|
Port: intstr.FromInt(8080),
|
2015-08-07 03:59:37 +00:00
|
|
|
},
|
|
|
|
},
|
2016-02-05 18:49:22 +00:00
|
|
|
InitialDelaySeconds: 15,
|
|
|
|
TimeoutSeconds: 10,
|
2015-11-05 23:38:46 +00:00
|
|
|
FailureThreshold: 1,
|
2015-08-07 03:59:37 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2015-09-30 00:00:19 +00:00
|
|
|
}, 0, defaultObservationTimeout)
|
2015-08-07 03:59:37 +00:00
|
|
|
})
|
|
|
|
|
Expose exec and logs via WebSockets
Not all clients and systems can support SPDY protocols. This commit adds
support for two new websocket protocols, one to handle streaming of pod
logs from a pod, and the other to allow exec to be tunneled over
websocket.
Browser support for chunked encoding is still poor, and web consoles
that wish to show pod logs may need to make compromises to display the
output. The /pods/<name>/log endpoint now supports websocket upgrade to
the 'binary.k8s.io' subprotocol, which sends chunks of logs as binary to
the client. Messages are written as logs are streamed from the container
daemon, so flushing should be unaffected.
Browser support for raw communication over SDPY is not possible, and
some languages lack libraries for it and HTTP/2. The Kubelet supports
upgrade to WebSocket instead of SPDY, and will multiplex STDOUT/IN/ERR
over websockets by prepending each binary message with a single byte
representing the channel (0 for IN, 1 for OUT, and 2 for ERR). Because
framing on WebSockets suffers from head-of-line blocking, clients and
other server code should ensure that no particular stream blocks. An
alternative subprotocol 'base64.channel.k8s.io' base64 encodes the body
and uses '0'-'9' to represent the channel for ease of use in browsers.
2015-09-11 20:09:51 +00:00
|
|
|
It("should support remote command execution over websockets", func() {
|
2016-04-07 17:21:31 +00:00
|
|
|
config, err := framework.LoadConfig()
|
Expose exec and logs via WebSockets
Not all clients and systems can support SPDY protocols. This commit adds
support for two new websocket protocols, one to handle streaming of pod
logs from a pod, and the other to allow exec to be tunneled over
websocket.
Browser support for chunked encoding is still poor, and web consoles
that wish to show pod logs may need to make compromises to display the
output. The /pods/<name>/log endpoint now supports websocket upgrade to
the 'binary.k8s.io' subprotocol, which sends chunks of logs as binary to
the client. Messages are written as logs are streamed from the container
daemon, so flushing should be unaffected.
Browser support for raw communication over SDPY is not possible, and
some languages lack libraries for it and HTTP/2. The Kubelet supports
upgrade to WebSocket instead of SPDY, and will multiplex STDOUT/IN/ERR
over websockets by prepending each binary message with a single byte
representing the channel (0 for IN, 1 for OUT, and 2 for ERR). Because
framing on WebSockets suffers from head-of-line blocking, clients and
other server code should ensure that no particular stream blocks. An
alternative subprotocol 'base64.channel.k8s.io' base64 encodes the body
and uses '0'-'9' to represent the channel for ease of use in browsers.
2015-09-11 20:09:51 +00:00
|
|
|
if err != nil {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Failf("Unable to get base config: %v", err)
|
Expose exec and logs via WebSockets
Not all clients and systems can support SPDY protocols. This commit adds
support for two new websocket protocols, one to handle streaming of pod
logs from a pod, and the other to allow exec to be tunneled over
websocket.
Browser support for chunked encoding is still poor, and web consoles
that wish to show pod logs may need to make compromises to display the
output. The /pods/<name>/log endpoint now supports websocket upgrade to
the 'binary.k8s.io' subprotocol, which sends chunks of logs as binary to
the client. Messages are written as logs are streamed from the container
daemon, so flushing should be unaffected.
Browser support for raw communication over SDPY is not possible, and
some languages lack libraries for it and HTTP/2. The Kubelet supports
upgrade to WebSocket instead of SPDY, and will multiplex STDOUT/IN/ERR
over websockets by prepending each binary message with a single byte
representing the channel (0 for IN, 1 for OUT, and 2 for ERR). Because
framing on WebSockets suffers from head-of-line blocking, clients and
other server code should ensure that no particular stream blocks. An
alternative subprotocol 'base64.channel.k8s.io' base64 encodes the body
and uses '0'-'9' to represent the channel for ease of use in browsers.
2015-09-11 20:09:51 +00:00
|
|
|
}
|
2016-04-07 17:21:31 +00:00
|
|
|
podClient := f.Client.Pods(f.Namespace.Name)
|
Expose exec and logs via WebSockets
Not all clients and systems can support SPDY protocols. This commit adds
support for two new websocket protocols, one to handle streaming of pod
logs from a pod, and the other to allow exec to be tunneled over
websocket.
Browser support for chunked encoding is still poor, and web consoles
that wish to show pod logs may need to make compromises to display the
output. The /pods/<name>/log endpoint now supports websocket upgrade to
the 'binary.k8s.io' subprotocol, which sends chunks of logs as binary to
the client. Messages are written as logs are streamed from the container
daemon, so flushing should be unaffected.
Browser support for raw communication over SDPY is not possible, and
some languages lack libraries for it and HTTP/2. The Kubelet supports
upgrade to WebSocket instead of SPDY, and will multiplex STDOUT/IN/ERR
over websockets by prepending each binary message with a single byte
representing the channel (0 for IN, 1 for OUT, and 2 for ERR). Because
framing on WebSockets suffers from head-of-line blocking, clients and
other server code should ensure that no particular stream blocks. An
alternative subprotocol 'base64.channel.k8s.io' base64 encodes the body
and uses '0'-'9' to represent the channel for ease of use in browsers.
2015-09-11 20:09:51 +00:00
|
|
|
|
|
|
|
By("creating the pod")
|
|
|
|
name := "pod-exec-websocket-" + string(util.NewUUID())
|
|
|
|
pod := &api.Pod{
|
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Name: name,
|
|
|
|
},
|
|
|
|
Spec: api.PodSpec{
|
|
|
|
Containers: []api.Container{
|
|
|
|
{
|
|
|
|
Name: "main",
|
2016-02-08 23:28:55 +00:00
|
|
|
Image: "gcr.io/google_containers/busybox:1.24",
|
Expose exec and logs via WebSockets
Not all clients and systems can support SPDY protocols. This commit adds
support for two new websocket protocols, one to handle streaming of pod
logs from a pod, and the other to allow exec to be tunneled over
websocket.
Browser support for chunked encoding is still poor, and web consoles
that wish to show pod logs may need to make compromises to display the
output. The /pods/<name>/log endpoint now supports websocket upgrade to
the 'binary.k8s.io' subprotocol, which sends chunks of logs as binary to
the client. Messages are written as logs are streamed from the container
daemon, so flushing should be unaffected.
Browser support for raw communication over SDPY is not possible, and
some languages lack libraries for it and HTTP/2. The Kubelet supports
upgrade to WebSocket instead of SPDY, and will multiplex STDOUT/IN/ERR
over websockets by prepending each binary message with a single byte
representing the channel (0 for IN, 1 for OUT, and 2 for ERR). Because
framing on WebSockets suffers from head-of-line blocking, clients and
other server code should ensure that no particular stream blocks. An
alternative subprotocol 'base64.channel.k8s.io' base64 encodes the body
and uses '0'-'9' to represent the channel for ease of use in browsers.
2015-09-11 20:09:51 +00:00
|
|
|
Command: []string{"/bin/sh", "-c", "echo container is alive; sleep 600"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
By("submitting the pod to kubernetes")
|
|
|
|
defer func() {
|
|
|
|
By("deleting the pod")
|
|
|
|
podClient.Delete(pod.Name, api.NewDeleteOptions(0))
|
|
|
|
}()
|
|
|
|
pod, err = podClient.Create(pod)
|
|
|
|
if err != nil {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Failf("Failed to create pod: %v", err)
|
Expose exec and logs via WebSockets
Not all clients and systems can support SPDY protocols. This commit adds
support for two new websocket protocols, one to handle streaming of pod
logs from a pod, and the other to allow exec to be tunneled over
websocket.
Browser support for chunked encoding is still poor, and web consoles
that wish to show pod logs may need to make compromises to display the
output. The /pods/<name>/log endpoint now supports websocket upgrade to
the 'binary.k8s.io' subprotocol, which sends chunks of logs as binary to
the client. Messages are written as logs are streamed from the container
daemon, so flushing should be unaffected.
Browser support for raw communication over SDPY is not possible, and
some languages lack libraries for it and HTTP/2. The Kubelet supports
upgrade to WebSocket instead of SPDY, and will multiplex STDOUT/IN/ERR
over websockets by prepending each binary message with a single byte
representing the channel (0 for IN, 1 for OUT, and 2 for ERR). Because
framing on WebSockets suffers from head-of-line blocking, clients and
other server code should ensure that no particular stream blocks. An
alternative subprotocol 'base64.channel.k8s.io' base64 encodes the body
and uses '0'-'9' to represent the channel for ease of use in browsers.
2015-09-11 20:09:51 +00:00
|
|
|
}
|
|
|
|
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.ExpectNoError(f.WaitForPodRunning(pod.Name))
|
Expose exec and logs via WebSockets
Not all clients and systems can support SPDY protocols. This commit adds
support for two new websocket protocols, one to handle streaming of pod
logs from a pod, and the other to allow exec to be tunneled over
websocket.
Browser support for chunked encoding is still poor, and web consoles
that wish to show pod logs may need to make compromises to display the
output. The /pods/<name>/log endpoint now supports websocket upgrade to
the 'binary.k8s.io' subprotocol, which sends chunks of logs as binary to
the client. Messages are written as logs are streamed from the container
daemon, so flushing should be unaffected.
Browser support for raw communication over SDPY is not possible, and
some languages lack libraries for it and HTTP/2. The Kubelet supports
upgrade to WebSocket instead of SPDY, and will multiplex STDOUT/IN/ERR
over websockets by prepending each binary message with a single byte
representing the channel (0 for IN, 1 for OUT, and 2 for ERR). Because
framing on WebSockets suffers from head-of-line blocking, clients and
other server code should ensure that no particular stream blocks. An
alternative subprotocol 'base64.channel.k8s.io' base64 encodes the body
and uses '0'-'9' to represent the channel for ease of use in browsers.
2015-09-11 20:09:51 +00:00
|
|
|
|
2016-04-07 17:21:31 +00:00
|
|
|
req := f.Client.Get().
|
|
|
|
Namespace(f.Namespace.Name).
|
Expose exec and logs via WebSockets
Not all clients and systems can support SPDY protocols. This commit adds
support for two new websocket protocols, one to handle streaming of pod
logs from a pod, and the other to allow exec to be tunneled over
websocket.
Browser support for chunked encoding is still poor, and web consoles
that wish to show pod logs may need to make compromises to display the
output. The /pods/<name>/log endpoint now supports websocket upgrade to
the 'binary.k8s.io' subprotocol, which sends chunks of logs as binary to
the client. Messages are written as logs are streamed from the container
daemon, so flushing should be unaffected.
Browser support for raw communication over SDPY is not possible, and
some languages lack libraries for it and HTTP/2. The Kubelet supports
upgrade to WebSocket instead of SPDY, and will multiplex STDOUT/IN/ERR
over websockets by prepending each binary message with a single byte
representing the channel (0 for IN, 1 for OUT, and 2 for ERR). Because
framing on WebSockets suffers from head-of-line blocking, clients and
other server code should ensure that no particular stream blocks. An
alternative subprotocol 'base64.channel.k8s.io' base64 encodes the body
and uses '0'-'9' to represent the channel for ease of use in browsers.
2015-09-11 20:09:51 +00:00
|
|
|
Resource("pods").
|
|
|
|
Name(pod.Name).
|
|
|
|
Suffix("exec").
|
|
|
|
Param("stderr", "1").
|
|
|
|
Param("stdout", "1").
|
|
|
|
Param("container", pod.Spec.Containers[0].Name).
|
|
|
|
Param("command", "cat").
|
|
|
|
Param("command", "/etc/resolv.conf")
|
|
|
|
|
|
|
|
url := req.URL()
|
2016-04-07 17:21:31 +00:00
|
|
|
ws, err := framework.OpenWebSocketForURL(url, config, []string{"channel.k8s.io"})
|
Expose exec and logs via WebSockets
Not all clients and systems can support SPDY protocols. This commit adds
support for two new websocket protocols, one to handle streaming of pod
logs from a pod, and the other to allow exec to be tunneled over
websocket.
Browser support for chunked encoding is still poor, and web consoles
that wish to show pod logs may need to make compromises to display the
output. The /pods/<name>/log endpoint now supports websocket upgrade to
the 'binary.k8s.io' subprotocol, which sends chunks of logs as binary to
the client. Messages are written as logs are streamed from the container
daemon, so flushing should be unaffected.
Browser support for raw communication over SDPY is not possible, and
some languages lack libraries for it and HTTP/2. The Kubelet supports
upgrade to WebSocket instead of SPDY, and will multiplex STDOUT/IN/ERR
over websockets by prepending each binary message with a single byte
representing the channel (0 for IN, 1 for OUT, and 2 for ERR). Because
framing on WebSockets suffers from head-of-line blocking, clients and
other server code should ensure that no particular stream blocks. An
alternative subprotocol 'base64.channel.k8s.io' base64 encodes the body
and uses '0'-'9' to represent the channel for ease of use in browsers.
2015-09-11 20:09:51 +00:00
|
|
|
if err != nil {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Failf("Failed to open websocket to %s: %v", url.String(), err)
|
Expose exec and logs via WebSockets
Not all clients and systems can support SPDY protocols. This commit adds
support for two new websocket protocols, one to handle streaming of pod
logs from a pod, and the other to allow exec to be tunneled over
websocket.
Browser support for chunked encoding is still poor, and web consoles
that wish to show pod logs may need to make compromises to display the
output. The /pods/<name>/log endpoint now supports websocket upgrade to
the 'binary.k8s.io' subprotocol, which sends chunks of logs as binary to
the client. Messages are written as logs are streamed from the container
daemon, so flushing should be unaffected.
Browser support for raw communication over SDPY is not possible, and
some languages lack libraries for it and HTTP/2. The Kubelet supports
upgrade to WebSocket instead of SPDY, and will multiplex STDOUT/IN/ERR
over websockets by prepending each binary message with a single byte
representing the channel (0 for IN, 1 for OUT, and 2 for ERR). Because
framing on WebSockets suffers from head-of-line blocking, clients and
other server code should ensure that no particular stream blocks. An
alternative subprotocol 'base64.channel.k8s.io' base64 encodes the body
and uses '0'-'9' to represent the channel for ease of use in browsers.
2015-09-11 20:09:51 +00:00
|
|
|
}
|
|
|
|
defer ws.Close()
|
|
|
|
|
|
|
|
buf := &bytes.Buffer{}
|
|
|
|
for {
|
|
|
|
var msg []byte
|
|
|
|
if err := websocket.Message.Receive(ws, &msg); err != nil {
|
|
|
|
if err == io.EOF {
|
|
|
|
break
|
|
|
|
}
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Failf("Failed to read completely from websocket %s: %v", url.String(), err)
|
Expose exec and logs via WebSockets
Not all clients and systems can support SPDY protocols. This commit adds
support for two new websocket protocols, one to handle streaming of pod
logs from a pod, and the other to allow exec to be tunneled over
websocket.
Browser support for chunked encoding is still poor, and web consoles
that wish to show pod logs may need to make compromises to display the
output. The /pods/<name>/log endpoint now supports websocket upgrade to
the 'binary.k8s.io' subprotocol, which sends chunks of logs as binary to
the client. Messages are written as logs are streamed from the container
daemon, so flushing should be unaffected.
Browser support for raw communication over SDPY is not possible, and
some languages lack libraries for it and HTTP/2. The Kubelet supports
upgrade to WebSocket instead of SPDY, and will multiplex STDOUT/IN/ERR
over websockets by prepending each binary message with a single byte
representing the channel (0 for IN, 1 for OUT, and 2 for ERR). Because
framing on WebSockets suffers from head-of-line blocking, clients and
other server code should ensure that no particular stream blocks. An
alternative subprotocol 'base64.channel.k8s.io' base64 encodes the body
and uses '0'-'9' to represent the channel for ease of use in browsers.
2015-09-11 20:09:51 +00:00
|
|
|
}
|
|
|
|
if len(msg) == 0 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if msg[0] != 1 {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Failf("Got message from server that didn't start with channel 1 (STDOUT): %v", msg)
|
Expose exec and logs via WebSockets
Not all clients and systems can support SPDY protocols. This commit adds
support for two new websocket protocols, one to handle streaming of pod
logs from a pod, and the other to allow exec to be tunneled over
websocket.
Browser support for chunked encoding is still poor, and web consoles
that wish to show pod logs may need to make compromises to display the
output. The /pods/<name>/log endpoint now supports websocket upgrade to
the 'binary.k8s.io' subprotocol, which sends chunks of logs as binary to
the client. Messages are written as logs are streamed from the container
daemon, so flushing should be unaffected.
Browser support for raw communication over SDPY is not possible, and
some languages lack libraries for it and HTTP/2. The Kubelet supports
upgrade to WebSocket instead of SPDY, and will multiplex STDOUT/IN/ERR
over websockets by prepending each binary message with a single byte
representing the channel (0 for IN, 1 for OUT, and 2 for ERR). Because
framing on WebSockets suffers from head-of-line blocking, clients and
other server code should ensure that no particular stream blocks. An
alternative subprotocol 'base64.channel.k8s.io' base64 encodes the body
and uses '0'-'9' to represent the channel for ease of use in browsers.
2015-09-11 20:09:51 +00:00
|
|
|
}
|
|
|
|
buf.Write(msg[1:])
|
|
|
|
}
|
|
|
|
if buf.Len() == 0 {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Failf("Unexpected output from server")
|
Expose exec and logs via WebSockets
Not all clients and systems can support SPDY protocols. This commit adds
support for two new websocket protocols, one to handle streaming of pod
logs from a pod, and the other to allow exec to be tunneled over
websocket.
Browser support for chunked encoding is still poor, and web consoles
that wish to show pod logs may need to make compromises to display the
output. The /pods/<name>/log endpoint now supports websocket upgrade to
the 'binary.k8s.io' subprotocol, which sends chunks of logs as binary to
the client. Messages are written as logs are streamed from the container
daemon, so flushing should be unaffected.
Browser support for raw communication over SDPY is not possible, and
some languages lack libraries for it and HTTP/2. The Kubelet supports
upgrade to WebSocket instead of SPDY, and will multiplex STDOUT/IN/ERR
over websockets by prepending each binary message with a single byte
representing the channel (0 for IN, 1 for OUT, and 2 for ERR). Because
framing on WebSockets suffers from head-of-line blocking, clients and
other server code should ensure that no particular stream blocks. An
alternative subprotocol 'base64.channel.k8s.io' base64 encodes the body
and uses '0'-'9' to represent the channel for ease of use in browsers.
2015-09-11 20:09:51 +00:00
|
|
|
}
|
|
|
|
if !strings.Contains(buf.String(), "nameserver") {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Failf("Expected to find 'nameserver' in %q", buf.String())
|
Expose exec and logs via WebSockets
Not all clients and systems can support SPDY protocols. This commit adds
support for two new websocket protocols, one to handle streaming of pod
logs from a pod, and the other to allow exec to be tunneled over
websocket.
Browser support for chunked encoding is still poor, and web consoles
that wish to show pod logs may need to make compromises to display the
output. The /pods/<name>/log endpoint now supports websocket upgrade to
the 'binary.k8s.io' subprotocol, which sends chunks of logs as binary to
the client. Messages are written as logs are streamed from the container
daemon, so flushing should be unaffected.
Browser support for raw communication over SDPY is not possible, and
some languages lack libraries for it and HTTP/2. The Kubelet supports
upgrade to WebSocket instead of SPDY, and will multiplex STDOUT/IN/ERR
over websockets by prepending each binary message with a single byte
representing the channel (0 for IN, 1 for OUT, and 2 for ERR). Because
framing on WebSockets suffers from head-of-line blocking, clients and
other server code should ensure that no particular stream blocks. An
alternative subprotocol 'base64.channel.k8s.io' base64 encodes the body
and uses '0'-'9' to represent the channel for ease of use in browsers.
2015-09-11 20:09:51 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should support retrieving logs from the container over websockets", func() {
|
2016-04-07 17:21:31 +00:00
|
|
|
config, err := framework.LoadConfig()
|
Expose exec and logs via WebSockets
Not all clients and systems can support SPDY protocols. This commit adds
support for two new websocket protocols, one to handle streaming of pod
logs from a pod, and the other to allow exec to be tunneled over
websocket.
Browser support for chunked encoding is still poor, and web consoles
that wish to show pod logs may need to make compromises to display the
output. The /pods/<name>/log endpoint now supports websocket upgrade to
the 'binary.k8s.io' subprotocol, which sends chunks of logs as binary to
the client. Messages are written as logs are streamed from the container
daemon, so flushing should be unaffected.
Browser support for raw communication over SDPY is not possible, and
some languages lack libraries for it and HTTP/2. The Kubelet supports
upgrade to WebSocket instead of SPDY, and will multiplex STDOUT/IN/ERR
over websockets by prepending each binary message with a single byte
representing the channel (0 for IN, 1 for OUT, and 2 for ERR). Because
framing on WebSockets suffers from head-of-line blocking, clients and
other server code should ensure that no particular stream blocks. An
alternative subprotocol 'base64.channel.k8s.io' base64 encodes the body
and uses '0'-'9' to represent the channel for ease of use in browsers.
2015-09-11 20:09:51 +00:00
|
|
|
if err != nil {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Failf("Unable to get base config: %v", err)
|
Expose exec and logs via WebSockets
Not all clients and systems can support SPDY protocols. This commit adds
support for two new websocket protocols, one to handle streaming of pod
logs from a pod, and the other to allow exec to be tunneled over
websocket.
Browser support for chunked encoding is still poor, and web consoles
that wish to show pod logs may need to make compromises to display the
output. The /pods/<name>/log endpoint now supports websocket upgrade to
the 'binary.k8s.io' subprotocol, which sends chunks of logs as binary to
the client. Messages are written as logs are streamed from the container
daemon, so flushing should be unaffected.
Browser support for raw communication over SDPY is not possible, and
some languages lack libraries for it and HTTP/2. The Kubelet supports
upgrade to WebSocket instead of SPDY, and will multiplex STDOUT/IN/ERR
over websockets by prepending each binary message with a single byte
representing the channel (0 for IN, 1 for OUT, and 2 for ERR). Because
framing on WebSockets suffers from head-of-line blocking, clients and
other server code should ensure that no particular stream blocks. An
alternative subprotocol 'base64.channel.k8s.io' base64 encodes the body
and uses '0'-'9' to represent the channel for ease of use in browsers.
2015-09-11 20:09:51 +00:00
|
|
|
}
|
2016-04-07 17:21:31 +00:00
|
|
|
podClient := f.Client.Pods(f.Namespace.Name)
|
Expose exec and logs via WebSockets
Not all clients and systems can support SPDY protocols. This commit adds
support for two new websocket protocols, one to handle streaming of pod
logs from a pod, and the other to allow exec to be tunneled over
websocket.
Browser support for chunked encoding is still poor, and web consoles
that wish to show pod logs may need to make compromises to display the
output. The /pods/<name>/log endpoint now supports websocket upgrade to
the 'binary.k8s.io' subprotocol, which sends chunks of logs as binary to
the client. Messages are written as logs are streamed from the container
daemon, so flushing should be unaffected.
Browser support for raw communication over SDPY is not possible, and
some languages lack libraries for it and HTTP/2. The Kubelet supports
upgrade to WebSocket instead of SPDY, and will multiplex STDOUT/IN/ERR
over websockets by prepending each binary message with a single byte
representing the channel (0 for IN, 1 for OUT, and 2 for ERR). Because
framing on WebSockets suffers from head-of-line blocking, clients and
other server code should ensure that no particular stream blocks. An
alternative subprotocol 'base64.channel.k8s.io' base64 encodes the body
and uses '0'-'9' to represent the channel for ease of use in browsers.
2015-09-11 20:09:51 +00:00
|
|
|
|
|
|
|
By("creating the pod")
|
|
|
|
name := "pod-logs-websocket-" + string(util.NewUUID())
|
|
|
|
pod := &api.Pod{
|
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Name: name,
|
|
|
|
},
|
|
|
|
Spec: api.PodSpec{
|
|
|
|
Containers: []api.Container{
|
|
|
|
{
|
|
|
|
Name: "main",
|
2016-02-08 23:28:55 +00:00
|
|
|
Image: "gcr.io/google_containers/busybox:1.24",
|
Expose exec and logs via WebSockets
Not all clients and systems can support SPDY protocols. This commit adds
support for two new websocket protocols, one to handle streaming of pod
logs from a pod, and the other to allow exec to be tunneled over
websocket.
Browser support for chunked encoding is still poor, and web consoles
that wish to show pod logs may need to make compromises to display the
output. The /pods/<name>/log endpoint now supports websocket upgrade to
the 'binary.k8s.io' subprotocol, which sends chunks of logs as binary to
the client. Messages are written as logs are streamed from the container
daemon, so flushing should be unaffected.
Browser support for raw communication over SDPY is not possible, and
some languages lack libraries for it and HTTP/2. The Kubelet supports
upgrade to WebSocket instead of SPDY, and will multiplex STDOUT/IN/ERR
over websockets by prepending each binary message with a single byte
representing the channel (0 for IN, 1 for OUT, and 2 for ERR). Because
framing on WebSockets suffers from head-of-line blocking, clients and
other server code should ensure that no particular stream blocks. An
alternative subprotocol 'base64.channel.k8s.io' base64 encodes the body
and uses '0'-'9' to represent the channel for ease of use in browsers.
2015-09-11 20:09:51 +00:00
|
|
|
Command: []string{"/bin/sh", "-c", "echo container is alive; sleep 600"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
By("submitting the pod to kubernetes")
|
|
|
|
defer func() {
|
|
|
|
By("deleting the pod")
|
|
|
|
podClient.Delete(pod.Name, api.NewDeleteOptions(0))
|
|
|
|
}()
|
|
|
|
pod, err = podClient.Create(pod)
|
|
|
|
if err != nil {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Failf("Failed to create pod: %v", err)
|
Expose exec and logs via WebSockets
Not all clients and systems can support SPDY protocols. This commit adds
support for two new websocket protocols, one to handle streaming of pod
logs from a pod, and the other to allow exec to be tunneled over
websocket.
Browser support for chunked encoding is still poor, and web consoles
that wish to show pod logs may need to make compromises to display the
output. The /pods/<name>/log endpoint now supports websocket upgrade to
the 'binary.k8s.io' subprotocol, which sends chunks of logs as binary to
the client. Messages are written as logs are streamed from the container
daemon, so flushing should be unaffected.
Browser support for raw communication over SDPY is not possible, and
some languages lack libraries for it and HTTP/2. The Kubelet supports
upgrade to WebSocket instead of SPDY, and will multiplex STDOUT/IN/ERR
over websockets by prepending each binary message with a single byte
representing the channel (0 for IN, 1 for OUT, and 2 for ERR). Because
framing on WebSockets suffers from head-of-line blocking, clients and
other server code should ensure that no particular stream blocks. An
alternative subprotocol 'base64.channel.k8s.io' base64 encodes the body
and uses '0'-'9' to represent the channel for ease of use in browsers.
2015-09-11 20:09:51 +00:00
|
|
|
}
|
|
|
|
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.ExpectNoError(f.WaitForPodRunning(pod.Name))
|
Expose exec and logs via WebSockets
Not all clients and systems can support SPDY protocols. This commit adds
support for two new websocket protocols, one to handle streaming of pod
logs from a pod, and the other to allow exec to be tunneled over
websocket.
Browser support for chunked encoding is still poor, and web consoles
that wish to show pod logs may need to make compromises to display the
output. The /pods/<name>/log endpoint now supports websocket upgrade to
the 'binary.k8s.io' subprotocol, which sends chunks of logs as binary to
the client. Messages are written as logs are streamed from the container
daemon, so flushing should be unaffected.
Browser support for raw communication over SDPY is not possible, and
some languages lack libraries for it and HTTP/2. The Kubelet supports
upgrade to WebSocket instead of SPDY, and will multiplex STDOUT/IN/ERR
over websockets by prepending each binary message with a single byte
representing the channel (0 for IN, 1 for OUT, and 2 for ERR). Because
framing on WebSockets suffers from head-of-line blocking, clients and
other server code should ensure that no particular stream blocks. An
alternative subprotocol 'base64.channel.k8s.io' base64 encodes the body
and uses '0'-'9' to represent the channel for ease of use in browsers.
2015-09-11 20:09:51 +00:00
|
|
|
|
2016-04-07 17:21:31 +00:00
|
|
|
req := f.Client.Get().
|
|
|
|
Namespace(f.Namespace.Name).
|
Expose exec and logs via WebSockets
Not all clients and systems can support SPDY protocols. This commit adds
support for two new websocket protocols, one to handle streaming of pod
logs from a pod, and the other to allow exec to be tunneled over
websocket.
Browser support for chunked encoding is still poor, and web consoles
that wish to show pod logs may need to make compromises to display the
output. The /pods/<name>/log endpoint now supports websocket upgrade to
the 'binary.k8s.io' subprotocol, which sends chunks of logs as binary to
the client. Messages are written as logs are streamed from the container
daemon, so flushing should be unaffected.
Browser support for raw communication over SDPY is not possible, and
some languages lack libraries for it and HTTP/2. The Kubelet supports
upgrade to WebSocket instead of SPDY, and will multiplex STDOUT/IN/ERR
over websockets by prepending each binary message with a single byte
representing the channel (0 for IN, 1 for OUT, and 2 for ERR). Because
framing on WebSockets suffers from head-of-line blocking, clients and
other server code should ensure that no particular stream blocks. An
alternative subprotocol 'base64.channel.k8s.io' base64 encodes the body
and uses '0'-'9' to represent the channel for ease of use in browsers.
2015-09-11 20:09:51 +00:00
|
|
|
Resource("pods").
|
|
|
|
Name(pod.Name).
|
|
|
|
Suffix("log").
|
|
|
|
Param("container", pod.Spec.Containers[0].Name)
|
|
|
|
|
|
|
|
url := req.URL()
|
|
|
|
|
2016-04-07 17:21:31 +00:00
|
|
|
ws, err := framework.OpenWebSocketForURL(url, config, []string{"binary.k8s.io"})
|
Expose exec and logs via WebSockets
Not all clients and systems can support SPDY protocols. This commit adds
support for two new websocket protocols, one to handle streaming of pod
logs from a pod, and the other to allow exec to be tunneled over
websocket.
Browser support for chunked encoding is still poor, and web consoles
that wish to show pod logs may need to make compromises to display the
output. The /pods/<name>/log endpoint now supports websocket upgrade to
the 'binary.k8s.io' subprotocol, which sends chunks of logs as binary to
the client. Messages are written as logs are streamed from the container
daemon, so flushing should be unaffected.
Browser support for raw communication over SDPY is not possible, and
some languages lack libraries for it and HTTP/2. The Kubelet supports
upgrade to WebSocket instead of SPDY, and will multiplex STDOUT/IN/ERR
over websockets by prepending each binary message with a single byte
representing the channel (0 for IN, 1 for OUT, and 2 for ERR). Because
framing on WebSockets suffers from head-of-line blocking, clients and
other server code should ensure that no particular stream blocks. An
alternative subprotocol 'base64.channel.k8s.io' base64 encodes the body
and uses '0'-'9' to represent the channel for ease of use in browsers.
2015-09-11 20:09:51 +00:00
|
|
|
if err != nil {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Failf("Failed to open websocket to %s: %v", url.String(), err)
|
Expose exec and logs via WebSockets
Not all clients and systems can support SPDY protocols. This commit adds
support for two new websocket protocols, one to handle streaming of pod
logs from a pod, and the other to allow exec to be tunneled over
websocket.
Browser support for chunked encoding is still poor, and web consoles
that wish to show pod logs may need to make compromises to display the
output. The /pods/<name>/log endpoint now supports websocket upgrade to
the 'binary.k8s.io' subprotocol, which sends chunks of logs as binary to
the client. Messages are written as logs are streamed from the container
daemon, so flushing should be unaffected.
Browser support for raw communication over SDPY is not possible, and
some languages lack libraries for it and HTTP/2. The Kubelet supports
upgrade to WebSocket instead of SPDY, and will multiplex STDOUT/IN/ERR
over websockets by prepending each binary message with a single byte
representing the channel (0 for IN, 1 for OUT, and 2 for ERR). Because
framing on WebSockets suffers from head-of-line blocking, clients and
other server code should ensure that no particular stream blocks. An
alternative subprotocol 'base64.channel.k8s.io' base64 encodes the body
and uses '0'-'9' to represent the channel for ease of use in browsers.
2015-09-11 20:09:51 +00:00
|
|
|
}
|
|
|
|
defer ws.Close()
|
|
|
|
buf := &bytes.Buffer{}
|
|
|
|
for {
|
|
|
|
var msg []byte
|
|
|
|
if err := websocket.Message.Receive(ws, &msg); err != nil {
|
|
|
|
if err == io.EOF {
|
|
|
|
break
|
|
|
|
}
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Failf("Failed to read completely from websocket %s: %v", url.String(), err)
|
Expose exec and logs via WebSockets
Not all clients and systems can support SPDY protocols. This commit adds
support for two new websocket protocols, one to handle streaming of pod
logs from a pod, and the other to allow exec to be tunneled over
websocket.
Browser support for chunked encoding is still poor, and web consoles
that wish to show pod logs may need to make compromises to display the
output. The /pods/<name>/log endpoint now supports websocket upgrade to
the 'binary.k8s.io' subprotocol, which sends chunks of logs as binary to
the client. Messages are written as logs are streamed from the container
daemon, so flushing should be unaffected.
Browser support for raw communication over SDPY is not possible, and
some languages lack libraries for it and HTTP/2. The Kubelet supports
upgrade to WebSocket instead of SPDY, and will multiplex STDOUT/IN/ERR
over websockets by prepending each binary message with a single byte
representing the channel (0 for IN, 1 for OUT, and 2 for ERR). Because
framing on WebSockets suffers from head-of-line blocking, clients and
other server code should ensure that no particular stream blocks. An
alternative subprotocol 'base64.channel.k8s.io' base64 encodes the body
and uses '0'-'9' to represent the channel for ease of use in browsers.
2015-09-11 20:09:51 +00:00
|
|
|
}
|
|
|
|
if len(msg) == 0 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
buf.Write(msg)
|
|
|
|
}
|
|
|
|
if buf.String() != "container is alive\n" {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Failf("Unexpected websocket logs:\n%s", buf.String())
|
Expose exec and logs via WebSockets
Not all clients and systems can support SPDY protocols. This commit adds
support for two new websocket protocols, one to handle streaming of pod
logs from a pod, and the other to allow exec to be tunneled over
websocket.
Browser support for chunked encoding is still poor, and web consoles
that wish to show pod logs may need to make compromises to display the
output. The /pods/<name>/log endpoint now supports websocket upgrade to
the 'binary.k8s.io' subprotocol, which sends chunks of logs as binary to
the client. Messages are written as logs are streamed from the container
daemon, so flushing should be unaffected.
Browser support for raw communication over SDPY is not possible, and
some languages lack libraries for it and HTTP/2. The Kubelet supports
upgrade to WebSocket instead of SPDY, and will multiplex STDOUT/IN/ERR
over websockets by prepending each binary message with a single byte
representing the channel (0 for IN, 1 for OUT, and 2 for ERR). Because
framing on WebSockets suffers from head-of-line blocking, clients and
other server code should ensure that no particular stream blocks. An
alternative subprotocol 'base64.channel.k8s.io' base64 encodes the body
and uses '0'-'9' to represent the channel for ease of use in browsers.
2015-09-11 20:09:51 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2016-01-30 00:36:18 +00:00
|
|
|
It("should have their auto-restart back-off timer reset on image update [Slow]", func() {
|
2015-10-15 04:58:20 +00:00
|
|
|
podName := "pod-back-off-image"
|
|
|
|
containerName := "back-off"
|
2016-04-07 17:21:31 +00:00
|
|
|
podClient := f.Client.Pods(f.Namespace.Name)
|
2015-10-15 04:58:20 +00:00
|
|
|
pod := &api.Pod{
|
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Name: podName,
|
|
|
|
Labels: map[string]string{"test": "back-off-image"},
|
|
|
|
},
|
|
|
|
Spec: api.PodSpec{
|
|
|
|
Containers: []api.Container{
|
|
|
|
{
|
|
|
|
Name: containerName,
|
2016-02-08 23:28:55 +00:00
|
|
|
Image: "gcr.io/google_containers/busybox:1.24",
|
2015-10-15 04:58:20 +00:00
|
|
|
Command: []string{"/bin/sh", "-c", "sleep 5", "/crash/missing"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
By("deleting the pod")
|
|
|
|
podClient.Delete(pod.Name, api.NewDeleteOptions(0))
|
|
|
|
}()
|
|
|
|
|
2016-04-07 17:21:31 +00:00
|
|
|
delay1, delay2 := startPodAndGetBackOffs(f, pod, podName, containerName, buildBackOffDuration)
|
2015-10-15 04:58:20 +00:00
|
|
|
|
|
|
|
By("updating the image")
|
|
|
|
pod, err := podClient.Get(pod.Name)
|
|
|
|
if err != nil {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Failf("failed to get pod: %v", err)
|
2015-10-15 04:58:20 +00:00
|
|
|
}
|
2016-02-25 00:54:40 +00:00
|
|
|
pod.Spec.Containers[0].Image = "gcr.io/google_containers/nginx:1.7.9"
|
2015-10-15 04:58:20 +00:00
|
|
|
pod, err = podClient.Update(pod)
|
|
|
|
if err != nil {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Failf("error updating pod=%s/%s %v", podName, containerName, err)
|
2015-10-15 04:58:20 +00:00
|
|
|
}
|
|
|
|
time.Sleep(syncLoopFrequency)
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.ExpectNoError(f.WaitForPodRunning(pod.Name))
|
2015-10-15 04:58:20 +00:00
|
|
|
|
|
|
|
By("get restart delay after image update")
|
2016-04-07 17:21:31 +00:00
|
|
|
delayAfterUpdate, err := getRestartDelay(f.Client, pod, f.Namespace.Name, podName, containerName)
|
2015-10-15 04:58:20 +00:00
|
|
|
if err != nil {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Failf("timed out waiting for container restart in pod=%s/%s", podName, containerName)
|
2015-10-15 04:58:20 +00:00
|
|
|
}
|
|
|
|
|
2015-10-27 00:58:22 +00:00
|
|
|
if delayAfterUpdate > 2*delay2 || delayAfterUpdate > 2*delay1 {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Failf("updating image did not reset the back-off value in pod=%s/%s d3=%s d2=%s d1=%s", podName, containerName, delayAfterUpdate, delay1, delay2)
|
2015-10-15 04:58:20 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2015-12-20 19:00:00 +00:00
|
|
|
// Slow issue #19027 (20 mins)
|
|
|
|
It("should cap back-off at MaxContainerBackOff [Slow]", func() {
|
2016-04-07 17:21:31 +00:00
|
|
|
podClient := f.Client.Pods(f.Namespace.Name)
|
2015-10-15 04:58:20 +00:00
|
|
|
podName := "back-off-cap"
|
|
|
|
containerName := "back-off-cap"
|
|
|
|
pod := &api.Pod{
|
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Name: podName,
|
|
|
|
Labels: map[string]string{"test": "liveness"},
|
|
|
|
},
|
|
|
|
Spec: api.PodSpec{
|
|
|
|
Containers: []api.Container{
|
|
|
|
{
|
|
|
|
Name: containerName,
|
2016-02-08 23:28:55 +00:00
|
|
|
Image: "gcr.io/google_containers/busybox:1.24",
|
2015-10-15 04:58:20 +00:00
|
|
|
Command: []string{"/bin/sh", "-c", "sleep 5", "/crash/missing"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
By("deleting the pod")
|
|
|
|
podClient.Delete(pod.Name, api.NewDeleteOptions(0))
|
|
|
|
}()
|
|
|
|
|
2016-04-07 17:21:31 +00:00
|
|
|
runPodFromStruct(f, pod)
|
2015-10-15 04:58:20 +00:00
|
|
|
time.Sleep(2 * kubelet.MaxContainerBackOff) // it takes slightly more than 2*x to get to a back-off of x
|
|
|
|
|
|
|
|
// wait for a delay == capped delay of MaxContainerBackOff
|
|
|
|
By("geting restart delay when capped")
|
|
|
|
var (
|
|
|
|
delay1 time.Duration
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
for i := 0; i < 3; i++ {
|
2016-04-07 17:21:31 +00:00
|
|
|
delay1, err = getRestartDelay(f.Client, pod, f.Namespace.Name, podName, containerName)
|
2015-10-15 04:58:20 +00:00
|
|
|
if err != nil {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Failf("timed out waiting for container restart in pod=%s/%s", podName, containerName)
|
2015-10-15 04:58:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if delay1 < kubelet.MaxContainerBackOff {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (delay1 < kubelet.MaxContainerBackOff) || (delay1 > maxBackOffTolerance) {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Failf("expected %s back-off got=%s in delay1", kubelet.MaxContainerBackOff, delay1)
|
2015-10-15 04:58:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
By("getting restart delay after a capped delay")
|
2016-04-07 17:21:31 +00:00
|
|
|
delay2, err := getRestartDelay(f.Client, pod, f.Namespace.Name, podName, containerName)
|
2015-10-15 04:58:20 +00:00
|
|
|
if err != nil {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Failf("timed out waiting for container restart in pod=%s/%s", podName, containerName)
|
2015-10-15 04:58:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if delay2 < kubelet.MaxContainerBackOff || delay2 > maxBackOffTolerance { // syncloop cumulative drift
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Failf("expected %s back-off got=%s on delay2", kubelet.MaxContainerBackOff, delay2)
|
2015-10-15 04:58:20 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2015-01-08 20:41:38 +00:00
|
|
|
// The following tests for remote command execution and port forwarding are
|
|
|
|
// commented out because the GCE environment does not currently have nsenter
|
|
|
|
// in the kubelet's PATH, nor does it have socat installed. Once we figure
|
|
|
|
// out the best way to have nsenter and socat available in GCE (and hopefully
|
|
|
|
// all providers), we can enable these tests.
|
|
|
|
/*
|
|
|
|
It("should support remote command execution", func() {
|
2016-04-07 17:21:31 +00:00
|
|
|
clientConfig, err := framework.LoadConfig()
|
2015-01-08 20:41:38 +00:00
|
|
|
if err != nil {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Failf("Failed to create client config: %v", err)
|
2015-01-08 20:41:38 +00:00
|
|
|
}
|
|
|
|
|
2016-04-07 17:21:31 +00:00
|
|
|
podClient := f.Client.Pods(f.Namespace.Name)
|
2015-01-08 20:41:38 +00:00
|
|
|
|
|
|
|
By("creating the pod")
|
|
|
|
name := "pod-exec-" + string(util.NewUUID())
|
|
|
|
value := strconv.Itoa(time.Now().Nanosecond())
|
|
|
|
pod := &api.Pod{
|
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Name: name,
|
|
|
|
Labels: map[string]string{
|
|
|
|
"name": "foo",
|
|
|
|
"time": value,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Spec: api.PodSpec{
|
|
|
|
Containers: []api.Container{
|
|
|
|
{
|
|
|
|
Name: "nginx",
|
2015-06-16 18:49:36 +00:00
|
|
|
Image: "gcr.io/google_containers/nginx:1.7.9",
|
2015-01-08 20:41:38 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
By("submitting the pod to kubernetes")
|
|
|
|
_, err = podClient.Create(pod)
|
|
|
|
if err != nil {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Failf("Failed to create pod: %v", err)
|
2015-01-08 20:41:38 +00:00
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
// We call defer here in case there is a problem with
|
|
|
|
// the test so we can ensure that we clean up after
|
|
|
|
// ourselves
|
2015-08-20 02:09:57 +00:00
|
|
|
podClient.Delete(pod.Name, api.NewDeleteOptions(0))
|
2015-01-08 20:41:38 +00:00
|
|
|
}()
|
|
|
|
|
|
|
|
By("waiting for the pod to start running")
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.ExpectNoError(f.WaitForPodRunning(pod.Name))
|
2015-01-08 20:41:38 +00:00
|
|
|
|
|
|
|
By("verifying the pod is in kubernetes")
|
2015-12-02 11:12:57 +00:00
|
|
|
selector := labels.SelectorFromSet(labels.Set(map[string]string{"time": value}))
|
2015-12-10 09:39:03 +00:00
|
|
|
options := api.ListOptions{LabelSelector: selector}
|
2015-12-02 11:12:57 +00:00
|
|
|
pods, err := podClient.List(options)
|
2015-01-08 20:41:38 +00:00
|
|
|
if err != nil {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Failf("Failed to query for pods: %v", err)
|
2015-01-08 20:41:38 +00:00
|
|
|
}
|
|
|
|
Expect(len(pods.Items)).To(Equal(1))
|
|
|
|
|
|
|
|
pod = &pods.Items[0]
|
|
|
|
By(fmt.Sprintf("executing command on host %s pod %s in container %s",
|
|
|
|
pod.Status.Host, pod.Name, pod.Spec.Containers[0].Name))
|
2016-04-07 17:21:31 +00:00
|
|
|
req := f.Client.Get().
|
2015-01-08 20:41:38 +00:00
|
|
|
Prefix("proxy").
|
2015-09-10 08:40:22 +00:00
|
|
|
Resource("nodes").
|
2015-01-08 20:41:38 +00:00
|
|
|
Name(pod.Status.Host).
|
2016-04-07 17:21:31 +00:00
|
|
|
Suffix("exec", f.Namespace.Name, pod.Name, pod.Spec.Containers[0].Name)
|
2015-01-08 20:41:38 +00:00
|
|
|
|
|
|
|
out := &bytes.Buffer{}
|
|
|
|
e := remotecommand.New(req, clientConfig, []string{"whoami"}, nil, out, nil, false)
|
|
|
|
err = e.Execute()
|
|
|
|
if err != nil {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Failf("Failed to execute command on host %s pod %s in container %s: %v",
|
2015-07-23 23:03:34 +00:00
|
|
|
pod.Status.Host, pod.Name, pod.Spec.Containers[0].Name, err)
|
2015-01-08 20:41:38 +00:00
|
|
|
}
|
|
|
|
if e, a := "root\n", out.String(); e != a {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Failf("exec: whoami: expected '%s', got '%s'", e, a)
|
2015-01-08 20:41:38 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
It("should support port forwarding", func() {
|
2016-04-07 17:21:31 +00:00
|
|
|
clientConfig, err := framework.LoadConfig()
|
2015-01-08 20:41:38 +00:00
|
|
|
if err != nil {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Failf("Failed to create client config: %v", err)
|
2015-01-08 20:41:38 +00:00
|
|
|
}
|
|
|
|
|
2016-04-07 17:21:31 +00:00
|
|
|
podClient := f.Client.Pods(f.Namespace.Name)
|
2015-01-08 20:41:38 +00:00
|
|
|
|
|
|
|
By("creating the pod")
|
|
|
|
name := "pod-portforward-" + string(util.NewUUID())
|
|
|
|
value := strconv.Itoa(time.Now().Nanosecond())
|
|
|
|
pod := &api.Pod{
|
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Name: name,
|
|
|
|
Labels: map[string]string{
|
|
|
|
"name": "foo",
|
|
|
|
"time": value,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Spec: api.PodSpec{
|
|
|
|
Containers: []api.Container{
|
|
|
|
{
|
|
|
|
Name: "nginx",
|
2015-06-16 18:49:36 +00:00
|
|
|
Image: "gcr.io/google_containers/nginx:1.7.9",
|
2015-01-08 20:41:38 +00:00
|
|
|
Ports: []api.Port{{ContainerPort: 80}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
By("submitting the pod to kubernetes")
|
|
|
|
_, err = podClient.Create(pod)
|
|
|
|
if err != nil {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Failf("Failed to create pod: %v", err)
|
2015-01-08 20:41:38 +00:00
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
// We call defer here in case there is a problem with
|
|
|
|
// the test so we can ensure that we clean up after
|
|
|
|
// ourselves
|
2015-08-20 02:09:57 +00:00
|
|
|
podClient.Delete(pod.Name, api.NewDeleteOptions(0))
|
2015-01-08 20:41:38 +00:00
|
|
|
}()
|
|
|
|
|
|
|
|
By("waiting for the pod to start running")
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.ExpectNoError(f.WaitForPodRunning(pod.Name))
|
2015-01-08 20:41:38 +00:00
|
|
|
|
|
|
|
By("verifying the pod is in kubernetes")
|
2015-12-02 11:12:57 +00:00
|
|
|
selector := labels.SelectorFromSet(labels.Set(map[string]string{"time": value}))
|
2015-12-10 09:39:03 +00:00
|
|
|
options := api.ListOptions{LabelSelector: selector}
|
2015-12-02 11:12:57 +00:00
|
|
|
pods, err := podClient.List(options)
|
2015-01-08 20:41:38 +00:00
|
|
|
if err != nil {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Failf("Failed to query for pods: %v", err)
|
2015-01-08 20:41:38 +00:00
|
|
|
}
|
|
|
|
Expect(len(pods.Items)).To(Equal(1))
|
|
|
|
|
|
|
|
pod = &pods.Items[0]
|
|
|
|
By(fmt.Sprintf("initiating port forwarding to host %s pod %s in container %s",
|
|
|
|
pod.Status.Host, pod.Name, pod.Spec.Containers[0].Name))
|
|
|
|
|
2016-04-07 17:21:31 +00:00
|
|
|
req := f.Client.Get().
|
2015-01-08 20:41:38 +00:00
|
|
|
Prefix("proxy").
|
2015-09-10 08:40:22 +00:00
|
|
|
Resource("nodes").
|
2015-01-08 20:41:38 +00:00
|
|
|
Name(pod.Status.Host).
|
2016-04-07 17:21:31 +00:00
|
|
|
Suffix("portForward", f.Namespace.Name, pod.Name)
|
2015-01-08 20:41:38 +00:00
|
|
|
|
|
|
|
stopChan := make(chan struct{})
|
|
|
|
pf, err := portforward.New(req, clientConfig, []string{"5678:80"}, stopChan)
|
|
|
|
if err != nil {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Failf("Error creating port forwarder: %s", err)
|
2015-01-08 20:41:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
errorChan := make(chan error)
|
|
|
|
go func() {
|
|
|
|
errorChan <- pf.ForwardPorts()
|
|
|
|
}()
|
|
|
|
|
|
|
|
// wait for listeners to start
|
|
|
|
<-pf.Ready
|
|
|
|
|
|
|
|
resp, err := http.Get("http://localhost:5678/")
|
|
|
|
if err != nil {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Failf("Error with http get to localhost:5678: %s", err)
|
2015-01-08 20:41:38 +00:00
|
|
|
}
|
|
|
|
body, err := ioutil.ReadAll(resp.Body)
|
|
|
|
if err != nil {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Failf("Error reading response body: %s", err)
|
2015-01-08 20:41:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
titleRegex := regexp.MustCompile("<title>(.+)</title>")
|
|
|
|
matches := titleRegex.FindStringSubmatch(string(body))
|
|
|
|
if len(matches) != 2 {
|
|
|
|
Fail("Unable to locate page title in response HTML")
|
|
|
|
}
|
|
|
|
if e, a := "Welcome to nginx on Debian!", matches[1]; e != a {
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.Failf("<title>: expected '%s', got '%s'", e, a)
|
2015-01-08 20:41:38 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
*/
|
2015-01-28 00:38:48 +00:00
|
|
|
})
|