Skip to content

Commit 2f1f997

Browse files
committed
add env var to allow disabling the aggregated discovery timeout
1 parent aaebd67 commit 2f1f997

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

staging/src/k8s.io/kube-aggregator/pkg/apiserver/handler_proxy.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import (
2020
"context"
2121
"net/http"
2222
"net/url"
23+
"os"
24+
"strconv"
2325
"strings"
2426
"sync/atomic"
2527
"time"
@@ -29,6 +31,7 @@ import (
2931
"k8s.io/apimachinery/pkg/util/httpstream/spdy"
3032
utilnet "k8s.io/apimachinery/pkg/util/net"
3133
"k8s.io/apimachinery/pkg/util/proxy"
34+
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
3235
"k8s.io/apiserver/pkg/endpoints/handlers/responsewriters"
3336
endpointmetrics "k8s.io/apiserver/pkg/endpoints/metrics"
3437
genericapirequest "k8s.io/apiserver/pkg/endpoints/request"
@@ -47,6 +50,19 @@ const (
4750
aggregatedDiscoveryTimeout = 5 * time.Second
4851
)
4952

53+
var (
54+
// TODO this should be unconditionally true once we remove the env var override
55+
enableAggregatedDiscoveryTimeout = true
56+
)
57+
58+
func init() {
59+
disableAggregatedDiscoveryTimeout, err := strconv.ParseBool(os.Getenv("DEPRECATED_DISABLE_AGGREGATOR_DISCOVERY_TIMEOUT"))
60+
if err != nil {
61+
utilruntime.HandleError(err)
62+
}
63+
enableAggregatedDiscoveryTimeout = !disableAggregatedDiscoveryTimeout
64+
}
65+
5066
// proxyHandler provides a http.Handler which will proxy traffic to locations
5167
// specified by items implementing Redirector.
5268
type proxyHandler struct {
@@ -185,7 +201,7 @@ func newRequestForProxy(location *url.URL, req *http.Request) (*http.Request, co
185201

186202
// trim leading and trailing slashes. Then "/apis/group/version" requests are for discovery, so if we have exactly three
187203
// segments that we are going to proxy, we have a discovery request.
188-
} else if len(strings.Split(strings.Trim(req.URL.Path, "/"), "/")) == 3 {
204+
} else if enableAggregatedDiscoveryTimeout && len(strings.Split(strings.Trim(req.URL.Path, "/"), "/")) == 3 {
189205
// discovery requests are used by kubectl and others to determine which resources a server has. This is a cheap call that
190206
// should be fast for every aggregated apiserver. Latency for aggregation is expected to be low (as for all extensions)
191207
// so forcing a short timeout here helps responsiveness of all clients.

0 commit comments

Comments
 (0)