Upgrade k8s package verison (#5358)
* upgrade k8s package version Signed-off-by: hongzhouzi <hongzhouzi@kubesphere.io> * Script upgrade and code formatting. Signed-off-by: hongzhouzi <hongzhouzi@kubesphere.io> Signed-off-by: hongzhouzi <hongzhouzi@kubesphere.io>
This commit is contained in:
29
vendor/k8s.io/apiserver/pkg/server/egressselector/config.go
generated
vendored
29
vendor/k8s.io/apiserver/pkg/server/egressselector/config.go
generated
vendored
@@ -34,8 +34,7 @@ import (
|
||||
var cfgScheme = runtime.NewScheme()
|
||||
|
||||
// validEgressSelectorNames contains the set of valid egress selctor names.
|
||||
// 'master' is deprecated in favor of 'controlplane' and will be removed in v1.22.
|
||||
var validEgressSelectorNames = sets.NewString("master", "controlplane", "cluster", "etcd")
|
||||
var validEgressSelectorNames = sets.NewString("controlplane", "cluster", "etcd")
|
||||
|
||||
func init() {
|
||||
install.Install(cfgScheme)
|
||||
@@ -103,27 +102,21 @@ func ValidateEgressSelectorConfiguration(config *apiserver.EgressSelectorConfigu
|
||||
}
|
||||
}
|
||||
|
||||
var foundControlPlane, foundMaster bool
|
||||
for _, service := range config.EgressSelections {
|
||||
seen := sets.String{}
|
||||
for i, service := range config.EgressSelections {
|
||||
canonicalName := strings.ToLower(service.Name)
|
||||
|
||||
if !validEgressSelectorNames.Has(canonicalName) {
|
||||
allErrs = append(allErrs, field.NotSupported(field.NewPath("egressSelection", "name"), canonicalName, validEgressSelectorNames.List()))
|
||||
fldPath := field.NewPath("service", "connection")
|
||||
// no duplicate check
|
||||
if seen.Has(canonicalName) {
|
||||
allErrs = append(allErrs, field.Duplicate(fldPath.Index(i), canonicalName))
|
||||
continue
|
||||
}
|
||||
seen.Insert(canonicalName)
|
||||
|
||||
if canonicalName == "master" {
|
||||
foundMaster = true
|
||||
if !validEgressSelectorNames.Has(canonicalName) {
|
||||
allErrs = append(allErrs, field.NotSupported(fldPath, canonicalName, validEgressSelectorNames.List()))
|
||||
continue
|
||||
}
|
||||
|
||||
if canonicalName == "controlplane" {
|
||||
foundControlPlane = true
|
||||
}
|
||||
}
|
||||
|
||||
// error if both master and controlplane egress selectors are set
|
||||
if foundMaster && foundControlPlane {
|
||||
allErrs = append(allErrs, field.Forbidden(field.NewPath("egressSelection", "name"), "both egressSelection names 'master' and 'controlplane' are specified, only one is allowed"))
|
||||
}
|
||||
|
||||
return allErrs
|
||||
|
||||
61
vendor/k8s.io/apiserver/pkg/server/egressselector/egress_selector.go
generated
vendored
61
vendor/k8s.io/apiserver/pkg/server/egressselector/egress_selector.go
generated
vendored
@@ -30,6 +30,7 @@ import (
|
||||
"time"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
|
||||
utilnet "k8s.io/apimachinery/pkg/util/net"
|
||||
"k8s.io/apiserver/pkg/apis/apiserver"
|
||||
@@ -91,10 +92,6 @@ func (s EgressType) AsNetworkContext() NetworkContext {
|
||||
|
||||
func lookupServiceName(name string) (EgressType, error) {
|
||||
switch strings.ToLower(name) {
|
||||
// 'master' is deprecated, interpret "master" as controlplane internally until removed in v1.22.
|
||||
case "master":
|
||||
klog.Warning("EgressSelection name 'master' is deprecated, use 'controlplane' instead")
|
||||
return ControlPlane, nil
|
||||
case "controlplane":
|
||||
return ControlPlane, nil
|
||||
case "etcd":
|
||||
@@ -134,7 +131,7 @@ func tunnelHTTPConnect(proxyConn net.Conn, proxyAddress, addr string) (net.Conn,
|
||||
|
||||
type proxier interface {
|
||||
// proxy returns a connection to addr.
|
||||
proxy(addr string) (net.Conn, error)
|
||||
proxy(ctx context.Context, addr string) (net.Conn, error)
|
||||
}
|
||||
|
||||
var _ proxier = &httpConnectProxier{}
|
||||
@@ -144,7 +141,7 @@ type httpConnectProxier struct {
|
||||
proxyAddress string
|
||||
}
|
||||
|
||||
func (t *httpConnectProxier) proxy(addr string) (net.Conn, error) {
|
||||
func (t *httpConnectProxier) proxy(ctx context.Context, addr string) (net.Conn, error) {
|
||||
return tunnelHTTPConnect(t.conn, t.proxyAddress, addr)
|
||||
}
|
||||
|
||||
@@ -154,14 +151,18 @@ type grpcProxier struct {
|
||||
tunnel client.Tunnel
|
||||
}
|
||||
|
||||
func (g *grpcProxier) proxy(addr string) (net.Conn, error) {
|
||||
return g.tunnel.Dial("tcp", addr)
|
||||
func (g *grpcProxier) proxy(ctx context.Context, addr string) (net.Conn, error) {
|
||||
return g.tunnel.DialContext(ctx, "tcp", addr)
|
||||
}
|
||||
|
||||
type proxyServerConnector interface {
|
||||
// connect establishes connection to the proxy server, and returns a
|
||||
// proxier based on the connection.
|
||||
connect() (proxier, error)
|
||||
//
|
||||
// The provided Context must be non-nil. The context is used for connecting to the proxy only.
|
||||
// If the context expires before the connection is complete, an error is returned.
|
||||
// Once successfully connected to the proxy, any expiration of the context will not affect the connection.
|
||||
connect(context.Context) (proxier, error)
|
||||
}
|
||||
|
||||
type tcpHTTPConnectConnector struct {
|
||||
@@ -169,8 +170,11 @@ type tcpHTTPConnectConnector struct {
|
||||
tlsConfig *tls.Config
|
||||
}
|
||||
|
||||
func (t *tcpHTTPConnectConnector) connect() (proxier, error) {
|
||||
conn, err := tls.Dial("tcp", t.proxyAddress, t.tlsConfig)
|
||||
func (t *tcpHTTPConnectConnector) connect(ctx context.Context) (proxier, error) {
|
||||
d := tls.Dialer{
|
||||
Config: t.tlsConfig,
|
||||
}
|
||||
conn, err := d.DialContext(ctx, "tcp", t.proxyAddress)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -181,8 +185,9 @@ type udsHTTPConnectConnector struct {
|
||||
udsName string
|
||||
}
|
||||
|
||||
func (u *udsHTTPConnectConnector) connect() (proxier, error) {
|
||||
conn, err := net.Dial("unix", u.udsName)
|
||||
func (u *udsHTTPConnectConnector) connect(ctx context.Context) (proxier, error) {
|
||||
var d net.Dialer
|
||||
conn, err := d.DialContext(ctx, "unix", u.udsName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -193,17 +198,25 @@ type udsGRPCConnector struct {
|
||||
udsName string
|
||||
}
|
||||
|
||||
func (u *udsGRPCConnector) connect() (proxier, error) {
|
||||
// connect establishes a connection to a proxy over gRPC.
|
||||
// TODO At the moment, it does not use the provided context.
|
||||
func (u *udsGRPCConnector) connect(_ context.Context) (proxier, error) {
|
||||
udsName := u.udsName
|
||||
dialOption := grpc.WithContextDialer(func(context.Context, string) (net.Conn, error) {
|
||||
c, err := net.Dial("unix", udsName)
|
||||
dialOption := grpc.WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) {
|
||||
var d net.Dialer
|
||||
c, err := d.DialContext(ctx, "unix", udsName)
|
||||
if err != nil {
|
||||
klog.Errorf("failed to create connection to uds name %s, error: %v", udsName, err)
|
||||
}
|
||||
return c, err
|
||||
})
|
||||
|
||||
tunnel, err := client.CreateSingleUseGrpcTunnel(udsName, dialOption, grpc.WithInsecure())
|
||||
// CreateSingleUseGrpcTunnel() unfortunately couples dial and connection contexts. Because of that,
|
||||
// we cannot use ctx just for dialing and control the connection lifetime separately.
|
||||
// See https://github.com/kubernetes-sigs/apiserver-network-proxy/issues/357.
|
||||
tunnelCtx := context.TODO()
|
||||
tunnel, err := client.CreateSingleUseGrpcTunnel(tunnelCtx, udsName, dialOption,
|
||||
grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -229,12 +242,12 @@ func (d *dialerCreator) createDialer() utilnet.DialFunc {
|
||||
trace := utiltrace.New(fmt.Sprintf("Proxy via %s protocol over %s", d.options.protocol, d.options.transport), utiltrace.Field{Key: "address", Value: addr})
|
||||
defer trace.LogIfLong(500 * time.Millisecond)
|
||||
start := egressmetrics.Metrics.Clock().Now()
|
||||
proxier, err := d.connector.connect()
|
||||
proxier, err := d.connector.connect(ctx)
|
||||
if err != nil {
|
||||
egressmetrics.Metrics.ObserveDialFailure(d.options.protocol, d.options.transport, egressmetrics.StageConnect)
|
||||
return nil, err
|
||||
}
|
||||
conn, err := proxier.proxy(addr)
|
||||
conn, err := proxier.proxy(ctx, addr)
|
||||
if err != nil {
|
||||
egressmetrics.Metrics.ObserveDialFailure(d.options.protocol, d.options.transport, egressmetrics.StageProxy)
|
||||
return nil, err
|
||||
@@ -361,6 +374,16 @@ func NewEgressSelector(config *apiserver.EgressSelectorConfiguration) (*EgressSe
|
||||
return cs, nil
|
||||
}
|
||||
|
||||
// NewEgressSelectorWithMap returns a EgressSelector with the supplied EgressType to DialFunc map.
|
||||
func NewEgressSelectorWithMap(m map[EgressType]utilnet.DialFunc) *EgressSelector {
|
||||
if m == nil {
|
||||
m = make(map[EgressType]utilnet.DialFunc)
|
||||
}
|
||||
return &EgressSelector{
|
||||
egressToDialer: m,
|
||||
}
|
||||
}
|
||||
|
||||
// Lookup gets the dialer function for the network context.
|
||||
// This is configured for the Kubernetes API Server at startup.
|
||||
func (cs *EgressSelector) Lookup(networkContext NetworkContext) (utilnet.DialFunc, error) {
|
||||
|
||||
2
vendor/k8s.io/apiserver/pkg/server/egressselector/metrics/metrics.go
generated
vendored
2
vendor/k8s.io/apiserver/pkg/server/egressselector/metrics/metrics.go
generated
vendored
@@ -19,9 +19,9 @@ package metrics
|
||||
import (
|
||||
"time"
|
||||
|
||||
"k8s.io/apimachinery/pkg/util/clock"
|
||||
"k8s.io/component-base/metrics"
|
||||
"k8s.io/component-base/metrics/legacyregistry"
|
||||
"k8s.io/utils/clock"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
Reference in New Issue
Block a user