2015-01-13 02:11:27 +00:00
|
|
|
/*
|
2016-07-18 07:52:39 +00:00
|
|
|
Copyright 2016 The Kubernetes Authors.
|
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.
|
|
|
|
*/
|
|
|
|
|
2016-07-18 07:52:39 +00:00
|
|
|
package common
|
2015-01-13 02:11:27 +00:00
|
|
|
|
|
|
|
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"
|
|
|
|
|
2017-06-22 18:24:23 +00:00
|
|
|
"k8s.io/api/core/v1"
|
2017-01-11 14:09:48 +00:00
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
"k8s.io/apimachinery/pkg/labels"
|
2017-01-27 20:42:17 +00:00
|
|
|
"k8s.io/apimachinery/pkg/util/intstr"
|
2017-01-24 14:35:22 +00:00
|
|
|
"k8s.io/apimachinery/pkg/util/uuid"
|
2017-01-11 14:09:48 +00:00
|
|
|
"k8s.io/apimachinery/pkg/util/wait"
|
|
|
|
"k8s.io/apimachinery/pkg/watch"
|
2017-04-17 17:56:40 +00:00
|
|
|
podutil "k8s.io/kubernetes/pkg/api/v1/pod"
|
2015-10-15 04:58:20 +00:00
|
|
|
"k8s.io/kubernetes/pkg/kubelet"
|
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"
|
2017-08-29 08:32:08 +00:00
|
|
|
imageutils "k8s.io/kubernetes/test/utils/image"
|
2015-01-13 02:11:27 +00:00
|
|
|
)
|
|
|
|
|
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-04-10 20:00:07 +00:00
|
|
|
// testHostIP tests that a pod gets a host IP
|
2016-11-18 20:55:17 +00:00
|
|
|
func testHostIP(podClient *framework.PodClient, pod *v1.Pod) {
|
2015-04-10 20:00:07 +00:00
|
|
|
By("creating pod")
|
2016-07-18 07:52:39 +00:00
|
|
|
podClient.CreateSync(pod)
|
|
|
|
|
2015-04-10 20:00:07 +00:00
|
|
|
// 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 {
|
2016-12-07 14:40:26 +00:00
|
|
|
p, err := podClient.Get(pod.Name, metav1.GetOptions{})
|
2016-10-07 03:00:42 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred(), "Failed to get pod %q", pod.Name)
|
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-11-18 20:55:17 +00:00
|
|
|
func startPodAndGetBackOffs(podClient *framework.PodClient, pod *v1.Pod, sleepAmount time.Duration) (time.Duration, time.Duration) {
|
2016-07-18 07:52:39 +00:00
|
|
|
podClient.CreateSync(pod)
|
2015-10-15 04:58:20 +00:00
|
|
|
time.Sleep(sleepAmount)
|
2016-07-18 07:52:39 +00:00
|
|
|
Expect(pod.Spec.Containers).NotTo(BeEmpty())
|
|
|
|
podName := pod.Name
|
|
|
|
containerName := pod.Spec.Containers[0].Name
|
2015-10-15 04:58:20 +00:00
|
|
|
|
|
|
|
By("getting restart delay-0")
|
2016-07-18 07:52:39 +00:00
|
|
|
_, err := getRestartDelay(podClient, 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-07-18 07:52:39 +00:00
|
|
|
delay1, err := getRestartDelay(podClient, 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-07-18 07:52:39 +00:00
|
|
|
delay2, err := getRestartDelay(podClient, 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
|
|
|
|
}
|
|
|
|
|
2016-07-18 07:52:39 +00:00
|
|
|
func getRestartDelay(podClient *framework.PodClient, podName string, containerName string) (time.Duration, error) {
|
2015-10-15 04:58:20 +00:00
|
|
|
beginTime := time.Now()
|
|
|
|
for time.Since(beginTime) < (2 * maxBackOffTolerance) { // may just miss the 1st MaxContainerBackOff delay
|
|
|
|
time.Sleep(time.Second)
|
2016-12-07 14:40:26 +00:00
|
|
|
pod, err := podClient.Get(podName, metav1.GetOptions{})
|
2016-07-18 07:52:39 +00:00
|
|
|
framework.ExpectNoError(err, fmt.Sprintf("getting pod %s", podName))
|
2017-04-17 17:56:40 +00:00
|
|
|
status, ok := podutil.GetContainerStatus(pod.Status.ContainerStatuses, containerName)
|
2015-10-15 04:58:20 +00:00
|
|
|
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")
|
2016-07-18 07:52:39 +00:00
|
|
|
var podClient *framework.PodClient
|
|
|
|
BeforeEach(func() {
|
|
|
|
podClient = f.PodClient()
|
|
|
|
})
|
2015-01-30 20:59:13 +00:00
|
|
|
|
2017-10-13 15:22:06 +00:00
|
|
|
/*
|
|
|
|
Testname: pods-created-pod-assigned-hostip
|
|
|
|
Description: Make sure when a pod is created that it is assigned a host IP
|
|
|
|
Address.
|
|
|
|
*/
|
2018-05-22 01:09:33 +00:00
|
|
|
framework.ConformanceIt("should get a host IP [NodeConformance]", func() {
|
2016-07-26 15:13:18 +00:00
|
|
|
name := "pod-hostip-" + string(uuid.NewUUID())
|
2016-11-18 20:55:17 +00:00
|
|
|
testHostIP(podClient, &v1.Pod{
|
2017-01-17 03:38:19 +00:00
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
2015-04-10 20:00:07 +00:00
|
|
|
Name: name,
|
|
|
|
},
|
2016-11-18 20:55:17 +00:00
|
|
|
Spec: v1.PodSpec{
|
|
|
|
Containers: []v1.Container{
|
2015-04-10 20:00:07 +00:00
|
|
|
{
|
|
|
|
Name: "test",
|
2018-01-09 06:42:02 +00:00
|
|
|
Image: imageutils.GetPauseImageName(),
|
2015-04-10 20:00:07 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
2015-07-09 11:56:19 +00:00
|
|
|
|
2017-10-13 15:22:06 +00:00
|
|
|
/*
|
|
|
|
Testname: pods-submitted-removed
|
|
|
|
Description: Makes sure a pod is created, a watch can be setup for the pod,
|
|
|
|
pod creation was observed, pod is deleted, and pod deletion is observed.
|
|
|
|
*/
|
2018-05-22 01:09:33 +00:00
|
|
|
framework.ConformanceIt("should be submitted and removed [NodeConformance]", func() {
|
2015-02-03 20:29:23 +00:00
|
|
|
By("creating the pod")
|
2016-07-18 07:52:39 +00:00
|
|
|
name := "pod-submit-remove-" + string(uuid.NewUUID())
|
2015-01-30 21:00:03 +00:00
|
|
|
value := strconv.Itoa(time.Now().Nanosecond())
|
2016-11-18 20:55:17 +00:00
|
|
|
pod := &v1.Pod{
|
2017-01-17 03:38:19 +00:00
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
2015-02-03 20:29:23 +00:00
|
|
|
Name: name,
|
|
|
|
Labels: map[string]string{
|
|
|
|
"name": "foo",
|
|
|
|
"time": value,
|
|
|
|
},
|
|
|
|
},
|
2016-11-18 20:55:17 +00:00
|
|
|
Spec: v1.PodSpec{
|
|
|
|
Containers: []v1.Container{
|
2015-02-03 20:29:23 +00:00
|
|
|
{
|
|
|
|
Name: "nginx",
|
2017-08-29 08:32:08 +00:00
|
|
|
Image: imageutils.GetE2EImage(imageutils.NginxSlim),
|
2015-02-03 20:29:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
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}))
|
2017-01-22 03:36:02 +00:00
|
|
|
options := metav1.ListOptions{LabelSelector: selector.String()}
|
2015-12-02 11:12:57 +00:00
|
|
|
pods, err := podClient.List(options)
|
2016-07-18 07:52:39 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred(), "failed to query for pods")
|
2015-03-10 08:41:42 +00:00
|
|
|
Expect(len(pods.Items)).To(Equal(0))
|
2017-01-22 03:36:02 +00:00
|
|
|
options = metav1.ListOptions{
|
2016-11-18 20:55:17 +00:00
|
|
|
LabelSelector: selector.String(),
|
2015-11-26 15:27:45 +00:00
|
|
|
ResourceVersion: pods.ListMeta.ResourceVersion,
|
|
|
|
}
|
|
|
|
w, err := podClient.Watch(options)
|
2016-07-18 07:52:39 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred(), "failed to set up watch")
|
2015-03-10 08:41:42 +00:00
|
|
|
|
2015-01-30 21:00:03 +00:00
|
|
|
By("submitting the pod to kubernetes")
|
2016-07-18 07:52:39 +00:00
|
|
|
podClient.Create(pod)
|
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}))
|
2017-01-22 03:36:02 +00:00
|
|
|
options = metav1.ListOptions{LabelSelector: selector.String()}
|
2015-12-02 11:12:57 +00:00
|
|
|
pods, err = podClient.List(options)
|
2016-07-18 07:52:39 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred(), "failed to query for pods")
|
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):
|
2017-05-09 22:39:35 +00:00
|
|
|
framework.Failf("Timeout while waiting for pod creation")
|
2015-03-10 08:41:42 +00:00
|
|
|
}
|
|
|
|
|
2016-07-18 07:52:39 +00:00
|
|
|
// We need to wait for the pod to be running, otherwise the deletion
|
|
|
|
// may be carried out immediately rather than gracefully.
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.ExpectNoError(f.WaitForPodRunning(pod.Name))
|
2016-07-18 07:52:39 +00:00
|
|
|
// save the running pod
|
2016-12-07 14:40:26 +00:00
|
|
|
pod, err = podClient.Get(pod.Name, metav1.GetOptions{})
|
2016-07-18 07:52:39 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred(), "failed to GET scheduled pod")
|
|
|
|
framework.Logf("running pod: %#v", pod)
|
2016-01-27 07:08:50 +00:00
|
|
|
|
2015-08-20 02:18:59 +00:00
|
|
|
By("deleting the pod gracefully")
|
2017-01-24 15:38:21 +00:00
|
|
|
err = podClient.Delete(pod.Name, metav1.NewDeleteOptions(30))
|
2016-07-18 07:52:39 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred(), "failed to delete pod")
|
2015-03-10 08:41:42 +00:00
|
|
|
|
2016-03-09 23:01:55 +00:00
|
|
|
By("verifying the kubelet observed the termination notice")
|
|
|
|
Expect(wait.Poll(time.Second*5, time.Second*30, func() (bool, error) {
|
2016-10-18 13:00:38 +00:00
|
|
|
podList, err := framework.GetKubeletPods(f.ClientSet, 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
|
2016-11-18 20:55:17 +00:00
|
|
|
var lastPod *v1.Pod
|
2017-03-08 22:39:51 +00:00
|
|
|
timer := time.After(framework.DefaultPodDeletionTimeout)
|
2017-02-24 19:12:47 +00:00
|
|
|
for !deleted {
|
2015-03-10 08:41:42 +00:00
|
|
|
select {
|
|
|
|
case event, _ := <-w.ResultChan():
|
2017-02-24 19:12:47 +00:00
|
|
|
switch event.Type {
|
|
|
|
case watch.Deleted:
|
2016-11-18 20:55:17 +00:00
|
|
|
lastPod = event.Object.(*v1.Pod)
|
2015-03-10 08:41:42 +00:00
|
|
|
deleted = true
|
2017-02-24 19:12:47 +00:00
|
|
|
case watch.Error:
|
|
|
|
framework.Logf("received a watch error: %v", event.Object)
|
2017-05-09 22:39:35 +00:00
|
|
|
framework.Failf("watch closed with error")
|
2015-03-10 08:41:42 +00:00
|
|
|
}
|
|
|
|
case <-timer:
|
2017-05-09 22:39:35 +00:00
|
|
|
framework.Failf("timed out waiting for pod deletion")
|
2015-03-10 08:41:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if !deleted {
|
2017-05-09 22:39:35 +00:00
|
|
|
framework.Failf("Failed to observe pod deletion")
|
2015-03-10 08:41:42 +00:00
|
|
|
}
|
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}))
|
2017-01-22 03:36:02 +00:00
|
|
|
options = metav1.ListOptions{LabelSelector: selector.String()}
|
2015-12-02 11:12:57 +00:00
|
|
|
pods, err = podClient.List(options)
|
2016-07-18 07:52:39 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred(), "failed to query for pods")
|
2015-08-07 16:40:59 +00:00
|
|
|
Expect(len(pods.Items)).To(Equal(0))
|
2015-01-30 21:00:03 +00:00
|
|
|
})
|
|
|
|
|
2017-10-13 15:22:06 +00:00
|
|
|
/*
|
|
|
|
Testname: pods-updated-successfully
|
|
|
|
Description: Make sure it is possible to successfully update a pod's labels.
|
|
|
|
*/
|
2018-05-22 01:09:33 +00:00
|
|
|
framework.ConformanceIt("should be updated [NodeConformance]", func() {
|
2015-01-30 20:59:13 +00:00
|
|
|
By("creating the pod")
|
2016-07-26 15:13:18 +00:00
|
|
|
name := "pod-update-" + string(uuid.NewUUID())
|
2015-01-30 20:59:13 +00:00
|
|
|
value := strconv.Itoa(time.Now().Nanosecond())
|
2016-11-18 20:55:17 +00:00
|
|
|
pod := &v1.Pod{
|
2017-01-17 03:38:19 +00:00
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
2015-01-30 20:59:13 +00:00
|
|
|
Name: name,
|
|
|
|
Labels: map[string]string{
|
|
|
|
"name": "foo",
|
|
|
|
"time": value,
|
|
|
|
},
|
2015-01-30 23:25:56 +00:00
|
|
|
},
|
2016-11-18 20:55:17 +00:00
|
|
|
Spec: v1.PodSpec{
|
|
|
|
Containers: []v1.Container{
|
2015-01-30 20:59:13 +00:00
|
|
|
{
|
|
|
|
Name: "nginx",
|
2017-08-29 08:32:08 +00:00
|
|
|
Image: imageutils.GetE2EImage(imageutils.NginxSlim),
|
2015-01-30 23:25:56 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2015-01-30 20:59:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
By("submitting the pod to kubernetes")
|
2016-07-18 07:52:39 +00:00
|
|
|
pod = podClient.CreateSync(pod)
|
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}))
|
2017-01-22 03:36:02 +00:00
|
|
|
options := metav1.ListOptions{LabelSelector: selector.String()}
|
2015-12-02 11:12:57 +00:00
|
|
|
pods, err := podClient.List(options)
|
2016-07-18 07:52:39 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred(), "failed to query for pods")
|
2015-01-30 20:59:13 +00:00
|
|
|
Expect(len(pods.Items)).To(Equal(1))
|
|
|
|
|
2016-07-06 02:05:53 +00:00
|
|
|
By("updating the pod")
|
2016-11-18 20:55:17 +00:00
|
|
|
podClient.Update(name, func(pod *v1.Pod) {
|
2015-04-21 00:42:17 +00:00
|
|
|
value = strconv.Itoa(time.Now().Nanosecond())
|
|
|
|
pod.Labels["time"] = value
|
2016-07-06 02:05:53 +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 updated pod is in kubernetes")
|
2015-12-02 11:12:57 +00:00
|
|
|
selector = labels.SelectorFromSet(labels.Set(map[string]string{"time": value}))
|
2017-01-22 03:36:02 +00:00
|
|
|
options = metav1.ListOptions{LabelSelector: selector.String()}
|
2015-12-02 11:12:57 +00:00
|
|
|
pods, err = podClient.List(options)
|
2016-07-18 07:52:39 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred(), "failed to query for pods")
|
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
|
|
|
|
2017-10-13 15:22:06 +00:00
|
|
|
/*
|
|
|
|
Testname: pods-update-active-deadline-seconds
|
|
|
|
Description: Make sure it is possible to create a pod, update its
|
|
|
|
activeDeadlineSecondsValue, and then waits for the deadline to pass
|
|
|
|
and verifies the pod is terminated.
|
|
|
|
*/
|
2018-05-22 01:09:33 +00:00
|
|
|
framework.ConformanceIt("should allow activeDeadlineSeconds to be updated [NodeConformance]", func() {
|
2016-01-26 20:52:14 +00:00
|
|
|
By("creating the pod")
|
2016-07-26 15:13:18 +00:00
|
|
|
name := "pod-update-activedeadlineseconds-" + string(uuid.NewUUID())
|
2016-01-26 20:52:14 +00:00
|
|
|
value := strconv.Itoa(time.Now().Nanosecond())
|
2016-11-18 20:55:17 +00:00
|
|
|
pod := &v1.Pod{
|
2017-01-17 03:38:19 +00:00
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
2016-01-26 20:52:14 +00:00
|
|
|
Name: name,
|
|
|
|
Labels: map[string]string{
|
|
|
|
"name": "foo",
|
|
|
|
"time": value,
|
|
|
|
},
|
|
|
|
},
|
2016-11-18 20:55:17 +00:00
|
|
|
Spec: v1.PodSpec{
|
|
|
|
Containers: []v1.Container{
|
2016-01-26 20:52:14 +00:00
|
|
|
{
|
|
|
|
Name: "nginx",
|
2017-08-29 08:32:08 +00:00
|
|
|
Image: imageutils.GetE2EImage(imageutils.NginxSlim),
|
2016-01-26 20:52:14 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
By("submitting the pod to kubernetes")
|
2016-07-18 07:52:39 +00:00
|
|
|
podClient.CreateSync(pod)
|
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}))
|
2017-01-22 03:36:02 +00:00
|
|
|
options := metav1.ListOptions{LabelSelector: selector.String()}
|
2016-01-26 20:52:14 +00:00
|
|
|
pods, err := podClient.List(options)
|
2016-07-18 07:52:39 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred(), "failed to query for pods")
|
2016-01-26 20:52:14 +00:00
|
|
|
Expect(len(pods.Items)).To(Equal(1))
|
|
|
|
|
2016-07-06 02:05:53 +00:00
|
|
|
By("updating the pod")
|
2016-11-18 20:55:17 +00:00
|
|
|
podClient.Update(name, func(pod *v1.Pod) {
|
2016-01-26 20:52:14 +00:00
|
|
|
newDeadline := int64(5)
|
|
|
|
pod.Spec.ActiveDeadlineSeconds = &newDeadline
|
2016-07-06 02:05:53 +00:00
|
|
|
})
|
2016-01-26 20:52:14 +00:00
|
|
|
|
2016-04-07 17:21:31 +00:00
|
|
|
framework.ExpectNoError(f.WaitForPodTerminated(pod.Name, "DeadlineExceeded"))
|
2016-01-26 20:52:14 +00:00
|
|
|
})
|
|
|
|
|
2017-10-13 15:22:06 +00:00
|
|
|
/*
|
|
|
|
Testname: pods-contain-services-environment-variables
|
|
|
|
Description: Make sure that when a pod is created it contains environment
|
|
|
|
variables for each active service.
|
|
|
|
*/
|
2018-05-22 01:09:33 +00:00
|
|
|
framework.ConformanceIt("should contain environment variables for services [NodeConformance]", func() {
|
2015-02-02 14:11:06 +00:00
|
|
|
// Make a pod that will be a service.
|
|
|
|
// This pod serves its hostname via HTTP.
|
2016-07-26 15:13:18 +00:00
|
|
|
serverName := "server-envvars-" + string(uuid.NewUUID())
|
2016-11-18 20:55:17 +00:00
|
|
|
serverPod := &v1.Pod{
|
2017-01-17 03:38:19 +00:00
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
2015-02-03 18:43:14 +00:00
|
|
|
Name: serverName,
|
|
|
|
Labels: map[string]string{"name": serverName},
|
|
|
|
},
|
2016-11-18 20:55:17 +00:00
|
|
|
Spec: v1.PodSpec{
|
|
|
|
Containers: []v1.Container{
|
2015-02-03 18:43:14 +00:00
|
|
|
{
|
|
|
|
Name: "srv",
|
2017-04-24 07:08:39 +00:00
|
|
|
Image: framework.ServeHostnameImage,
|
2016-11-18 20:55:17 +00:00
|
|
|
Ports: []v1.ContainerPort{{ContainerPort: 9376}},
|
2015-02-03 18:43:14 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2016-07-18 07:52:39 +00:00
|
|
|
podClient.CreateSync(serverPod)
|
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"
|
2016-11-18 20:55:17 +00:00
|
|
|
svc := &v1.Service{
|
2017-01-17 03:38:19 +00:00
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
2015-02-03 18:43:14 +00:00
|
|
|
Name: svcName,
|
|
|
|
Labels: map[string]string{
|
|
|
|
"name": svcName,
|
|
|
|
},
|
|
|
|
},
|
2016-11-18 20:55:17 +00:00
|
|
|
Spec: v1.ServiceSpec{
|
|
|
|
Ports: []v1.ServicePort{{
|
2015-03-13 15:16:41 +00:00
|
|
|
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
|
|
|
}
|
2017-10-25 15:54:32 +00:00
|
|
|
_, err := f.ClientSet.CoreV1().Services(f.Namespace.Name).Create(svc)
|
2016-07-18 07:52:39 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred(), "failed to create service")
|
2015-02-02 14:11:06 +00:00
|
|
|
|
|
|
|
// Make a client pod that verifies that it has the service environment variables.
|
2016-07-26 15:13:18 +00:00
|
|
|
podName := "client-envvars-" + string(uuid.NewUUID())
|
2016-08-31 22:19:56 +00:00
|
|
|
const containerName = "env3cont"
|
2016-11-18 20:55:17 +00:00
|
|
|
pod := &v1.Pod{
|
2017-01-17 03:38:19 +00:00
|
|
|
ObjectMeta: metav1.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
|
|
|
},
|
2016-11-18 20:55:17 +00:00
|
|
|
Spec: v1.PodSpec{
|
|
|
|
Containers: []v1.Container{
|
2015-02-03 18:43:14 +00:00
|
|
|
{
|
2016-08-31 22:19:56 +00:00
|
|
|
Name: containerName,
|
2017-08-29 08:32:08 +00:00
|
|
|
Image: busyboxImage,
|
2015-03-31 17:25:14 +00:00
|
|
|
Command: []string{"sh", "-c", "env"},
|
2015-02-03 18:43:14 +00:00
|
|
|
},
|
|
|
|
},
|
2016-11-18 20:55:17 +00:00
|
|
|
RestartPolicy: v1.RestartPolicyNever,
|
2015-02-03 18:43:14 +00:00
|
|
|
},
|
|
|
|
}
|
2015-02-02 14:11:06 +00:00
|
|
|
|
2016-08-31 22:19:56 +00:00
|
|
|
// It's possible for the Pod to be created before the Kubelet is updated with the new
|
|
|
|
// service. In that case, we just retry.
|
|
|
|
const maxRetries = 3
|
|
|
|
expectedVars := []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=",
|
2016-08-31 22:19:56 +00:00
|
|
|
}
|
|
|
|
framework.ExpectNoErrorWithRetries(func() error {
|
|
|
|
return f.MatchContainerOutput(pod, containerName, expectedVars, ContainSubstring)
|
|
|
|
}, maxRetries, "Container should have service environment variables set")
|
2015-02-02 14:11:06 +00:00
|
|
|
})
|
2015-02-10 14:03:21 +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()
|
2016-07-18 07:52:39 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred(), "unable to get base config")
|
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")
|
2016-07-26 15:13:18 +00:00
|
|
|
name := "pod-exec-websocket-" + string(uuid.NewUUID())
|
2016-11-18 20:55:17 +00:00
|
|
|
pod := &v1.Pod{
|
2017-01-17 03:38:19 +00:00
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
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
|
|
|
Name: name,
|
|
|
|
},
|
2016-11-18 20:55:17 +00:00
|
|
|
Spec: v1.PodSpec{
|
|
|
|
Containers: []v1.Container{
|
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
|
|
|
{
|
|
|
|
Name: "main",
|
2017-08-29 08:32:08 +00:00
|
|
|
Image: busyboxImage,
|
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")
|
2016-07-18 07:52:39 +00:00
|
|
|
pod = podClient.CreateSync(pod)
|
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
|
|
|
|
2017-10-25 15:54:32 +00:00
|
|
|
req := f.ClientSet.CoreV1().RESTClient().Get().
|
2016-04-07 17:21:31 +00:00
|
|
|
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{}
|
2016-08-31 00:11:48 +00:00
|
|
|
Eventually(func() error {
|
|
|
|
for {
|
|
|
|
var msg []byte
|
|
|
|
if err := websocket.Message.Receive(ws, &msg); err != nil {
|
|
|
|
if err == io.EOF {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
2016-08-31 00:11:48 +00:00
|
|
|
if len(msg) == 0 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if msg[0] != 1 {
|
2018-02-26 21:15:37 +00:00
|
|
|
if len(msg) == 1 {
|
|
|
|
// skip an empty message on stream other than stdout
|
|
|
|
continue
|
|
|
|
} else {
|
|
|
|
framework.Failf("Got message from server that didn't start with channel 1 (STDOUT): %v", msg)
|
|
|
|
}
|
|
|
|
|
2016-08-31 00:11:48 +00:00
|
|
|
}
|
|
|
|
buf.Write(msg[1:])
|
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-08-31 00:11:48 +00:00
|
|
|
if buf.Len() == 0 {
|
|
|
|
return fmt.Errorf("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
|
|
|
}
|
2016-08-31 00:11:48 +00:00
|
|
|
if !strings.Contains(buf.String(), "nameserver") {
|
|
|
|
return fmt.Errorf("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
|
|
|
}
|
2016-08-31 00:11:48 +00:00
|
|
|
return nil
|
|
|
|
}, time.Minute, 10*time.Second).Should(BeNil())
|
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()
|
2016-07-18 07:52:39 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred(), "unable to get base config")
|
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")
|
2016-07-26 15:13:18 +00:00
|
|
|
name := "pod-logs-websocket-" + string(uuid.NewUUID())
|
2016-11-18 20:55:17 +00:00
|
|
|
pod := &v1.Pod{
|
2017-01-17 03:38:19 +00:00
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
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
|
|
|
Name: name,
|
|
|
|
},
|
2016-11-18 20:55:17 +00:00
|
|
|
Spec: v1.PodSpec{
|
|
|
|
Containers: []v1.Container{
|
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
|
|
|
{
|
|
|
|
Name: "main",
|
2017-08-29 08:32:08 +00:00
|
|
|
Image: busyboxImage,
|
2016-08-29 20:00:00 +00:00
|
|
|
Command: []string{"/bin/sh", "-c", "echo container is alive; sleep 10000"},
|
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("submitting the pod to kubernetes")
|
2016-07-18 07:52:39 +00:00
|
|
|
podClient.CreateSync(pod)
|
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
|
|
|
|
2017-10-25 15:54:32 +00:00
|
|
|
req := f.ClientSet.CoreV1().RESTClient().Get().
|
2016-04-07 17:21:31 +00:00
|
|
|
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
|
|
|
}
|
2016-08-29 20:00:00 +00:00
|
|
|
if len(strings.TrimSpace(string(msg))) == 0 {
|
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
|
|
|
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-11-18 20:55:17 +00:00
|
|
|
pod := &v1.Pod{
|
2017-01-17 03:38:19 +00:00
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
2015-10-15 04:58:20 +00:00
|
|
|
Name: podName,
|
|
|
|
Labels: map[string]string{"test": "back-off-image"},
|
|
|
|
},
|
2016-11-18 20:55:17 +00:00
|
|
|
Spec: v1.PodSpec{
|
|
|
|
Containers: []v1.Container{
|
2015-10-15 04:58:20 +00:00
|
|
|
{
|
|
|
|
Name: containerName,
|
2017-08-29 08:32:08 +00:00
|
|
|
Image: busyboxImage,
|
2015-10-15 04:58:20 +00:00
|
|
|
Command: []string{"/bin/sh", "-c", "sleep 5", "/crash/missing"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2016-07-18 07:52:39 +00:00
|
|
|
delay1, delay2 := startPodAndGetBackOffs(podClient, pod, buildBackOffDuration)
|
2015-10-15 04:58:20 +00:00
|
|
|
|
|
|
|
By("updating the image")
|
2016-11-18 20:55:17 +00:00
|
|
|
podClient.Update(podName, func(pod *v1.Pod) {
|
2017-08-29 08:32:08 +00:00
|
|
|
pod.Spec.Containers[0].Image = imageutils.GetE2EImage(imageutils.NginxSlim)
|
2016-07-06 02:05:53 +00:00
|
|
|
})
|
|
|
|
|
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-07-18 07:52:39 +00:00
|
|
|
delayAfterUpdate, err := getRestartDelay(podClient, 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() {
|
2015-10-15 04:58:20 +00:00
|
|
|
podName := "back-off-cap"
|
|
|
|
containerName := "back-off-cap"
|
2016-11-18 20:55:17 +00:00
|
|
|
pod := &v1.Pod{
|
2017-01-17 03:38:19 +00:00
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
2015-10-15 04:58:20 +00:00
|
|
|
Name: podName,
|
|
|
|
Labels: map[string]string{"test": "liveness"},
|
|
|
|
},
|
2016-11-18 20:55:17 +00:00
|
|
|
Spec: v1.PodSpec{
|
|
|
|
Containers: []v1.Container{
|
2015-10-15 04:58:20 +00:00
|
|
|
{
|
|
|
|
Name: containerName,
|
2017-08-29 08:32:08 +00:00
|
|
|
Image: busyboxImage,
|
2015-10-15 04:58:20 +00:00
|
|
|
Command: []string{"/bin/sh", "-c", "sleep 5", "/crash/missing"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2016-07-18 07:52:39 +00:00
|
|
|
podClient.CreateSync(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
|
2018-02-09 06:53:53 +00:00
|
|
|
By("getting restart delay when capped")
|
2015-10-15 04:58:20 +00:00
|
|
|
var (
|
|
|
|
delay1 time.Duration
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
for i := 0; i < 3; i++ {
|
2016-07-18 07:52:39 +00:00
|
|
|
delay1, err = getRestartDelay(podClient, 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-07-18 07:52:39 +00:00
|
|
|
delay2, err := getRestartDelay(podClient, 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-28 00:38:48 +00:00
|
|
|
})
|