From d9687a8c3adaf48d398237328a8db510f3b9399d Mon Sep 17 00:00:00 2001 From: Jian Zeng Date: Fri, 13 Sep 2024 22:22:59 +0800 Subject: [PATCH] feat(apiserver): set stream param in LogLocation Signed-off-by: Jian Zeng --- pkg/registry/core/pod/rest/log.go | 7 ++++++- pkg/registry/core/pod/strategy.go | 9 +++++++-- staging/src/k8s.io/apiserver/pkg/endpoints/installer.go | 2 ++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/pkg/registry/core/pod/rest/log.go b/pkg/registry/core/pod/rest/log.go index eb872337fef..55641b79323 100644 --- a/pkg/registry/core/pod/rest/log.go +++ b/pkg/registry/core/pod/rest/log.go @@ -21,6 +21,8 @@ import ( "fmt" utilruntime "k8s.io/apimachinery/pkg/util/runtime" + utilfeature "k8s.io/apiserver/pkg/util/feature" + "k8s.io/kubernetes/pkg/features" "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime" @@ -86,7 +88,10 @@ func (r *LogREST) Get(ctx context.Context, name string, opts runtime.Object) (ru countSkipTLSMetric(logOpts.InsecureSkipTLSVerifyBackend) - if errs := validation.ValidatePodLogOptions(logOpts); len(errs) > 0 { + if !utilfeature.DefaultFeatureGate.Enabled(features.PodLogsQuerySplitStreams) { + logOpts.Stream = nil + } + if errs := validation.ValidatePodLogOptions(logOpts, utilfeature.DefaultFeatureGate.Enabled(features.PodLogsQuerySplitStreams)); len(errs) > 0 { return nil, errors.NewInvalid(api.Kind("PodLogOptions"), name, errs) } location, transport, err := pod.LogLocation(ctx, r.Store, r.KubeletConn, name, logOpts) diff --git a/pkg/registry/core/pod/strategy.go b/pkg/registry/core/pod/strategy.go index 05257423fdc..fd239f6970e 100644 --- a/pkg/registry/core/pod/strategy.go +++ b/pkg/registry/core/pod/strategy.go @@ -26,6 +26,9 @@ import ( "strings" "time" + netutils "k8s.io/utils/net" + "sigs.k8s.io/structured-merge-diff/v4/fieldpath" + apiv1 "k8s.io/api/core/v1" apiequality "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/errors" @@ -50,8 +53,6 @@ import ( corevalidation "k8s.io/kubernetes/pkg/apis/core/validation" "k8s.io/kubernetes/pkg/features" "k8s.io/kubernetes/pkg/kubelet/client" - netutils "k8s.io/utils/net" - "sigs.k8s.io/structured-merge-diff/v4/fieldpath" ) // podStrategy implements behavior for Pods @@ -563,6 +564,10 @@ func LogLocation( if opts.LimitBytes != nil { params.Add("limitBytes", strconv.FormatInt(*opts.LimitBytes, 10)) } + if utilfeature.DefaultFeatureGate.Enabled(features.PodLogsQuerySplitStreams) { + // With defaulters, We can be confident that opts.Stream is not nil here. + params.Add("stream", string(*opts.Stream)) + } loc := &url.URL{ Scheme: nodeInfo.Scheme, Host: net.JoinHostPort(nodeInfo.Hostname, nodeInfo.Port), diff --git a/staging/src/k8s.io/apiserver/pkg/endpoints/installer.go b/staging/src/k8s.io/apiserver/pkg/endpoints/installer.go index 78e67109f08..f9dec903184 100644 --- a/staging/src/k8s.io/apiserver/pkg/endpoints/installer.go +++ b/staging/src/k8s.io/apiserver/pkg/endpoints/installer.go @@ -1216,6 +1216,8 @@ func typeToJSON(typeName string) string { return "string" case "v1.IncludeObjectPolicy", "*v1.IncludeObjectPolicy": return "string" + case "*string": + return "string" // TODO: Fix these when go-restful supports a way to specify an array query param: // https://github.com/emicklei/go-restful/issues/225