[main] Upgrade to latest dependencies (#1675)

* upgrade to latest dependencies

bumping knative.dev/pkg a8b7d99...f907b31:
  > f907b31 Update community files (# 2520)
  > 2d8305b Update community files (# 2517)
bumping knative.dev/hack a8076b0...b4d4d73:
  > b4d4d73 Update community files (# 178)
  > f4972b4 Update community files (# 177)
bumping knative.dev/serving f726b1d...45f7c05:
  > 45f7c05 Fix deprecation notices (# 12958)
  > 4446497 fix owner files after merging scaling + serving working groups (# 12960)
  > 92b11a8 drop swap file (# 12959)
  > 591e12d upgrade to latest dependencies (# 12954)
  > a522443 Update net-istio nightly (# 12951)
  > 9ea835d Update net-gateway-api nightly (# 12950)
  > bc7fcd3 Update net-certmanager nightly (# 12949)
  > b2fff20 Update net-contour nightly (# 12948)
  > 9db81c3 Update net-kourier nightly (# 12952)
  > 4e54509 Update community files (# 12946)
  > 646e5cc Update net-istio nightly (# 12945)
  > f56e235 Update net-certmanager nightly (# 12944)
  > 08f0d31 Update net-contour nightly (# 12929)
  > ba84f6e upgrade to latest dependencies (# 12943)
  > 08e09bc kind-e2e dump namespaces and crds (# 12942)
  > 5776635 Update net-istio nightly (# 12931)
  > d7e2e3a Update net-certmanager nightly (# 12928)
  > 0bdaf56 Update net-kourier nightly (# 12930)
  > 3b832ad Update net-gateway-api nightly (# 12926)
  > 1a99825 Use mako stub for collecting performance tests results (# 12889)
  > fd6b191 fix a flake where the informer didn't have KPA (# 12934)
  > 9b7788c Update community files (# 12933)
  > f778a37 Update net-certmanager nightly (# 12925)
bumping knative.dev/eventing 9af9870...c3e1396:
  > c3e1396 Propagate log level to env var in source ConfigWatcher (# 6391)
  > 9449169 Update community files (# 6390)
  > d7a8a95 upgrade to latest dependencies (# 6389)
  > 75253dc Only proxy some headers from the reply in MTBroker filter (# 6357)
  > bba50a4 Upgrade test exports logs before shutting down sender (# 6384)
  > 0a738fd Remove calling 'ExecuteLocalYAML', b/c it is deprecated (# 6380)
  > e7c9ffc Adding retry for 408 (Request Timeout) http status code ♻️ (# 6370)
  > b966175 remove the namespae for the imc (# 6382)
  > 005d6b6 adding util for adding custom annotation values to different broker implementation usage (# 6378)
  > 02a6fa0 Update community files (# 6379)
  > ee7c071 Update the link of the sample code.(# 6374) (# 6375)
bumping knative.dev/networking 91dcb36...941c61a:
  > 941c61a move label to apis/networking (# 674)
  > 773e2bf fix deprecated comments (# 673)
  > 3f52bdb Update community files (# 672)
  > f1ee84b Split up the `networking/pkg` to separate packages (# 670)
  > 7363ea6 Add label selector for secrets (# 668)
  > 894675d Update community files (# 669)

Signed-off-by: Knative Automation <automation@knative.team>

* Fix deprecated networking pkg label

Co-authored-by: David Simansky <dsimansk@redhat.com>
This commit is contained in:
knative-automation 2022-05-24 16:13:03 -04:00 committed by GitHub
parent 2f4e19252f
commit 4df601027b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
34 changed files with 1289 additions and 367 deletions

10
go.mod
View File

@ -21,11 +21,11 @@ require (
k8s.io/cli-runtime v0.23.4
k8s.io/client-go v0.23.5
k8s.io/code-generator v0.23.5
knative.dev/eventing v0.31.1-0.20220509144032-9af98709e92b
knative.dev/hack v0.0.0-20220506160929-a8076b0510ed
knative.dev/networking v0.0.0-20220505013701-91dcb36802a9
knative.dev/pkg v0.0.0-20220505013700-a8b7d99374a3
knative.dev/serving v0.31.1-0.20220510145433-f726b1db1b0a
knative.dev/eventing v0.31.1-0.20220523181303-c3e13967001f
knative.dev/hack v0.0.0-20220518013938-b4d4d73a2995
knative.dev/networking v0.0.0-20220519194057-941c61aa258b
knative.dev/pkg v0.0.0-20220518013728-f907b31046d3
knative.dev/serving v0.31.1-0.20220521001759-45f7c054f694
sigs.k8s.io/yaml v1.3.0
)

29
go.sum
View File

@ -2268,25 +2268,26 @@ k8s.io/utils v0.0.0-20210930125809-cb0fa318a74b/go.mod h1:jPW/WVKK9YHAvNhRxK0md/
k8s.io/utils v0.0.0-20211116205334-6203023598ed/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9 h1:HNSDgDCrr/6Ly3WEGKZftiE7IY19Vz2GdbOCyI4qqhc=
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
knative.dev/caching v0.0.0-20220504134959-dd8e0ef37355/go.mod h1:AoEBl6LxEVEHZNkuu/s34Z/ffIFX8SQBJ7+puQXkczU=
knative.dev/eventing v0.31.1-0.20220509144032-9af98709e92b h1:Pn78o0BAvZY5KBdYpt0zFuOOQHXzI6WOaQT+R78wx3E=
knative.dev/eventing v0.31.1-0.20220509144032-9af98709e92b/go.mod h1:aqiJ8eEXtXBz3vERz/2lbkRjA1jbG6yXujaEGHqKLgs=
knative.dev/caching v0.0.0-20220518013728-03ca91f08490/go.mod h1:AoEBl6LxEVEHZNkuu/s34Z/ffIFX8SQBJ7+puQXkczU=
knative.dev/eventing v0.31.1-0.20220523181303-c3e13967001f h1:1wtkcxcu3p+uRzQ/PP2qup8yGAFaa7yX+1alUmjtUoQ=
knative.dev/eventing v0.31.1-0.20220523181303-c3e13967001f/go.mod h1:xFZEPJpiJ4sQ8S5IUdCFvKsnkKBlVVXdbFdMAb9aOfA=
knative.dev/hack v0.0.0-20220427014036-5f473869d377/go.mod h1:PHt8x8yX5Z9pPquBEfIj0X66f8iWkWfR0S/sarACJrI=
knative.dev/hack v0.0.0-20220503220458-46c77f157e20/go.mod h1:PHt8x8yX5Z9pPquBEfIj0X66f8iWkWfR0S/sarACJrI=
knative.dev/hack v0.0.0-20220505013956-ccf82ad03f32/go.mod h1:PHt8x8yX5Z9pPquBEfIj0X66f8iWkWfR0S/sarACJrI=
knative.dev/hack v0.0.0-20220506160929-a8076b0510ed h1:6mFHY1IFMRnO9O1z9q6xL9mAy6Gpm8SmRQ2KbahXKz0=
knative.dev/hack v0.0.0-20220506160929-a8076b0510ed/go.mod h1:PHt8x8yX5Z9pPquBEfIj0X66f8iWkWfR0S/sarACJrI=
knative.dev/hack/schema v0.0.0-20220506160929-a8076b0510ed/go.mod h1:ffjwmdcrH5vN3mPhO8RrF2KfNnbHeCE2C60A+2cv3U0=
knative.dev/networking v0.0.0-20220504043559-8d5dcbeeea2a/go.mod h1:+H5KnK/r/4/WtRRacuQuuGEjCn0961q2o7gwl+FoZfo=
knative.dev/networking v0.0.0-20220505013701-91dcb36802a9 h1:3/5bRIjG/cHKCQVmD/lMVCFKaym1U+0+Hlah25sF8c8=
knative.dev/networking v0.0.0-20220505013701-91dcb36802a9/go.mod h1:+H5KnK/r/4/WtRRacuQuuGEjCn0961q2o7gwl+FoZfo=
knative.dev/hack v0.0.0-20220512014059-f4972b4daff9/go.mod h1:PHt8x8yX5Z9pPquBEfIj0X66f8iWkWfR0S/sarACJrI=
knative.dev/hack v0.0.0-20220518013938-b4d4d73a2995 h1:Bt1Mdo6K6E4gaVUFiI8ZMvFcvsb0e10vLFyW7qKRxy4=
knative.dev/hack v0.0.0-20220518013938-b4d4d73a2995/go.mod h1:PHt8x8yX5Z9pPquBEfIj0X66f8iWkWfR0S/sarACJrI=
knative.dev/hack/schema v0.0.0-20220512014059-f4972b4daff9/go.mod h1:ffjwmdcrH5vN3mPhO8RrF2KfNnbHeCE2C60A+2cv3U0=
knative.dev/networking v0.0.0-20220519194057-941c61aa258b h1:l9qsbYY77iIAxw+zkS5oHQSQH2DIOEiygksNCsu/z5I=
knative.dev/networking v0.0.0-20220519194057-941c61aa258b/go.mod h1:8JUhHDPrN9DKOnvpysGIP5trCv7FiGkXq+RDP1605RA=
knative.dev/pkg v0.0.0-20220503223858-245166458ef4/go.mod h1:NXK3p/UMCbFybBM9xQGii3TuMN/WKHByXcYsTwZ6Y6U=
knative.dev/pkg v0.0.0-20220504135159-0719b405eca5/go.mod h1:mRzBIY8eoQurpADZ4+3LzNuucKOBhsSvhX6lXqMVpIc=
knative.dev/pkg v0.0.0-20220505013700-a8b7d99374a3 h1:odf5hudTbupqdYDsxeqofZtMsZuU0FqPZqWI6xETYIA=
knative.dev/pkg v0.0.0-20220505013700-a8b7d99374a3/go.mod h1:mRzBIY8eoQurpADZ4+3LzNuucKOBhsSvhX6lXqMVpIc=
knative.dev/reconciler-test v0.0.0-20220505183729-e295cedfd97b/go.mod h1:blANTpykbOpFykGxucL/8RkU8hH4WmZRWaxifP8heF4=
knative.dev/serving v0.31.1-0.20220510145433-f726b1db1b0a h1:M2wdCCJPQYWtqNT4HzRXKSyyWvgSzv1+RVMWNsIF5As=
knative.dev/serving v0.31.1-0.20220510145433-f726b1db1b0a/go.mod h1:p3hhjSBFUOGgyapoypIGLgHp9dJvdIH3ZiJz+DCtbic=
knative.dev/pkg v0.0.0-20220512013937-2d8305b2e59a/go.mod h1:mRzBIY8eoQurpADZ4+3LzNuucKOBhsSvhX6lXqMVpIc=
knative.dev/pkg v0.0.0-20220518013728-f907b31046d3 h1:NElwuc4+cGeJGwJEv65uyd552nFedHTBI4rtVZ+eDRw=
knative.dev/pkg v0.0.0-20220518013728-f907b31046d3/go.mod h1:mRzBIY8eoQurpADZ4+3LzNuucKOBhsSvhX6lXqMVpIc=
knative.dev/reconciler-test v0.0.0-20220513144654-fdb392439fb5/go.mod h1:blANTpykbOpFykGxucL/8RkU8hH4WmZRWaxifP8heF4=
knative.dev/serving v0.31.1-0.20220521001759-45f7c054f694 h1:8PcQO2Mry1d3Adz3GLt0OLZ9dQpCDV6cFrYvPOQVAr8=
knative.dev/serving v0.31.1-0.20220521001759-45f7c054f694/go.mod h1:htBTT0KiHsng8NIqF2kCKtzrS//SNZhF/Tu6TvjM8FY=
mvdan.cc/gofumpt v0.1.1/go.mod h1:yXG1r1WqZVKWbVRtBWKWX9+CxGYfA51nSomhM0woR48=
mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed/go.mod h1:Xkxe497xwlCKkIaQYRfC7CSLworTXY9RMqwhhCm+8Nc=
mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b/go.mod h1:2odslEg/xrtNQqCYg2/jCoyKnw3vv5biOc3JnIcYfL4=

View File

@ -27,7 +27,7 @@ import (
knflags "knative.dev/client/pkg/kn/flags"
servinglib "knative.dev/client/pkg/serving"
"knative.dev/client/pkg/util"
network "knative.dev/networking/pkg"
network "knative.dev/networking/pkg/apis/networking"
"knative.dev/serving/pkg/apis/autoscaling"
"knative.dev/serving/pkg/apis/serving"
servingv1 "knative.dev/serving/pkg/apis/serving/v1"

View File

@ -34,7 +34,7 @@ import (
"knative.dev/client/pkg/kn/commands"
"knative.dev/client/pkg/util"
"knative.dev/client/pkg/wait"
network "knative.dev/networking/pkg"
network "knative.dev/networking/pkg/apis/networking"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"

View File

@ -32,7 +32,7 @@ import (
servinglib "knative.dev/client/pkg/serving"
"knative.dev/client/pkg/util"
"knative.dev/client/pkg/wait"
network "knative.dev/networking/pkg"
network "knative.dev/networking/pkg/apis/networking"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"

View File

@ -27,7 +27,7 @@ import (
v1 "k8s.io/api/core/v1"
"knative.dev/client/lib/test"
"knative.dev/client/pkg/util"
network "knative.dev/networking/pkg"
network "knative.dev/networking/pkg/apis/networking"
pkgtest "knative.dev/pkg/test"
"knative.dev/serving/pkg/apis/serving"
servingv1 "knative.dev/serving/pkg/apis/serving/v1"

View File

@ -0,0 +1,133 @@
/*
Copyright 2013 Google Inc.
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.
*/
// Package lru implements an LRU cache.
package golang_lru
import "container/list"
// Cache is an LRU cache. It is not safe for concurrent access.
type Cache struct {
// MaxEntries is the maximum number of cache entries before
// an item is evicted. Zero means no limit.
MaxEntries int
// OnEvicted optionally specifies a callback function to be
// executed when an entry is purged from the cache.
OnEvicted func(key Key, value interface{})
ll *list.List
cache map[interface{}]*list.Element
}
// A Key may be any value that is comparable. See http://golang.org/ref/spec#Comparison_operators
type Key interface{}
type entry struct {
key Key
value interface{}
}
// New creates a new Cache.
// If maxEntries is zero, the cache has no limit and it's assumed
// that eviction is done by the caller.
func New(maxEntries int) *Cache {
return &Cache{
MaxEntries: maxEntries,
ll: list.New(),
cache: make(map[interface{}]*list.Element),
}
}
// Add adds a value to the cache.
func (c *Cache) Add(key Key, value interface{}) {
if c.cache == nil {
c.cache = make(map[interface{}]*list.Element)
c.ll = list.New()
}
if ee, ok := c.cache[key]; ok {
c.ll.MoveToFront(ee)
ee.Value.(*entry).value = value
return
}
ele := c.ll.PushFront(&entry{key, value})
c.cache[key] = ele
if c.MaxEntries != 0 && c.ll.Len() > c.MaxEntries {
c.RemoveOldest()
}
}
// Get looks up a key's value from the cache.
func (c *Cache) Get(key Key) (value interface{}, ok bool) {
if c.cache == nil {
return
}
if ele, hit := c.cache[key]; hit {
c.ll.MoveToFront(ele)
return ele.Value.(*entry).value, true
}
return
}
// Remove removes the provided key from the cache.
func (c *Cache) Remove(key Key) {
if c.cache == nil {
return
}
if ele, hit := c.cache[key]; hit {
c.removeElement(ele)
}
}
// RemoveOldest removes the oldest item from the cache.
func (c *Cache) RemoveOldest() {
if c.cache == nil {
return
}
ele := c.ll.Back()
if ele != nil {
c.removeElement(ele)
}
}
func (c *Cache) removeElement(e *list.Element) {
c.ll.Remove(e)
kv := e.Value.(*entry)
delete(c.cache, kv.key)
if c.OnEvicted != nil {
c.OnEvicted(kv.key, kv.value)
}
}
// Len returns the number of items in the cache.
func (c *Cache) Len() int {
if c.cache == nil {
return 0
}
return c.ll.Len()
}
// Clear purges all stored items from the cache.
func (c *Cache) Clear() {
if c.OnEvicted != nil {
for _, e := range c.cache {
kv := e.Value.(*entry)
c.OnEvicted(kv.key, kv.value)
}
}
c.ll = nil
c.cache = nil
}

79
vendor/k8s.io/utils/lru/lru.go generated vendored Normal file
View File

@ -0,0 +1,79 @@
/*
Copyright 2021 The Kubernetes Authors.
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.
*/
package lru
import (
"sync"
groupcache "k8s.io/utils/internal/third_party/forked/golang/golang-lru"
)
type Key = groupcache.Key
// Cache is a thread-safe fixed size LRU cache.
type Cache struct {
cache *groupcache.Cache
lock sync.RWMutex
}
// New creates an LRU of the given size.
func New(size int) *Cache {
return &Cache{
cache: groupcache.New(size),
}
}
// Add adds a value to the cache.
func (c *Cache) Add(key Key, value interface{}) {
c.lock.Lock()
defer c.lock.Unlock()
c.cache.Add(key, value)
}
// Get looks up a key's value from the cache.
func (c *Cache) Get(key Key) (value interface{}, ok bool) {
c.lock.Lock()
defer c.lock.Unlock()
return c.cache.Get(key)
}
// Remove removes the provided key from the cache.
func (c *Cache) Remove(key Key) {
c.lock.Lock()
defer c.lock.Unlock()
c.cache.Remove(key)
}
// RemoveOldest removes the oldest item from the cache.
func (c *Cache) RemoveOldest() {
c.lock.Lock()
defer c.lock.Unlock()
c.cache.RemoveOldest()
}
// Len returns the number of items in the cache.
func (c *Cache) Len() int {
c.lock.RLock()
defer c.lock.RUnlock()
return c.cache.Len()
}
// Clear purges all stored items from the cache.
func (c *Cache) Clear() {
c.lock.Lock()
defer c.lock.Unlock()
c.cache.Clear()
}

View File

@ -22,6 +22,9 @@ const (
// GroupName is the name for the networking API group.
GroupName = "networking.internal.knative.dev"
// CertifcateUIDLabelKey is used to specify a label selector for informers listing ingress secrets.
CertificateUIDLabelKey = GroupName + "/certificate-uid"
// IngressLabelKey is the label key attached to underlying network programming
// resources to indicate which Ingress triggered their creation.
IngressLabelKey = GroupName + "/ingress"
@ -104,6 +107,12 @@ const (
// WildcardCertDomainLabelKey is the label key attached to a certificate to indicate the
// domain for which it was issued.
WildcardCertDomainLabelKey = PublicGroupName + "/wildcardDomain"
// VisibilityLabelKey is the label to indicate visibility of Route
// and KServices. It can be an annotation too but since users are
// already using labels for domain, it probably best to keep this
// consistent.
VisibilityLabelKey = PublicGroupName + "/visibility"
)
// Pseudo-constants

View File

@ -1,11 +1,11 @@
/*
Copyright 2018 The Knative Authors
Copyright 2022 The Knative Authors
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
https://www.apache.org/licenses/LICENSE-2.0
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,
@ -14,102 +14,41 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package pkg
package config
import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"net/http"
"net/url"
"strings"
"text/template"
lru "github.com/hashicorp/golang-lru"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/lru"
cm "knative.dev/pkg/configmap"
"sigs.k8s.io/yaml"
)
var (
templateCache *lru.Cache
// Verify the default templates are valid.
_ = template.Must(template.New("domain-template").Parse(DefaultDomainTemplate))
_ = template.Must(template.New("tag-template").Parse(DefaultTagTemplate))
)
func init() {
// The only failure is due to negative size.
// Store ~10 latest templates per template type.
templateCache = lru.New(10 * 2)
}
const (
// ProbePath is the name of a path that activator, autoscaler and
// prober(used by KIngress generally) use for health check.
ProbePath = "/healthz"
// ProbeHeaderName is the name of a header that can be added to
// requests to probe the knative networking layer. Requests
// with this header will not be passed to the user container or
// included in request metrics.
ProbeHeaderName = "K-Network-Probe"
// ProxyHeaderName is the name of an internal header that activator
// uses to mark requests going through it.
ProxyHeaderName = "K-Proxy-Request"
// HashHeaderName is the name of an internal header that Ingress controller
// uses to find out which version of the networking config is deployed.
HashHeaderName = "K-Network-Hash"
// HashHeaderValue is the value that must appear in the HashHeaderName
// header in order for our network hash to be injected.
HashHeaderValue = "override"
// OriginalHostHeader is used to avoid Istio host based routing rules
// in Activator.
// The header contains the original Host value that can be rewritten
// at the Queue proxy level back to be a host header.
OriginalHostHeader = "K-Original-Host"
// ConfigName is the name of the configmap containing all
// customizations for networking features.
ConfigName = "config-network"
// DefaultIngressClassKey is the name of the configuration entry
// that specifies the default Ingress.
DefaultIngressClassKey = "ingress-class"
// DefaultCertificateClassKey is the name of the configuration entry
// that specifies the default Certificate.
DefaultCertificateClassKey = "certificate-class"
// IstioIngressClassName value for specifying knative's Istio
// Ingress reconciler.
IstioIngressClassName = "istio.ingress.networking.knative.dev"
// CertManagerCertificateClassName value for specifying Knative's Cert-Manager
// Certificate reconciler.
CertManagerCertificateClassName = "cert-manager.certificate.networking.knative.dev"
// DomainTemplateKey is the name of the configuration entry that
// specifies the golang template string to use to construct the
// Knative service's DNS name.
DomainTemplateKey = "domain-template"
// TagTemplateKey is the name of the configuration entry that
// specifies the golang template string to use to construct the
// hostname for a Route's tag.
TagTemplateKey = "tag-template"
// RolloutDurationKey is the name of the configuration entry
// that specifies the default duration of the configuration rollout.
RolloutDurationKey = "rollout-duration"
// NamespaceWildcardCertSelectorKey is the name of the configuration
// entry that specifies a LabelSelector to control which namespaces
// have a wildcard certificate provisioned for them.
NamespaceWildcardCertSelectorKey = "namespace-wildcard-cert-selector"
// KubeProbeUAPrefix is the user agent prefix of the probe.
// Since K8s 1.8, prober requests have
// User-Agent = "kube-probe/{major-version}.{minor-version}".
KubeProbeUAPrefix = "kube-probe/"
// KubeletProbeHeaderName is the name of the header supplied by kubelet
// probes. Istio with mTLS rewrites probes, but their probes pass a
// different user-agent. So we augment the probes with this header.
KubeletProbeHeaderName = "K-Kubelet-Probe"
ConfigMapName = "config-network"
// DefaultDomainTemplate is the default golang template to use when
// constructing the Knative Route's Domain(host)
@ -119,6 +58,18 @@ const (
// constructing the Knative Route's tag names.
DefaultTagTemplate = "{{.Tag}}-{{.Name}}"
// IstioIngressClassName value for specifying knative's Istio
// Ingress reconciler.
IstioIngressClassName = "istio.ingress.networking.knative.dev"
// CertManagerCertificateClassName value for specifying Knative's Cert-Manager
// Certificate reconciler.
CertManagerCertificateClassName = "cert-manager.certificate.networking.knative.dev"
)
// Config Keys
const (
// AutocreateClusterDomainClaimsKey is the key for the
// AutocreateClusterDomainClaims property.
AutocreateClusterDomainClaimsKey = "autocreate-cluster-domain-claims"
@ -127,68 +78,45 @@ const (
// that specifies enabling auto-TLS or not.
AutoTLSKey = "auto-tls"
// HTTPProtocolKey is the name of the configuration entry that
// specifies the HTTP endpoint behavior of Knative ingress.
HTTPProtocolKey = "http-protocol"
// DefaultCertificateClassKey is the name of the configuration entry
// that specifies the default Certificate.
DefaultCertificateClassKey = "certificate-class"
// UserAgentKey is the constant for header "User-Agent".
UserAgentKey = "User-Agent"
// DefaultExternalSchemeKey is the config for defining the scheme of external URLs.
DefaultExternalSchemeKey = "default-external-scheme"
// ActivatorUserAgent is the user-agent header value set in probe requests sent
// from activator.
ActivatorUserAgent = "Knative-Activator-Probe"
// DefaultIngressClassKey is the name of the configuration entry
// that specifies the default Ingress.
DefaultIngressClassKey = "ingress-class"
// QueueProxyUserAgent is the user-agent header value set in probe requests sent
// from queue-proxy.
QueueProxyUserAgent = "Knative-Queue-Proxy-Probe"
// IngressReadinessUserAgent is the user-agent header value
// set in probe requests for Ingress status.
IngressReadinessUserAgent = "Knative-Ingress-Probe"
// AutoscalingUserAgent is the user-agent header value set in probe
// requests sent by autoscaling implementations.
AutoscalingUserAgent = "Knative-Autoscaling-Probe"
// TagHeaderName is the name of the header entry which has a tag name as value.
// The tag name specifies which route was expected to be chosen by Ingress.
TagHeaderName = "Knative-Serving-Tag"
// DefaultRouteHeaderName is the name of the header entry
// identifying whether a request is routed via the default route or not.
// It has one of the string value "true" or "false".
DefaultRouteHeaderName = "Knative-Serving-Default-Route"
// ProtoAcceptContent is the content type to be used when autoscaler scrapes metrics from the QP
ProtoAcceptContent = "application/protobuf"
// FlushInterval controls the time when we flush the connection in the
// reverse proxies (Activator, QP).
// As of go1.16, a FlushInterval of 0 (the default) still flushes immediately
// when Content-Length is -1, which means the default works properly for
// streaming/websockets, without flushing more often than necessary for
// non-streaming requests.
FlushInterval = 0
// VisibilityLabelKey is the label to indicate visibility of Route
// and KServices. It can be an annotation too but since users are
// already using labels for domain, it probably best to keep this
// consistent.
VisibilityLabelKey = "networking.knative.dev/visibility"
// PassthroughLoadbalancingHeaderName is the name of the header that directs
// load balancers to not load balance the respective request but to
// send it to the request's target directly.
PassthroughLoadbalancingHeaderName = "K-Passthrough-Lb"
// DomainTemplateKey is the name of the configuration entry that
// specifies the golang template string to use to construct the
// Knative service's DNS name.
DomainTemplateKey = "domain-template"
// EnableMeshPodAddressabilityKey is the config for enabling pod addressability in mesh.
EnableMeshPodAddressabilityKey = "enable-mesh-pod-addressability"
// HTTPProtocolKey is the name of the configuration entry that
// specifies the HTTP endpoint behavior of Knative ingress.
HTTPProtocolKey = "http-protocol"
// MeshCompatibilityModeKey is the config for selecting the mesh compatibility mode.
MeshCompatibilityModeKey = "mesh-compatibility-mode"
// DefaultExternalSchemeKey is the config for defining the scheme of external URLs.
DefaultExternalSchemeKey = "default-external-scheme"
// NamespaceWildcardCertSelectorKey is the name of the configuration
// entry that specifies a LabelSelector to control which namespaces
// have a wildcard certificate provisioned for them.
NamespaceWildcardCertSelectorKey = "namespace-wildcard-cert-selector"
// RolloutDurationKey is the name of the configuration entry
// that specifies the default duration of the configuration rollout.
RolloutDurationKey = "rollout-duration"
// TagTemplateKey is the name of the configuration entry that
// specifies the golang template string to use to construct the
// hostname for a Route's tag.
TagTemplateKey = "tag-template"
// ActivatorCAKey is the config for the secret name, which stores CA public certificate used
// to sign the activator TLS certificate.
@ -213,6 +141,47 @@ const (
QueueProxyCertKey = "queue-proxy-cert-secret"
)
// HTTPProtocol indicates a type of HTTP endpoint behavior
// that Knative ingress could take.
type HTTPProtocol string
const (
// HTTPEnabled represents HTTP protocol is enabled in Knative ingress.
HTTPEnabled HTTPProtocol = "enabled"
// HTTPDisabled represents HTTP protocol is disabled in Knative ingress.
HTTPDisabled HTTPProtocol = "disabled"
// HTTPRedirected represents HTTP connection is redirected to HTTPS in Knative ingress.
HTTPRedirected HTTPProtocol = "redirected"
)
// MeshCompatibilityMode is one of enabled (always use ClusterIP), disabled
// (always use Pod IP), or auto (try PodIP, and fall back to ClusterIP if mesh
// is detected).
type MeshCompatibilityMode string
const (
// MeshCompatibilityModeEnabled instructs consumers of network plugins, such as
// Knative Serving, to use ClusterIP when connecting to pods. This is
// required when mesh is enabled (unless EnableMeshPodAddressability is set),
// but is less efficient.
MeshCompatibilityModeEnabled MeshCompatibilityMode = "enabled"
// MeshCompatibilityModeDisabled instructs consumers of network plugins, such as
// Knative Serving, to connect to individual Pod IPs. This is most efficient,
// but will only work with mesh enabled when EnableMeshPodAddressability is
// used.
MeshCompatibilityModeDisabled MeshCompatibilityMode = "disabled"
// MeshCompatibilityModeAuto instructs consumers of network plugins, such as
// Knative Serving, to heuristically determine whether to connect using the
// Cluster IP, or to ocnnect to individual Pod IPs. This is most efficient,
// determine whether mesh is enabled, and fall back from Direct Pod IP
// communication to Cluster IP as needed.
MeshCompatibilityModeAuto MeshCompatibilityMode = "auto"
)
// DomainTemplateValues are the available properties people can choose from
// in their Route's "DomainTemplate" golang template sting.
// We could add more over time - e.g. RevisionName if we thought that
@ -232,20 +201,6 @@ type TagTemplateValues struct {
Tag string
}
var (
templateCache *lru.Cache
// Verify the default templates are valid.
_ = template.Must(template.New("domain-template").Parse(DefaultDomainTemplate))
_ = template.Must(template.New("tag-template").Parse(DefaultTagTemplate))
)
func init() {
// The only failure is due to negative size.
// Store ~10 latest templates per template type.
templateCache, _ = lru.New(10 * 2)
}
// Config contains the networking configuration defined in the
// network config map.
type Config struct {
@ -333,47 +288,6 @@ type Config struct {
QueueProxyCertSecret string
}
// HTTPProtocol indicates a type of HTTP endpoint behavior
// that Knative ingress could take.
type HTTPProtocol string
const (
// HTTPEnabled represents HTTP protocol is enabled in Knative ingress.
HTTPEnabled HTTPProtocol = "enabled"
// HTTPDisabled represents HTTP protocol is disabled in Knative ingress.
HTTPDisabled HTTPProtocol = "disabled"
// HTTPRedirected represents HTTP connection is redirected to HTTPS in Knative ingress.
HTTPRedirected HTTPProtocol = "redirected"
)
// MeshCompatibilityMode is one of enabled (always use ClusterIP), disabled
// (always use Pod IP), or auto (try PodIP, and fall back to ClusterIP if mesh
// is detected).
type MeshCompatibilityMode string
const (
// MeshCompatibilityModeEnabled instructs consumers of network plugins, such as
// Knative Serving, to use ClusterIP when connecting to pods. This is
// required when mesh is enabled (unless EnableMeshPodAddressability is set),
// but is less efficient.
MeshCompatibilityModeEnabled MeshCompatibilityMode = "enabled"
// MeshCompatibilityModeDisabled instructs consumers of network plugins, such as
// Knative Serving, to connect to individual Pod IPs. This is most efficient,
// but will only work with mesh enabled when EnableMeshPodAddressability is
// used.
MeshCompatibilityModeDisabled MeshCompatibilityMode = "disabled"
// MeshCompatibilityModeAuto instructs consumers of network plugins, such as
// Knative Serving, to heuristically determine whether to connect using the
// Cluster IP, or to ocnnect to individual Pod IPs. This is most efficient,
// determine whether mesh is enabled, and fall back from Direct Pod IP
// communication to Cluster IP as needed.
MeshCompatibilityModeAuto MeshCompatibilityMode = "auto"
)
func defaultConfig() *Config {
return &Config{
DefaultIngressClass: IstioIngressClassName,
@ -395,11 +309,6 @@ func defaultConfig() *Config {
}
}
// NewConfigFromConfigMap creates a Config from the supplied ConfigMap
func NewConfigFromConfigMap(configMap *corev1.ConfigMap) (*Config, error) {
return NewConfigFromMap(configMap.Data)
}
// NewConfigFromMap creates a Config from the supplied data.
func NewConfigFromMap(data map[string]string) (*Config, error) {
nc := defaultConfig()
@ -571,82 +480,20 @@ func checkTagTemplate(t *template.Template) error {
return t.Execute(ioutil.Discard, data)
}
// IsKubeletProbe returns true if the request is a Kubernetes probe.
func IsKubeletProbe(r *http.Request) bool {
return strings.HasPrefix(r.Header.Get("User-Agent"), KubeProbeUAPrefix) ||
r.Header.Get(KubeletProbeHeaderName) != ""
}
// KnativeProbeHeader returns the value for key ProbeHeaderName in request headers.
func KnativeProbeHeader(r *http.Request) string {
return r.Header.Get(ProbeHeaderName)
}
// KnativeProxyHeader returns the value for key ProxyHeaderName in request headers.
func KnativeProxyHeader(r *http.Request) string {
return r.Header.Get(ProxyHeaderName)
}
// IsProbe returns true if the request is a Kubernetes probe or a Knative probe,
// i.e. non-empty ProbeHeaderName header.
func IsProbe(r *http.Request) bool {
return IsKubeletProbe(r) || KnativeProbeHeader(r) != ""
}
// RewriteHostIn removes the `Host` header from the inbound (server) request
// and replaces it with our custom header.
// This is done to avoid Istio Host based routing, see #3870.
// Queue-Proxy will execute the reverse process.
func RewriteHostIn(r *http.Request) {
h := r.Host
r.Host = ""
r.Header.Del("Host")
// Don't overwrite an existing OriginalHostHeader.
if r.Header.Get(OriginalHostHeader) == "" {
r.Header.Set(OriginalHostHeader, h)
}
}
// RewriteHostOut undoes the `RewriteHostIn` action.
// RewriteHostOut checks if network.OriginalHostHeader was set and if it was,
// then uses that as the r.Host (which takes priority over Request.Header["Host"]).
// If the request did not have the OriginalHostHeader header set, the request is untouched.
func RewriteHostOut(r *http.Request) {
if ohh := r.Header.Get(OriginalHostHeader); ohh != "" {
r.Host = ohh
r.Header.Del("Host")
r.Header.Del(OriginalHostHeader)
}
}
// NameForPortNumber finds the name for a given port as defined by a Service.
func NameForPortNumber(svc *corev1.Service, portNumber int32) (string, error) {
for _, port := range svc.Spec.Ports {
if port.Port == portNumber {
return port.Name, nil
// asLabelSelector returns a LabelSelector extracted from a given configmap key.
func asLabelSelector(key string, target **metav1.LabelSelector) cm.ParseFunc {
return func(data map[string]string) error {
if raw, ok := data[key]; ok {
if len(raw) > 0 {
var selector *metav1.LabelSelector
if err := yaml.Unmarshal([]byte(raw), &selector); err != nil {
return err
}
*target = selector
}
}
return nil
}
return "", fmt.Errorf("no port with number %d found", portNumber)
}
// PortNumberForName resolves a given name to a portNumber as defined by an EndpointSubset.
func PortNumberForName(sub corev1.EndpointSubset, portName string) (int32, error) {
for _, subPort := range sub.Ports {
if subPort.Name == portName {
return subPort.Port, nil
}
}
return 0, fmt.Errorf("no port for name %q found", portName)
}
// IsPotentialMeshErrorResponse returns whether the HTTP response is compatible
// with having been caused by attempting direct connection when mesh was
// enabled. For example if we get a HTTP 404 status code it's safe to assume
// mesh is not enabled even if a probe was otherwise unsuccessful. This is
// useful to avoid falling back to ClusterIP when we see errors which are
// unrelated to mesh being enabled.
func IsPotentialMeshErrorResponse(resp *http.Response) bool {
return resp.StatusCode == http.StatusServiceUnavailable || resp.StatusCode == http.StatusBadGateway
}
// asMode parses the value at key as a MeshCompatibilityMode into the target, if it exists.
@ -663,19 +510,3 @@ func asMode(key string, target *MeshCompatibilityMode) cm.ParseFunc {
return nil
}
}
// asLabelSelector returns a LabelSelector extracted from a given configmap key.
func asLabelSelector(key string, target **metav1.LabelSelector) cm.ParseFunc {
return func(data map[string]string) error {
if raw, ok := data[key]; ok {
if len(raw) > 0 {
var selector *metav1.LabelSelector
if err := yaml.Unmarshal([]byte(raw), &selector); err != nil {
return err
}
*target = selector
}
}
return nil
}
}

View File

@ -1,5 +1,5 @@
/*
Copyright 2018 The Knative Authors
Copyright 2022 The Knative Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@ -17,4 +17,4 @@ limitations under the License.
// +k8s:deepcopy-gen=package
// Package network holds the typed objects that define the schemas for
// configuring the knative/serving networking layer.
package pkg
package config

View File

@ -19,7 +19,7 @@ limitations under the License.
// Code generated by deepcopy-gen. DO NOT EDIT.
package pkg
package config
import (
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"

View File

@ -0,0 +1,247 @@
/*
Copyright 2022 The Knative Authors
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.
*/
package pkg
import (
corev1 "k8s.io/api/core/v1"
"knative.dev/networking/pkg/config"
)
const (
// ConfigName is the name of the configmap containing all
// customizations for networking features.
//
// Deprecated: use knative.dev/networking/pkg/config.ConfigMapName
ConfigName = config.ConfigMapName
// DefaultDomainTemplate is the default golang template to use when
// constructing the Knative Route's Domain(host)
//
// Deprecated: use knative.dev/networking/pkg/config.DefaultDomainTemplate
DefaultDomainTemplate = config.DefaultDomainTemplate
// DefaultTagTemplate is the default golang template to use when
// constructing the Knative Route's tag names.
//
// Deprecated: use knative.dev/networking/pkg/config.DefaultTagTemplate
DefaultTagTemplate = config.DefaultTagTemplate
// DefaultIngressClassKey is the name of the configuration entry
// that specifies the default Ingress.
//
// Deprecated: use knative.dev/networking/pkg/config.DefaultIngressClassKey
DefaultIngressClassKey = config.DefaultIngressClassKey
// DefaultCertificateClassKey is the name of the configuration entry
// that specifies the default Certificate.
//
// Deprecated: use knative.dev/networking/pkg/config.DefaultCertificateClassKey
DefaultCertificateClassKey = config.DefaultCertificateClassKey
// IstioIngressClassName value for specifying knative's Istio
// Ingress reconciler.
//
// Deprecated: use knative.dev/networking/pkg/config.IstioIngressClassName
IstioIngressClassName = config.IstioIngressClassName
// CertManagerCertificateClassName value for specifying Knative's Cert-Manager
// Certificate reconciler.
//
// Deprecated: use knative.dev/networking/pkg/config.CertManagerCertificateClassName
CertManagerCertificateClassName = config.CertManagerCertificateClassName
// DomainTemplateKey is the name of the configuration entry that
// specifies the golang template string to use to construct the
// Knative service's DNS name.
//
// Deprecated: use knative.dev/networking/pkg/config.DomainTemplateKey
DomainTemplateKey = config.DomainTemplateKey
// TagTemplateKey is the name of the configuration entry that
// specifies the golang template string to use to construct the
// hostname for a Route's tag.
//
// Deprecated: use knative.dev/networking/pkg/config.TagTemplateKey
TagTemplateKey = config.TagTemplateKey
// RolloutDurationKey is the name of the configuration entry
// that specifies the default duration of the configuration rollout.
//
// Deprecated: use knative.dev/networking/pkg/config.RolloutDurationKey
RolloutDurationKey = config.RolloutDurationKey
// NamespaceWildcardCertSelectorKey is the name of the configuration
// entry that specifies a LabelSelector to control which namespaces
// have a wildcard certificate provisioned for them.
//
// Deprecated: use knative.dev/networking/pkg/config.NamespaceWildcardCertSelectorKey
NamespaceWildcardCertSelectorKey = config.NamespaceWildcardCertSelectorKey
// AutocreateClusterDomainClaimsKey is the key for the
// AutocreateClusterDomainClaims property.
//
// Deprecated: use knative.dev/networking/pkg/config.AutocreateClusterDomainClaimsKey
AutocreateClusterDomainClaimsKey = config.AutocreateClusterDomainClaimsKey
// AutoTLSKey is the name of the configuration entry
// that specifies enabling auto-TLS or not.
//
// Deprecated: use knative.dev/networking/pkg/config.AutoTLSKey
AutoTLSKey = config.AutoTLSKey
// HTTPProtocolKey is the name of the configuration entry that
// specifies the HTTP endpoint behavior of Knative ingress.
//
// Deprecated: use knative.dev/networking/pkg/config.HTTPProtocolKey
HTTPProtocolKey = config.HTTPProtocolKey
// EnableMeshPodAddressabilityKey is the config for enabling pod addressability in mesh.
//
// Deprecated: use knative.dev/networking/pkg/config.EnableMeshPodAddressabilityKey
EnableMeshPodAddressabilityKey = config.EnableMeshPodAddressabilityKey
// MeshCompatibilityModeKey is the config for selecting the mesh compatibility mode.
//
// Deprecated: use knative.dev/networking/pkg/config.MeshCompatibilityModeKey
MeshCompatibilityModeKey = config.MeshCompatibilityModeKey
// DefaultExternalSchemeKey is the config for defining the scheme of external URLs.
//
// Deprecated: use knative.dev/networking/pkg/config.DefaultExternalSchemeKey
DefaultExternalSchemeKey = config.DefaultExternalSchemeKey
// ActivatorCAKey is the config for the secret name, which stores CA public certificate used
// to sign the activator TLS certificate.
//
// Deprecated: use knative.dev/networking/pkg/config.ActivatorCAKey
ActivatorCAKey = config.ActivatorCAKey
// ActivatorSANKey is the config for the SAN used to validate the activator TLS certificate.
//
// Deprecated: use knative.dev/networking/pkg/config.ActivatorSANKey
ActivatorSANKey = config.ActivatorSANKey
// ActivatorCertKey is the config for the secret name, which stores certificates
// to serve the TLS traffic from ingress to activator.
//
// Deprecated: use knative.dev/networking/pkg/config.ActivatorCertKey
ActivatorCertKey = config.ActivatorCertKey
// QueueProxyCAKey is the config for the secret name, which stores CA public certificate used
// to sign the queue-proxy TLS certificate.
//
// Deprecated: use knative.dev/networking/pkg/config.QueueProxyCAKey
QueueProxyCAKey = config.QueueProxyCAKey
// QueueProxySANKey is the config for the SAN used to validate the queue-proxy TLS certificate.
//
// Deprecated: use knative.dev/networking/pkg/config.QueueProxySANKey
QueueProxySANKey = config.QueueProxySANKey
// QueueProxyCertKey is the config for the secret name, which stores certificates
// to serve the TLS traffic from activator to queue-proxy.
//
// Deprecated: use knative.dev/networking/pkg/config.QueueProxyCertKey
QueueProxyCertKey = config.QueueProxyCertKey
)
// DomainTemplateValues are the available properties people can choose from
// in their Route's "DomainTemplate" golang template sting.
// We could add more over time - e.g. RevisionName if we thought that
// might be of interest to people.
//
// Deprecated: use knative.dev/networking/pkg/config.DomainTemplateValues
type DomainTemplateValues = config.DomainTemplateValues
// TagTemplateValues are the available properties people can choose from
// in their Route's "TagTemplate" golang template sting.
//
// Deprecated: use knative.dev/networking/pkg/config.TagTemplateValues
type TagTemplateValues = config.TagTemplateValues
// Config contains the networking configuration defined in the
// network config map.
//
// Deprecated: use knative.dev/networking/pkg/config.Config
type Config = config.Config
// HTTPProtocol indicates a type of HTTP endpoint behavior
// that Knative ingress could take.
//
// Deprecated: use knative.dev/networking/pkg/config.HTTPProtocol
type HTTPProtocol = config.HTTPProtocol
const (
// HTTPEnabled represents HTTP protocol is enabled in Knative ingress.
//
// Deprecated: use knative.dev/networking/pkg/config.HTTPEnabled
HTTPEnabled HTTPProtocol = config.HTTPEnabled
// HTTPDisabled represents HTTP protocol is disabled in Knative ingress.
//
// Deprecated: use knative.dev/networking/pkg/config.HTTPDisabled
HTTPDisabled HTTPProtocol = config.HTTPDisabled
// HTTPRedirected represents HTTP connection is redirected to HTTPS in Knative ingress.
//
// Deprecated: use knative.dev/networking/pkg/config.HTTPRedirected
HTTPRedirected HTTPProtocol = config.HTTPRedirected
)
// MeshCompatibilityMode is one of enabled (always use ClusterIP), disabled
// (always use Pod IP), or auto (try PodIP, and fall back to ClusterIP if mesh
// is detected).
//
// Deprecated: use knative.dev/networking/pkg/config.MeshCompatibilityMode
type MeshCompatibilityMode = config.MeshCompatibilityMode
const (
// MeshCompatibilityModeEnabled instructs consumers of network plugins, such as
// Knative Serving, to use ClusterIP when connecting to pods. This is
// required when mesh is enabled (unless EnableMeshPodAddressability is set),
// but is less efficient.
//
// Deprecated: Use knative.dev/networking/pkg/config/MeshCompatibilityModeEnabled
MeshCompatibilityModeEnabled MeshCompatibilityMode = config.MeshCompatibilityModeEnabled
// MeshCompatibilityModeDisabled instructs consumers of network plugins, such as
// Knative Serving, to connect to individual Pod IPs. This is most efficient,
// but will only work with mesh enabled when EnableMeshPodAddressability is
// used.
//
// Deprecated: Use knative.dev/networking/pkg/config/MeshCompatibilityModeDisabled
MeshCompatibilityModeDisabled MeshCompatibilityMode = config.MeshCompatibilityModeDisabled
// MeshCompatibilityModeAuto instructs consumers of network plugins, such as
// Knative Serving, to heuristically determine whether to connect using the
// Cluster IP, or to ocnnect to individual Pod IPs. This is most efficient,
// determine whether mesh is enabled, and fall back from Direct Pod IP
// communication to Cluster IP as needed.
//
// Deprecated: Use knative.dev/networking/pkg/config/MeshCompatibilityModeAuto
MeshCompatibilityModeAuto MeshCompatibilityMode = config.MeshCompatibilityModeAuto
)
// NewConfigFromConfigMap creates a Config from the supplied ConfigMap
func NewConfigFromConfigMap(configMap *corev1.ConfigMap) (*Config, error) {
return NewConfigFromMap(configMap.Data)
}
// NewConfigFromMap creates a Config from the supplied data.
//
// Deprecated: Use knative.dev/networking/pkg/config/NewConfigFromMap
var NewConfigFromMap = config.NewConfigFromMap

View File

@ -0,0 +1,167 @@
/*
Copyright 2022 The Knative Authors
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.
*/
package pkg
import (
"knative.dev/networking/pkg/http/header"
)
const (
// ProbeHeaderName is the name of a header that can be added to
// requests to probe the knative networking layer. Requests
// with this header will not be passed to the user container or
// included in request metrics.
//
// Deprecated: use knative.dev/networking/pkg/http/header.ProbeKey
ProbeHeaderName = header.ProbeKey
// ProxyHeaderName is the name of an internal header that activator
// uses to mark requests going through it.
//
// Deprecated: use knative.dev/networking/pkg/http/header.ProxyKey
ProxyHeaderName = header.ProxyKey
// HashHeaderName is the name of an internal header that Ingress controller
// uses to find out which version of the networking config is deployed.
//
// Deprecated: use knative.dev/networking/pkg/http/header.HashKey
HashHeaderName = header.HashKey
// HashHeaderValue is the value that must appear in the HashHeaderName
// header in order for our network hash to be injected.
//
// Deprecated: use knative.dev/networking/pkg/http/header.HashValueOverride
HashHeaderValue = header.HashValueOverride
// OriginalHostHeader is used to avoid Istio host based routing rules
// in Activator.
// The header contains the original Host value that can be rewritten
// at the Queue proxy level back to be a host header.
//
// Deprecated: use knative.dev/networking/pkg/http/header.OriginalHostKey
OriginalHostHeader = header.OriginalHostKey
// KubeProbeUAPrefix is the user agent prefix of the probe.
// Since K8s 1.8, prober requests have
// User-Agent = "kube-probe/{major-version}.{minor-version}".
//
// Deprecated: use knative.dev/networking/pkg/http/header.KubeProbeUAPrefix
KubeProbeUAPrefix = header.KubeProbeUAPrefix
// KubeletProbeHeaderName is the name of the header supplied by kubelet
// probes. Istio with mTLS rewrites probes, but their probes pass a
// different user-agent. So we augment the probes with this header.
//
// Deprecated: use knative.dev/networking/pkg/http/header.KubeletProbeKey
KubeletProbeHeaderName = header.KubeletProbeKey
// UserAgentKey is the constant for header "User-Agent".
//
// Deprecated: use knative.dev/networking/pkg/http/header.UserAgentKey
UserAgentKey = header.UserAgentKey
// ActivatorUserAgent is the user-agent header value set in probe requests sent
// from activator.
//
// Deprecated: use knative.dev/networking/pkg/http/header.ActivatorUserAgent
ActivatorUserAgent = header.ActivatorUserAgent
// QueueProxyUserAgent is the user-agent header value set in probe requests sent
// from queue-proxy.
//
// Deprecated: use knative.dev/networking/pkg/http/header.QueueProxyUserAgent
QueueProxyUserAgent = header.QueueProxyUserAgent
// IngressReadinessUserAgent is the user-agent header value
// set in probe requests for Ingress status.
//
// Deprecated: use knative.dev/networking/pkg/http/header.IngressReadinessUserAgent
IngressReadinessUserAgent = header.IngressReadinessUserAgent
// AutoscalingUserAgent is the user-agent header value set in probe
// requests sent by autoscaling implementations.
//
// Deprecated: use knative.dev/networking/pkg/http/header.AutoscalingUserAgent
AutoscalingUserAgent = header.AutoscalingUserAgent
// TagHeaderName is the name of the header entry which has a tag name as value.
// The tag name specifies which route was expected to be chosen by Ingress.
//
// Deprecated: use knative.dev/networking/pkg/http/header.RouteTagKey
TagHeaderName = header.RouteTagKey
// DefaultRouteHeaderName is the name of the header entry
// identifying whether a request is routed via the default route or not.
// It has one of the string value "true" or "false".
//
// Deprecated: use knative.dev/networking/pkg/http/header.DefaultRouteKey
DefaultRouteHeaderName = header.DefaultRouteKey
// PassthroughLoadbalancingHeaderName is the name of the header that directs
// load balancers to not load balance the respective request but to
// send it to the request's target directly.
//
// Deprecated: use knative.dev/networking/pkg/http/header.PassthroughLoadbalancingKey
PassthroughLoadbalancingHeaderName = header.PassthroughLoadbalancingKey
// ProtoAcceptContent is the content type to be used when autoscaler scrapes metrics from the QP
//
// Deprecated: use knative.dev/networking/pkg/http/header.ProtobufMIMEType
ProtoAcceptContent = header.ProtobufMIMEType
// ProbeHeaderValue is the value used in 'K-Network-Probe'
//
// Deprecated: use knative.dev/networking/pkg/http/header.ProbeValue
ProbeHeaderValue = header.ProbeValue
)
// IsKubeletProbe returns true if the request is a Kubernetes probe.
//
// Deprecated: use knative.dev/networking/pkg/http/header.IsKubeletProbe
var IsKubeletProbe = header.IsKubeletProbe
// KnativeProbeHeader returns the value for key ProbeHeaderName in request headers.
//
// Deprecated: use knative.dev/networking/pkg/http/header.GetKnativeProbeValue
var KnativeProbeHeader = header.GetKnativeProbeValue
// KnativeProxyHeader returns the value for key ProxyHeaderName in request headers.
//
// Deprecated: use knative.dev/networking/pkg/http/header.GetKnativeProxyValue
var KnativeProxyHeader = header.GetKnativeProxyValue
// IsProbe returns true if the request is a Kubernetes probe or a Knative probe,
// i.e. non-empty ProbeHeaderName header.
//
// Deprecated: use knative.dev/networking/pkg/http/header.IsProbe
var IsProbe = header.IsProbe
// RewriteHostIn removes the `Host` header from the inbound (server) request
// and replaces it with our custom header.
// This is done to avoid Istio Host based routing, see #3870.
// Queue-Proxy will execute the reverse process.
//
// Deprecated: use knative.dev/networking/pkg/http/header.RewriteHostIn
var RewriteHostIn = header.RewriteHostIn
// RewriteHostOut undoes the `RewriteHostIn` action.
// RewriteHostOut checks if network.OriginalHostHeader was set and if it was,
// then uses that as the r.Host (which takes priority over Request.Header["Host"]).
// If the request did not have the OriginalHostHeader header set, the request is untouched.
//
// Deprecated: use knative.dev/networking/pkg/http/header.RewriteHostOut
var RewriteHostOut = header.RewriteHostOut

View File

@ -0,0 +1,116 @@
/*
Copyright 2018 The Knative Authors
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.
*/
package pkg
import (
"knative.dev/networking/pkg/http"
"knative.dev/networking/pkg/http/probe"
"knative.dev/networking/pkg/http/proxy"
"knative.dev/networking/pkg/http/stats"
)
const (
// ProbePath is the name of a path that activator, autoscaler and
// prober(used by KIngress generally) use for health check.
//
// Deprecated: use knative.dev/networking/pkg/http.HealthCheckPath
ProbePath = http.HealthCheckPath
// FlushInterval controls the time when we flush the connection in the
// reverse proxies (Activator, QP).
// As of go1.16, a FlushInterval of 0 (the default) still flushes immediately
// when Content-Length is -1, which means the default works properly for
// streaming/websockets, without flushing more often than necessary for
// non-streaming requests.
//
// Deprecated: use knative.dev/networking/pkg/http/proxy.FlushInterval
FlushInterval = proxy.FlushInterval
)
type (
// ReqEvent represents either an incoming or closed request.
//
// Deprecated: use knative.dev/networking/pkg/http/stats.ReqEvent
ReqEvent = stats.ReqEvent
// ReqEventType denotes the type (incoming/closed) of a ReqEvent.
//
// Deprecated: use knative.dev/networking/pkg/http/stats.ReqEventType
ReqEventType = stats.ReqEventType
// RequestStats collects statistics about requests as they flow in and out of the system.
//
// Deprecated: use knative.dev/networking/pkg/http/stats.RequestStats
RequestStats = stats.RequestStats
// RequestStatsReport are the metrics reported from the the request stats collector
// at a given time.
//
// Deprecated: use knative.dev/networking/pkg/http/stats.RequestStatsReport
RequestStatsReport = stats.RequestStatsReport
)
const (
// ReqIn represents an incoming request
//
// Deprecated: use knative.dev/networking/pkg/http/stats.ReqIn
ReqIn = stats.ReqIn
// ReqOut represents a finished request
//
// Deprecated: use knative.dev/networking/pkg/http/stats.ReqOut
ReqOut = stats.ReqOut
// ProxiedIn represents an incoming request through a proxy.
//
// Deprecated: use knative.dev/networking/pkg/http/stats.ProxiedIn
ProxiedIn = stats.ProxiedIn
// ProxiedOut represents a finished proxied request.
//
// Deprecated: use knative.dev/networking/pkg/http/stats.ProxiedOut
ProxiedOut = stats.ProxiedOut
)
var (
// NewRequestStats builds a RequestStats instance, started at the given time.
//
// Deprecated: use knative.dev/networking/pkg/http/stats.NewRequestStats
NewRequestStats = stats.NewRequestStats
// NewBufferPool creates a new BufferPool. This is only safe to use in the context
// of a httputil.ReverseProxy, as the buffers returned via Put are not cleaned
// explicitly.
//
// Deprecated: use knative.dev/networking/pkg/http/proxy.NewBufferPool
NewBufferPool = proxy.NewBufferPool
// NewProbeHandler wraps a HTTP handler handling probing requests around the provided HTTP handler
//
// Deprecated: use knative.dev/networking/pkg/http/probe.NewHandler
NewProbeHandler = probe.NewHandler
// IsPotentialMeshErrorResponse returns whether the HTTP response is compatible
// with having been caused by attempting direct connection when mesh was
// enabled. For example if we get a HTTP 404 status code it's safe to assume
// mesh is not enabled even if a probe was otherwise unsuccessful. This is
// useful to avoid falling back to ClusterIP when we see errors which are
// unrelated to mesh being enabled.
//
// Deprecated: use knative.dev/networking/pkg/http.IsPotentialMeshErrorResponse
IsPotentialMeshErrorResponse = http.IsPotentialMeshErrorResponse
)

View File

@ -0,0 +1,29 @@
/*
Copyright 2022 The Knative Authors
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.
*/
package pkg
import "knative.dev/networking/pkg/apis/networking"
const (
// VisibilityLabelKey is the label to indicate visibility of Route
// and KServices. It can be an annotation too but since users are
// already using labels for domain, it probably best to keep this
// consistent.
//
// Deprecated: use knative.dev/networking/pkg/apis/networking.VisibilityLabelKey
VisibilityLabelKey = networking.VisibilityLabelKey
)

View File

@ -0,0 +1,29 @@
/*
Copyright 2022 The Knative Authors
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.
*/
package pkg
import "knative.dev/networking/pkg/k8s"
// NameForPortNumber finds the name for a given port as defined by a Service.
//
// Deprecated: use knative.dev/networking/pkg/k8s.NameForPortNumber
var NameForPortNumber = k8s.NameForPortNumber
// PortNumberForName resolves a given name to a portNumber as defined by an EndpointSubset.
//
// Deprecated: use knative.dev/networking/pkg/k8s.PortNumberForName
var PortNumberForName = k8s.PortNumberForName

View File

@ -0,0 +1,23 @@
/*
Copyright 2022 The Knative Authors
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.
*/
package http
const (
// HealthCheckPath is the name of a path that activator, autoscaler and
// prober(used by KIngress generally) use for health check.
HealthCheckPath = "/healthz"
)

View File

@ -0,0 +1,29 @@
/*
Copyright 2022 The Knative Authors
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.
*/
package http
import "net/http"
// IsPotentialMeshErrorResponse returns whether the HTTP response is compatible
// with having been caused by attempting direct connection when mesh was
// enabled. For example if we get a HTTP 404 status code it's safe to assume
// mesh is not enabled even if a probe was otherwise unsuccessful. This is
// useful to avoid falling back to ClusterIP when we see errors which are
// unrelated to mesh being enabled.
func IsPotentialMeshErrorResponse(resp *http.Response) bool {
return resp.StatusCode == http.StatusServiceUnavailable || resp.StatusCode == http.StatusBadGateway
}

View File

@ -0,0 +1,157 @@
/*
Copyright 2022 The Knative Authors
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.
*/
package header
import (
"net/http"
"strings"
)
// HashKey & Values
const (
// HashKey is the name of an internal header that Ingress controller
// uses to find out which version of the networking config is deployed.
HashKey = "K-Network-Hash"
// HashValueOverride is the value that must appear in the HashHeaderKey
// header in order for our network hash to be injected.
HashValueOverride = "override"
)
// ProbeKey & Values
const (
// ProbeKey is the name of a header that can be added to
// requests to probe the knative networking layer. Requests
// with this header will not be passed to the user container or
// included in request metrics.
ProbeKey = "K-Network-Probe"
// ProbeValue is the value used in 'K-Network-Probe'
ProbeValue = "probe"
)
const (
// ProxyKey is the name of an internal header that activator
// uses to mark requests going through it.
ProxyKey = "K-Proxy-Request"
// OriginalHostKey is used to avoid Istio host based routing rules
// in Activator.
// The header contains the original Host value that can be rewritten
// at the Queue proxy level back to be a host header.
OriginalHostKey = "K-Original-Host"
// KubeletProbeKey is the name of the header supplied by kubelet
// probes. Istio with mTLS rewrites probes, but their probes pass a
// different user-agent. So we augment the probes with this header.
KubeletProbeKey = "K-Kubelet-Probe"
// RouteTagKey is the name of the header entry which has a tag name as value.
// The tag name specifies which route was expected to be chosen by Ingress.
RouteTagKey = "Knative-Serving-Tag"
// DefaultRouteKey is the name of the header entry
// identifying whether a request is routed via the default route or not.
// It has one of the string value "true" or "false".
DefaultRouteKey = "Knative-Serving-Default-Route"
// PassthroughLoadbalancingKey is the name of the header that directs
// load balancers to not load balance the respective request but to
// send it to the request's target directly.
PassthroughLoadbalancingKey = "K-Passthrough-Lb"
)
// User Agent Key & Values
const (
// UserAgentKey is the constant for header "User-Agent".
UserAgentKey = "User-Agent"
// KubeProbeUAPrefix is the user agent prefix of the probe.
// Since K8s 1.8, prober requests have
// User-Agent = "kube-probe/{major-version}.{minor-version}".
KubeProbeUAPrefix = "kube-probe/"
// ActivatorUserAgent is the user-agent header value set in probe requests sent
// from activator.
ActivatorUserAgent = "Knative-Activator-Probe"
// QueueProxyUserAgent is the user-agent header value set in probe requests sent
// from queue-proxy.
QueueProxyUserAgent = "Knative-Queue-Proxy-Probe"
// IngressReadinessUserAgent is the user-agent header value
// set in probe requests for Ingress status.
IngressReadinessUserAgent = "Knative-Ingress-Probe"
// AutoscalingUserAgent is the user-agent header value set in probe
// requests sent by autoscaling implementations.
AutoscalingUserAgent = "Knative-Autoscaling-Probe"
)
// Accept Content Values
const (
// ProtobufMIMEType is a content type to be used when autoscaler scrapes metrics from the QP
ProtobufMIMEType = "application/protobuf"
)
// KnativeProbeHeader returns the value for key ProbeHeaderName in request headers.
func GetKnativeProbeValue(r *http.Request) string {
return r.Header.Get(ProbeKey)
}
// KnativeProxyHeader returns the value for key ProxyHeaderName in request headers.
func GetKnativeProxyValue(r *http.Request) string {
return r.Header.Get(ProxyKey)
}
// IsProbe returns true if the request is a Kubernetes probe or a Knative probe,
// i.e. non-empty ProbeHeaderName header.
func IsProbe(r *http.Request) bool {
return IsKubeletProbe(r) || GetKnativeProbeValue(r) != ""
}
// IsKubeletProbe returns true if the request is a Kubernetes probe.
func IsKubeletProbe(r *http.Request) bool {
return strings.HasPrefix(r.Header.Get("User-Agent"), KubeProbeUAPrefix) ||
r.Header.Get(KubeletProbeKey) != ""
}
// RewriteHostIn removes the `Host` header from the inbound (server) request
// and replaces it with our custom header.
// This is done to avoid Istio Host based routing, see #3870.
// Queue-Proxy will execute the reverse process.
func RewriteHostIn(r *http.Request) {
h := r.Host
r.Host = ""
r.Header.Del("Host")
// Don't overwrite an existing OriginalHostHeader.
if r.Header.Get(OriginalHostKey) == "" {
r.Header.Set(OriginalHostKey, h)
}
}
// RewriteHostOut undoes the `RewriteHostIn` action.
// RewriteHostOut checks if network.OriginalHostHeader was set and if it was,
// then uses that as the r.Host (which takes priority over Request.Header["Host"]).
// If the request did not have the OriginalHostHeader header set, the request is untouched.
func RewriteHostOut(r *http.Request) {
if ohh := r.Header.Get(OriginalHostKey); ohh != "" {
r.Host = ohh
r.Header.Del("Host")
r.Header.Del(OriginalHostKey)
}
}

View File

@ -1,5 +1,5 @@
/*
Copyright 2019 The Knative Authors
Copyright 2022 The Knative Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@ -14,39 +14,38 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package pkg
package probe
import (
"fmt"
"net/http"
)
// ProbeHeaderValue is the value used in 'K-Network-Probe'
var ProbeHeaderValue = "probe"
"knative.dev/networking/pkg/http/header"
)
type handler struct {
next http.Handler
}
// NewProbeHandler wraps a HTTP handler handling probing requests around the provided HTTP handler
func NewProbeHandler(next http.Handler) http.Handler {
// NewHandler wraps a HTTP handler handling probing requests around the provided HTTP handler
func NewHandler(next http.Handler) http.Handler {
return &handler{next: next}
}
// ServeHTTP handles probing requests
func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if ph := r.Header.Get(ProbeHeaderName); ph != ProbeHeaderValue {
r.Header.Del(HashHeaderName)
if ph := r.Header.Get(header.ProbeKey); ph != header.ProbeValue {
r.Header.Del(header.HashKey)
h.next.ServeHTTP(w, r)
return
}
hh := r.Header.Get(HashHeaderName)
hh := r.Header.Get(header.HashKey)
if hh == "" {
http.Error(w, fmt.Sprintf("a probe request must contain a non-empty %q header", HashHeaderName), http.StatusBadRequest)
http.Error(w, fmt.Sprintf("a probe request must contain a non-empty %q header", header.HashKey), http.StatusBadRequest)
return
}
w.Header().Set(HashHeaderName, hh)
w.Header().Set(header.HashKey, hh)
w.WriteHeader(http.StatusOK)
}

View File

@ -5,7 +5,7 @@ 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
https://www.apache.org/licenses/LICENSE-2.0
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,
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package pkg
package proxy
import (
"net/http/httputil"

View File

@ -0,0 +1,28 @@
/*
Copyright 2022 The Knative Authors
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.
*/
package proxy
const (
// FlushInterval controls the time when we flush the connection in the
// reverse proxies (Activator, QP).
// As of go1.16, a FlushInterval of 0 (the default) still flushes immediately
// when Content-Length is -1, which means the default works properly for
// streaming/websockets, without flushing more often than necessary for
// non-streaming requests.
FlushInterval = 0
)

View File

@ -5,7 +5,7 @@ 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
https://www.apache.org/licenses/LICENSE-2.0
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,
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package pkg
package stats
import (
"sync"
@ -24,7 +24,6 @@ import (
)
// ReqEvent represents either an incoming or closed request.
// +k8s:deepcopy-gen=false
type ReqEvent struct {
// Time is the time the request event happened.
Time time.Time
@ -55,7 +54,6 @@ func NewRequestStats(startedAt time.Time) *RequestStats {
}
// RequestStats collects statistics about requests as they flow in and out of the system.
// +k8s:deepcopy-gen=false
type RequestStats struct {
mux sync.Mutex
@ -72,7 +70,6 @@ type RequestStats struct {
// RequestStatsReport are the metrics reported from the the request stats collector
// at a given time.
// +k8s:deepcopy-gen=false
type RequestStatsReport struct {
// AverageConcurrency is the average concurrency over the reporting timeframe.
// This is calculated via the utilization at a given concurrency. For example:

View File

@ -0,0 +1,43 @@
/*
Copyright 2022 The Knative Authors
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.
*/
package k8s
import (
"fmt"
corev1 "k8s.io/api/core/v1"
)
// NameForPortNumber finds the name for a given port as defined by a Service.
func NameForPortNumber(svc *corev1.Service, portNumber int32) (string, error) {
for _, port := range svc.Spec.Ports {
if port.Port == portNumber {
return port.Name, nil
}
}
return "", fmt.Errorf("no port with number %d found", portNumber)
}
// PortNumberForName resolves a given name to a portNumber as defined by an EndpointSubset.
func PortNumberForName(sub corev1.EndpointSubset, portName string) (int32, error) {
for _, subPort := range sub.Ports {
if subPort.Name == portName {
return subPort.Port, nil
}
}
return 0, fmt.Errorf("no port for name %q found", portName)
}

View File

@ -5,21 +5,21 @@ import (
"fmt"
"strings"
networkingpkg "knative.dev/networking/pkg"
"knative.dev/networking/pkg/apis/networking"
netv1alpha1 "knative.dev/networking/pkg/apis/networking/v1alpha1"
netcfg "knative.dev/networking/pkg/config"
"knative.dev/pkg/logging"
)
// GetHTTPOption get http-protocol from resource annotations if not, get it from configmap config-network
func GetHTTPOption(ctx context.Context, networkConfig *networkingpkg.Config, annotations map[string]string) (netv1alpha1.HTTPOption, error) {
func GetHTTPOption(ctx context.Context, networkConfig *netcfg.Config, annotations map[string]string) (netv1alpha1.HTTPOption, error) {
// Get HTTPOption via annotations.
if len(annotations) != 0 && networking.GetHTTPProtocol(annotations) != "" {
protocol := strings.ToLower(networking.GetHTTPProtocol(annotations))
switch networkingpkg.HTTPProtocol(protocol) {
case networkingpkg.HTTPEnabled:
switch netcfg.HTTPProtocol(protocol) {
case netcfg.HTTPEnabled:
return netv1alpha1.HTTPOptionEnabled, nil
case networkingpkg.HTTPRedirected:
case netcfg.HTTPRedirected:
return netv1alpha1.HTTPOptionRedirected, nil
default:
return "", fmt.Errorf("incorrect http-protocol annotation: " + protocol)
@ -31,12 +31,12 @@ func GetHTTPOption(ctx context.Context, networkConfig *networkingpkg.Config, ann
// Get HTTPOption via config-network.
switch httpProtocol := networkConfig.HTTPProtocol; httpProtocol {
case networkingpkg.HTTPEnabled:
case netcfg.HTTPEnabled:
return netv1alpha1.HTTPOptionEnabled, nil
case networkingpkg.HTTPRedirected:
case netcfg.HTTPRedirected:
return netv1alpha1.HTTPOptionRedirected, nil
// This will be deprecated soon
case networkingpkg.HTTPDisabled:
case netcfg.HTTPDisabled:
logger.Warnf("http-protocol %s in config-network ConfigMap will be deprecated soon", httpProtocol)
return "", nil
default:

View File

@ -22,7 +22,7 @@ import (
corev1 "k8s.io/api/core/v1"
"sigs.k8s.io/yaml"
netpkg "knative.dev/networking/pkg"
"knative.dev/networking/pkg/apis/networking"
"knative.dev/pkg/configmap"
"knative.dev/pkg/network"
"knative.dev/serving/pkg/apis/serving"
@ -99,7 +99,7 @@ func (c *Domain) LookupDomainForLabels(labels map[string]string) string {
specificity := -1
// If we see VisibilityLabelKey sets with VisibilityClusterLocal, that
// will take precedence and the route will get a Cluster's Domain Name.
if labels[netpkg.VisibilityLabelKey] == serving.VisibilityClusterLocal {
if labels[networking.VisibilityLabelKey] == serving.VisibilityClusterLocal {
return "svc." + network.GetClusterDomainName()
}
for k, selector := range c.Domains {

View File

@ -20,6 +20,7 @@ import (
"context"
network "knative.dev/networking/pkg"
netcfg "knative.dev/networking/pkg/config"
"knative.dev/pkg/configmap"
"knative.dev/pkg/logging"
cfgmap "knative.dev/serving/pkg/apis/config"
@ -33,7 +34,7 @@ type cfgKey struct{}
type Config struct {
Domain *Domain
GC *gc.Config
Network *network.Config
Network *netcfg.Config
Features *cfgmap.Features
}
@ -88,7 +89,7 @@ func NewStore(ctx context.Context, onAfterStore ...func(name string, value inter
configmap.Constructors{
DomainConfigName: NewDomainFromConfigMap,
gc.ConfigName: gc.NewConfigFromConfigMapFunc(ctx),
network.ConfigName: network.NewConfigFromConfigMap,
netcfg.ConfigMapName: network.NewConfigFromConfigMap,
cfgmap.FeaturesConfigName: cfgmap.NewFeaturesConfigFromConfigMap,
},
onAfterStore...,
@ -108,7 +109,7 @@ func (s *Store) Load() *Config {
config := &Config{
Domain: s.UntypedLoad(DomainConfigName).(*Domain).DeepCopy(),
GC: s.UntypedLoad(gc.ConfigName).(*gc.Config).DeepCopy(),
Network: s.UntypedLoad(network.ConfigName).(*network.Config).DeepCopy(),
Network: s.UntypedLoad(netcfg.ConfigMapName).(*netcfg.Config).DeepCopy(),
Features: nil,
}

View File

@ -26,8 +26,9 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/validation"
"k8s.io/apimachinery/pkg/util/validation/field"
network "knative.dev/networking/pkg"
netapi "knative.dev/networking/pkg/apis/networking"
netv1alpha1 "knative.dev/networking/pkg/apis/networking/v1alpha1"
netcfg "knative.dev/networking/pkg/config"
"knative.dev/pkg/apis"
pkgnet "knative.dev/pkg/network"
"knative.dev/serving/pkg/apis/serving"
@ -72,7 +73,7 @@ func DomainNameFromTemplate(ctx context.Context, r metav1.ObjectMeta, name strin
// These are the available properties they can choose from.
// We could add more over time - e.g. RevisionName if we thought that
// might be of interest to people.
data := network.DomainTemplateValues{
data := netcfg.DomainTemplateValues{
Name: name,
Namespace: r.Namespace,
Domain: domain,
@ -86,9 +87,9 @@ func DomainNameFromTemplate(ctx context.Context, r metav1.ObjectMeta, name strin
var templ *template.Template
// If the route is "cluster local" then don't use the user-defined
// domain template, use the default one
if rLabels[network.VisibilityLabelKey] == serving.VisibilityClusterLocal {
if rLabels[netapi.VisibilityLabelKey] == serving.VisibilityClusterLocal {
templ = template.Must(template.New("domain-template").Parse(
network.DefaultDomainTemplate))
netcfg.DefaultDomainTemplate))
} else {
templ = networkConfig.GetDomainTemplate()
}
@ -114,7 +115,7 @@ func HostnameFromTemplate(ctx context.Context, name, tag string) (string, error)
// These are the available properties they can choose from.
// We could add more over time - e.g. RevisionName if we thought that
// might be of interest to people.
data := network.TagTemplateValues{
data := netcfg.TagTemplateValues{
Name: name,
Tag: tag,
}

View File

@ -18,7 +18,7 @@ package labels
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
network "knative.dev/networking/pkg"
network "knative.dev/networking/pkg/apis/networking"
"knative.dev/serving/pkg/apis/serving"
)

View File

@ -28,7 +28,6 @@ import (
"google.golang.org/grpc"
networkingpkg "knative.dev/networking/pkg"
"knative.dev/pkg/network"
ping "knative.dev/serving/test/test_images/grpc-ping/proto"
)
@ -81,16 +80,6 @@ func (s *server) PingStream(stream ping.PingService_PingStreamServer) error {
}
}
func httpWrapper(g *grpc.Server) http.Handler {
return networkingpkg.NewProbeHandler(
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.ProtoMajor == 2 && r.Header.Get("Content-Type") == "application/grpc" {
g.ServeHTTP(w, r)
}
}),
)
}
func main() {
log.Print("Starting server on ", os.Getenv("PORT"))
@ -103,9 +92,14 @@ func main() {
}
g := grpc.NewServer()
s := network.NewServer(":"+os.Getenv("PORT"), httpWrapper(g))
ping.RegisterPingServiceServer(g, &server{})
handler := func(w http.ResponseWriter, r *http.Request) {
if r.ProtoMajor == 2 && r.Header.Get("Content-Type") == "application/grpc" {
g.ServeHTTP(w, r)
}
}
s := network.NewServer(":"+os.Getenv("PORT"), http.HandlerFunc(handler))
log.Fatal(s.ListenAndServe())
}

View File

@ -43,7 +43,7 @@ const (
HelloVolumePath = "/hello/world"
caSecretNamespace = "cert-manager"
caSecretName = "ca-key-pair"
caSecretName = "ca-key-pair" // #nosec G101
)
// util.go provides shared utilities methods across knative serving test
@ -86,7 +86,7 @@ func TLSClientConfig(ctx context.Context, logf logging.FormatLogger, clients *Cl
if !rootCAs.AppendCertsFromPEM(PemDataFromSecret(ctx, logf, clients, caSecretNamespace, caSecretName)) {
logf("Failed to add the certificate to the root CA")
}
return &tls.Config{RootCAs: rootCAs}
return &tls.Config{RootCAs: rootCAs} // #nosec G402
}
// PemDataFromSecret gets pem data from secret.

21
vendor/modules.txt vendored
View File

@ -888,11 +888,13 @@ k8s.io/utils/buffer
k8s.io/utils/clock
k8s.io/utils/clock/testing
k8s.io/utils/integer
k8s.io/utils/internal/third_party/forked/golang/golang-lru
k8s.io/utils/internal/third_party/forked/golang/net
k8s.io/utils/lru
k8s.io/utils/net
k8s.io/utils/pointer
k8s.io/utils/trace
# knative.dev/eventing v0.31.1-0.20220509144032-9af98709e92b
# knative.dev/eventing v0.31.1-0.20220523181303-c3e13967001f
## explicit; go 1.16
knative.dev/eventing/pkg/apis/config
knative.dev/eventing/pkg/apis/duck
@ -920,18 +922,25 @@ knative.dev/eventing/pkg/client/clientset/versioned/typed/sources/v1
knative.dev/eventing/pkg/client/clientset/versioned/typed/sources/v1/fake
knative.dev/eventing/pkg/client/clientset/versioned/typed/sources/v1beta2
knative.dev/eventing/pkg/client/clientset/versioned/typed/sources/v1beta2/fake
# knative.dev/hack v0.0.0-20220506160929-a8076b0510ed
# knative.dev/hack v0.0.0-20220518013938-b4d4d73a2995
## explicit; go 1.14
knative.dev/hack
# knative.dev/networking v0.0.0-20220505013701-91dcb36802a9
## explicit; go 1.16
# knative.dev/networking v0.0.0-20220519194057-941c61aa258b
## explicit; go 1.17
knative.dev/networking/pkg
knative.dev/networking/pkg/apis/networking
knative.dev/networking/pkg/apis/networking/v1alpha1
knative.dev/networking/pkg/client/clientset/versioned
knative.dev/networking/pkg/client/clientset/versioned/scheme
knative.dev/networking/pkg/client/clientset/versioned/typed/networking/v1alpha1
# knative.dev/pkg v0.0.0-20220505013700-a8b7d99374a3
knative.dev/networking/pkg/config
knative.dev/networking/pkg/http
knative.dev/networking/pkg/http/header
knative.dev/networking/pkg/http/probe
knative.dev/networking/pkg/http/proxy
knative.dev/networking/pkg/http/stats
knative.dev/networking/pkg/k8s
# knative.dev/pkg v0.0.0-20220518013728-f907b31046d3
## explicit; go 1.17
knative.dev/pkg/apis
knative.dev/pkg/apis/duck
@ -981,7 +990,7 @@ knative.dev/pkg/tracing/config
knative.dev/pkg/tracing/propagation
knative.dev/pkg/tracing/propagation/tracecontextb3
knative.dev/pkg/tracker
# knative.dev/serving v0.31.1-0.20220510145433-f726b1db1b0a
# knative.dev/serving v0.31.1-0.20220521001759-45f7c054f694
## explicit; go 1.17
knative.dev/serving/pkg/apis/autoscaling
knative.dev/serving/pkg/apis/autoscaling/v1alpha1