Skip to content

Commit dc59c02

Browse files
fuweidaojea
andcommitted
proxy: should add PingPeriod for websocket translator
IIUC, before using the translator handler, the ping data can be delivered from the client to the runtime side since kube-apiserver does not parse any client data. However, with WebSocket, the server responds with a pong to the client without forwarding the data to the runtime side. If a proxy is present, it may close the connection due to inactivity. SPDY's PingPeriod can help address this issue. Signed-off-by: Wei Fu <[email protected]> Co-authored-by: Antonio Ojea <[email protected]>
1 parent 215a910 commit dc59c02

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

staging/src/k8s.io/apiserver/pkg/util/proxy/streamtranslator.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"net/http"
2222
"net/url"
2323
"strconv"
24+
"time"
2425

2526
"github.com/mxk/go-flowrate/flowrate"
2627
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -70,7 +71,7 @@ func (h *StreamTranslatorHandler) ServeHTTP(w http.ResponseWriter, req *http.Req
7071
defer websocketStreams.conn.Close()
7172

7273
// Creating SPDY executor, ensuring redirects are not followed.
73-
spdyRoundTripper, err := spdy.NewRoundTripperWithConfig(spdy.RoundTripperConfig{UpgradeTransport: h.Transport})
74+
spdyRoundTripper, err := spdy.NewRoundTripperWithConfig(spdy.RoundTripperConfig{UpgradeTransport: h.Transport, PingPeriod: 5 * time.Second})
7475
if err != nil {
7576
websocketStreams.writeStatus(apierrors.NewInternalError(err)) //nolint:errcheck
7677
metrics.IncStreamTranslatorRequest(req.Context(), strconv.Itoa(http.StatusInternalServerError))

test/e2e/kubectl/kubectl.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,16 @@ var _ = SIGDescribe("Kubectl client", func() {
501501
}
502502
})
503503

504+
// https://issues.k8s.io/128314
505+
f.It(f.WithSlow(), "should support exec idle connections", func(ctx context.Context) {
506+
ginkgo.By("executing a command in the container")
507+
508+
execOutput := e2ekubectl.RunKubectlOrDie(ns, "exec", podRunningTimeoutArg, simplePodName, "--", "/bin/sh", "-c", "sleep 320 && echo running in container")
509+
if expected, got := "running in container", strings.TrimSpace(execOutput); expected != got {
510+
framework.Failf("Unexpected kubectl exec output. Wanted %q, got %q", expected, got)
511+
}
512+
})
513+
504514
ginkgo.It("should support exec through kubectl proxy", func(ctx context.Context) {
505515
_ = getTestContextHost()
506516

0 commit comments

Comments
 (0)