knative.dev/pkg@v0.0.0-20260602142205-ac97e43f6622/network/network.go (about)

     1  /*
     2  Copyright 2019 The Knative Authors
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      https://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package network
    18  
    19  import (
    20  	"net/http"
    21  	"strings"
    22  	"time"
    23  )
    24  
    25  const (
    26  	// DefaultDrainTimeout is the time that Knative components on the data
    27  	// path will wait before shutting down server, but after starting to fail
    28  	// readiness probes to ensure network layer propagation and so that no requests
    29  	// are routed to this pod.
    30  	// Note that this was bumped from 30s due to intermittent issues where
    31  	// the webhook would get a bad request from the API Server when running
    32  	// under chaos.
    33  	DefaultDrainTimeout = 45 * time.Second
    34  
    35  	// UserAgentKey is the constant for header "User-Agent".
    36  	UserAgentKey = "User-Agent"
    37  
    38  	// ProbeHeaderName is the name of a header that can be added to
    39  	// requests to probe the knative networking layer.  Requests
    40  	// with this header will not be passed to the user container or
    41  	// included in request metrics.
    42  	ProbeHeaderName = "K-Network-Probe"
    43  
    44  	// ProbeHeaderValue is the value of a header that can be added to
    45  	// requests to probe the knative networking layer.  Requests
    46  	// with `K-Network-Probe` this value will not be passed to the user
    47  	// container or included in request metrics.
    48  	ProbeHeaderValue = "probe"
    49  
    50  	// HashHeaderName is the name of an internal header that Ingress controller
    51  	// uses to find out which version of the networking config is deployed.
    52  	HashHeaderName = "K-Network-Hash"
    53  
    54  	// KubeProbeUAPrefix is the prefix for the User-Agent header.
    55  	// Since K8s 1.8, prober requests have
    56  	//   User-Agent = "kube-probe/{major-version}.{minor-version}".
    57  	KubeProbeUAPrefix = "kube-probe/"
    58  
    59  	// KubeletProbeHeaderName is the header name to augment the probes, because
    60  	// Istio with mTLS rewrites probes, but their probes pass a different
    61  	// user-agent.
    62  	//
    63  	// Deprecated: use knative.dev/networking/pkg/http/header.UserAgentKey
    64  	KubeletProbeHeaderName = "K-Kubelet-Probe"
    65  )
    66  
    67  // IsKubeletProbe returns true if the request is a Kubernetes probe.
    68  func IsKubeletProbe(r *http.Request) bool {
    69  	return strings.HasPrefix(r.Header.Get(UserAgentKey), KubeProbeUAPrefix)
    70  }