Documentation ¶
Overview ¶
Copyright 2017 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.
// Copyright 2020 Antrea 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.
Modifies:
- Remove imports: "net", "reflect", "strconv", "sync", "time", "k8s.io/api/core/v1", "k8s.io/api/discovery/v1beta1", "k8s.io/apimachinery/pkg/util/sets", "k8s.io/client-go/tools/record", "k8s.io/klog/v2", "k8s.io/utils/net"
- Remove vars: "supportedEndpointSliceAddressTypes"
- Remove functions: "newBaseEndpointInfo", "makeEndpointFunc", "NewEndpointChangeTracker", "detectStaleConnections"
- Remove structs: "EndpointChangeTracker", "EndpointsMap"
Index ¶
- type BaseEndpointInfo
- func (info *BaseEndpointInfo) Equal(other Endpoint) bool
- func (info *BaseEndpointInfo) GetIsLocal() bool
- func (info *BaseEndpointInfo) GetNodeName() string
- func (info *BaseEndpointInfo) GetZone() string
- func (info *BaseEndpointInfo) GetZoneHints() sets.Set[string]
- func (info *BaseEndpointInfo) IP() string
- func (info *BaseEndpointInfo) IsReady() bool
- func (info *BaseEndpointInfo) IsServing() bool
- func (info *BaseEndpointInfo) IsTerminating() bool
- func (info *BaseEndpointInfo) Port() (int, error)
- func (info *BaseEndpointInfo) String() string
- type BaseServiceInfo
- func (info *BaseServiceInfo) ClusterIP() net.IP
- func (info *BaseServiceInfo) ExternalIPStrings() []string
- func (info *BaseServiceInfo) ExternalPolicyLocal() bool
- func (info *BaseServiceInfo) ExternallyAccessible() bool
- func (info *BaseServiceInfo) HealthCheckNodePort() int
- func (info *BaseServiceInfo) HintsAnnotation() string
- func (info *BaseServiceInfo) InternalPolicyLocal() bool
- func (info *BaseServiceInfo) InternalTrafficPolicy() *v1.ServiceInternalTrafficPolicyType
- func (info *BaseServiceInfo) LoadBalancerIPStrings() []string
- func (info *BaseServiceInfo) LoadBalancerSourceRanges() []string
- func (info *BaseServiceInfo) NodePort() int
- func (info *BaseServiceInfo) Port() int
- func (info *BaseServiceInfo) Protocol() v1.Protocol
- func (info *BaseServiceInfo) SessionAffinityType() v1.ServiceAffinity
- func (info *BaseServiceInfo) StickyMaxAgeSeconds() int
- func (info *BaseServiceInfo) String() string
- func (info *BaseServiceInfo) UsesClusterEndpoints() bool
- func (info *BaseServiceInfo) UsesLocalEndpoints() bool
- type BoundedFrequencyRunner
- type Endpoint
- type Provider
- type ServiceChangeTracker
- type ServiceEndpoint
- type ServiceMap
- type ServicePort
- type ServicePortName
- type UpdateServiceMapResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseEndpointInfo ¶
type BaseEndpointInfo struct { Endpoint string // TODO: should be an endpointString type // IsLocal indicates whether the endpoint is running in same host as kube-proxy. IsLocal bool // ZoneHints represent the zone hints for the endpoint. This is based on // endpoint.hints.forZones[*].name in the EndpointSlice API. ZoneHints sets.Set[string] // Ready indicates whether this endpoint is ready and NOT terminating. // For pods, this is true if a pod has a ready status and a nil deletion timestamp. // This is only set when watching EndpointSlices. If using Endpoints, this is always // true since only ready endpoints are read from Endpoints. // TODO: Ready can be inferred from Serving and Terminating below when enabled by default. Ready bool // Serving indiciates whether this endpoint is ready regardless of its terminating state. // For pods this is true if it has a ready status regardless of its deletion timestamp. // This is only set when watching EndpointSlices. If using Endpoints, this is always // true since only ready endpoints are read from Endpoints. Serving bool // Terminating indicates whether this endpoint is terminating. // For pods this is true if it has a non-nil deletion timestamp. // This is only set when watching EndpointSlices. If using Endpoints, this is always // false since terminating endpoints are always excluded from Endpoints. Terminating bool // NodeName is the name of the node this endpoint belongs to NodeName string // Zone is the name of the zone this endpoint belongs to Zone string }
BaseEndpointInfo contains base information that defines an endpoint. This could be used directly by proxier while processing endpoints, or can be used for constructing a more specific EndpointInfo struct defined by the proxier if needed.
func NewBaseEndpointInfo ¶
func (*BaseEndpointInfo) Equal ¶
func (info *BaseEndpointInfo) Equal(other Endpoint) bool
Equal is part of proxy.Endpoint interface.
func (*BaseEndpointInfo) GetIsLocal ¶
func (info *BaseEndpointInfo) GetIsLocal() bool
GetIsLocal is part of proxy.Endpoint interface.
func (*BaseEndpointInfo) GetNodeName ¶ added in v1.8.0
func (info *BaseEndpointInfo) GetNodeName() string
GetNodeName returns the NodeName for this endpoint.
func (*BaseEndpointInfo) GetZone ¶ added in v1.8.0
func (info *BaseEndpointInfo) GetZone() string
GetZone returns the Zone for this endpoint.
func (*BaseEndpointInfo) GetZoneHints ¶ added in v1.8.0
func (info *BaseEndpointInfo) GetZoneHints() sets.Set[string]
GetZoneHints returns the zone hint for the endpoint.
func (*BaseEndpointInfo) IP ¶
func (info *BaseEndpointInfo) IP() string
IP returns just the IP part of the endpoint, it's a part of proxy.Endpoint interface.
func (*BaseEndpointInfo) IsReady ¶ added in v1.8.0
func (info *BaseEndpointInfo) IsReady() bool
IsReady returns true if an endpoint is ready and not terminating.
func (*BaseEndpointInfo) IsServing ¶ added in v1.8.0
func (info *BaseEndpointInfo) IsServing() bool
IsServing returns true if an endpoint is ready, regardless of if the endpoint is terminating.
func (*BaseEndpointInfo) IsTerminating ¶ added in v1.8.0
func (info *BaseEndpointInfo) IsTerminating() bool
IsTerminating retruns true if an endpoint is terminating. For pods, that is any pod with a deletion timestamp.
func (*BaseEndpointInfo) Port ¶
func (info *BaseEndpointInfo) Port() (int, error)
Port returns just the Port part of the endpoint.
func (*BaseEndpointInfo) String ¶
func (info *BaseEndpointInfo) String() string
String is part of proxy.Endpoint interface.
type BaseServiceInfo ¶
type BaseServiceInfo struct {
// contains filtered or unexported fields
}
BaseServiceInfo contains base information that defines a service. This could be used directly by proxier while processing services, or can be used for constructing a more specific ServiceInfo struct defined by the proxier if needed.
func NewBaseServiceInfo ¶ added in v1.11.0
func NewBaseServiceInfo(clusterIP net.IP, port int, protocol v1.Protocol, nodePort int, loadBalancerStatus v1.LoadBalancerStatus, sessionAffinityType v1.ServiceAffinity, stickyMaxAgeSeconds int, externalIPs []string, loadBalancerSourceRanges []string, healthCheckNodePort int, externalPolicyLocal bool, internalPolicyLocal bool, internalTrafficPolicy *v1.ServiceInternalTrafficPolicyType, hintsAnnotation string) *BaseServiceInfo
NewBaseServiceInfo is for testing purposes only.
func (*BaseServiceInfo) ClusterIP ¶
func (info *BaseServiceInfo) ClusterIP() net.IP
ClusterIP is part of ServicePort interface.
func (*BaseServiceInfo) ExternalIPStrings ¶
func (info *BaseServiceInfo) ExternalIPStrings() []string
ExternalIPStrings is part of ServicePort interface.
func (*BaseServiceInfo) ExternalPolicyLocal ¶ added in v1.11.0
func (info *BaseServiceInfo) ExternalPolicyLocal() bool
ExternalPolicyLocal is part of ServicePort interface.
func (*BaseServiceInfo) ExternallyAccessible ¶ added in v1.11.0
func (info *BaseServiceInfo) ExternallyAccessible() bool
ExternallyAccessible is part of ServicePort interface.
func (*BaseServiceInfo) HealthCheckNodePort ¶
func (info *BaseServiceInfo) HealthCheckNodePort() int
HealthCheckNodePort is part of ServicePort interface.
func (*BaseServiceInfo) HintsAnnotation ¶
func (info *BaseServiceInfo) HintsAnnotation() string
HintsAnnotation is part of ServicePort interface.
func (*BaseServiceInfo) InternalPolicyLocal ¶ added in v1.11.0
func (info *BaseServiceInfo) InternalPolicyLocal() bool
InternalPolicyLocal is part of ServicePort interface
func (*BaseServiceInfo) InternalTrafficPolicy ¶
func (info *BaseServiceInfo) InternalTrafficPolicy() *v1.ServiceInternalTrafficPolicyType
InternalTrafficPolicy is part of ServicePort interface
func (*BaseServiceInfo) LoadBalancerIPStrings ¶
func (info *BaseServiceInfo) LoadBalancerIPStrings() []string
LoadBalancerIPStrings is part of ServicePort interface.
func (*BaseServiceInfo) LoadBalancerSourceRanges ¶
func (info *BaseServiceInfo) LoadBalancerSourceRanges() []string
LoadBalancerSourceRanges is part of ServicePort interface
func (*BaseServiceInfo) NodePort ¶
func (info *BaseServiceInfo) NodePort() int
NodePort is part of the ServicePort interface.
func (*BaseServiceInfo) Port ¶
func (info *BaseServiceInfo) Port() int
Port is part of ServicePort interface.
func (*BaseServiceInfo) Protocol ¶
func (info *BaseServiceInfo) Protocol() v1.Protocol
Protocol is part of ServicePort interface.
func (*BaseServiceInfo) SessionAffinityType ¶
func (info *BaseServiceInfo) SessionAffinityType() v1.ServiceAffinity
SessionAffinityType is part of the ServicePort interface.
func (*BaseServiceInfo) StickyMaxAgeSeconds ¶
func (info *BaseServiceInfo) StickyMaxAgeSeconds() int
StickyMaxAgeSeconds is part of the ServicePort interface
func (*BaseServiceInfo) String ¶
func (info *BaseServiceInfo) String() string
String is part of ServicePort interface.
func (*BaseServiceInfo) UsesClusterEndpoints ¶ added in v1.11.0
func (info *BaseServiceInfo) UsesClusterEndpoints() bool
UsesClusterEndpoints is part of ServicePort interface.
func (*BaseServiceInfo) UsesLocalEndpoints ¶ added in v1.11.0
func (info *BaseServiceInfo) UsesLocalEndpoints() bool
UsesLocalEndpoints is part of ServicePort interface.
type BoundedFrequencyRunner ¶
type BoundedFrequencyRunner struct {
// contains filtered or unexported fields
}
BoundedFrequencyRunner manages runs of a user-provided function. See NewBoundedFrequencyRunner for examples.
func NewBoundedFrequencyRunner ¶
func NewBoundedFrequencyRunner(name string, fn func(), minInterval, maxInterval time.Duration, burstRuns int) *BoundedFrequencyRunner
NewBoundedFrequencyRunner creates a new BoundedFrequencyRunner instance, which will manage runs of the specified function.
All runs will be async to the caller of BoundedFrequencyRunner.Run, but multiple runs are serialized. If the function needs to hold locks, it must take them internally.
Runs of the function will have at least minInterval between them (from completion to next start), except that up to bursts may be allowed. Burst runs are "accumulated" over time, one per minInterval up to burstRuns total. This can be used, for example, to mitigate the impact of expensive operations being called in response to user-initiated operations. Run requests that would violate the minInterval are coallesced and run at the next opportunity.
The function will be run at least once per maxInterval. For example, this can force periodic refreshes of state in the absence of anyone calling Run.
Examples:
NewBoundedFrequencyRunner("name", fn, time.Second, 5*time.Second, 1) - fn will have at least 1 second between runs - fn will have no more than 5 seconds between runs
NewBoundedFrequencyRunner("name", fn, 3*time.Second, 10*time.Second, 3) - fn will have at least 3 seconds between runs, with up to 3 burst runs - fn will have no more than 10 seconds between runs
The maxInterval must be greater than or equal to the minInterval, If the caller passes a maxInterval less than minInterval, this function will panic.
func (*BoundedFrequencyRunner) Loop ¶
func (bfr *BoundedFrequencyRunner) Loop(stop <-chan struct{})
Loop handles the periodic timer and run requests. This is expected to be called as a goroutine.
func (*BoundedFrequencyRunner) Run ¶
func (bfr *BoundedFrequencyRunner) Run()
Run the function as soon as possible. If this is called while Loop is not running, the call may be deferred indefinitely. If there is already a queued request to call the underlying function, it may be dropped - it is just guaranteed that we will try calling the underlying function as soon as possible starting from now.
type Endpoint ¶
type Endpoint interface { // String returns endpoint string. An example format can be: `IP:Port`. // We take the returned value as ServiceEndpoint.Endpoint. String() string // GetIsLocal returns true if the endpoint is running in same host as kube-proxy, otherwise returns false. GetIsLocal() bool // IsReady returns true if an endpoint is ready and not terminating. // This is only set when watching EndpointSlices. If using Endpoints, this is always // true since only ready endpoints are read from Endpoints. IsReady() bool // IsServing returns true if an endpoint is ready. It does not account // for terminating state. // This is only set when watching EndpointSlices. If using Endpoints, this is always // true since only ready endpoints are read from Endpoints. IsServing() bool // IsTerminating returns true if an endpoint is terminating. For pods, // that is any pod with a deletion timestamp. // This is only set when watching EndpointSlices. If using Endpoints, this is always // false since terminating endpoints are always excluded from Endpoints. IsTerminating() bool // GetZoneHints returns the zone hint for the endpoint. This is based on // endpoint.hints.forZones[0].name in the EndpointSlice API. GetZoneHints() sets.Set[string] // IP returns IP part of the endpoint. IP() string // Port returns the Port part of the endpoint. Port() (int, error) // Equal checks if two endpoints are equal. Equal(Endpoint) bool // GetNodeName returns the node name for the endpoint GetNodeName() string // GetZone returns the zone for the endpoint GetZone() string }
Endpoint in an interface which abstracts information about an endpoint. TODO: Rename functions to be consistent with ServicePort.
type Provider ¶
type Provider interface { config.EndpointsHandler config.EndpointSliceHandler config.NodeHandler config.ServiceHandler // SyncLoop runs periodic work. // This is expected to run as a goroutine or as the main loop of the app. // It does not return. SyncLoop() // SyncedOnce returns true if the proxier has synced rules at least once. SyncedOnce() bool Run(stopCh <-chan struct{}) }
Provider is the interface provided by proxier implementations.
func NewMetaProxier ¶
NewMetaProxier returns a dual-stack "meta-proxier". Proxier API calls will be dispatched to the ProxyProvider instances depending on address family.
type ServiceChangeTracker ¶
type ServiceChangeTracker struct {
// contains filtered or unexported fields
}
ServiceChangeTracker carries state about uncommitted changes to an arbitrary number of Services, keyed by their namespace and name.
func NewServiceChangeTracker ¶
func NewServiceChangeTracker(makeServiceInfo makeServicePortFunc, ipFamily v1.IPFamily, recorder record.EventRecorder, processServiceMapChange processServiceMapChangeFunc, serviceLabelSelector labels.Selector, skipServices []string) *ServiceChangeTracker
NewServiceChangeTracker initializes a ServiceChangeTracker
func (*ServiceChangeTracker) Update ¶
func (sct *ServiceChangeTracker) Update(previous, current *v1.Service) bool
Update updates given service's change map based on the <previous, current> service pair. It returns true if items changed, otherwise return false. Update can be used to add/update/delete items of ServiceChangeMap. For example, Add item
- pass <nil, service> as the <previous, current> pair.
Update item
- pass <oldService, service> as the <previous, current> pair.
Delete item
- pass <service, nil> as the <previous, current> pair.
type ServiceEndpoint ¶
type ServiceEndpoint struct { Endpoint string ServicePortName ServicePortName }
ServiceEndpoint is used to identify a service and one of its endpoint pair.
type ServiceMap ¶
type ServiceMap map[ServicePortName]ServicePort
ServiceMap maps a service to its ServicePort.
func (ServiceMap) Update ¶
func (sm ServiceMap) Update(changes *ServiceChangeTracker) (result UpdateServiceMapResult)
Update updates ServiceMap base on the given changes.
type ServicePort ¶
type ServicePort interface { // String returns service string. An example format can be: `IP:Port/Protocol`. String() string // GetClusterIP returns service cluster IP in net.IP format. ClusterIP() net.IP // GetPort returns service port if present. If return 0 means not present. Port() int // GetSessionAffinityType returns service session affinity type SessionAffinityType() v1.ServiceAffinity // GetStickyMaxAgeSeconds returns service max connection age StickyMaxAgeSeconds() int // ExternalIPStrings returns service ExternalIPs as a string array. ExternalIPStrings() []string // LoadBalancerIPStrings returns service LoadBalancerIPs as a string array. LoadBalancerIPStrings() []string // GetProtocol returns service protocol. Protocol() v1.Protocol // LoadBalancerSourceRanges returns service LoadBalancerSourceRanges if present empty array if not LoadBalancerSourceRanges() []string // GetHealthCheckNodePort returns service health check node port if present. If return 0, it means not present. HealthCheckNodePort() int // GetNodePort returns a service Node port if present. If return 0, it means not present. NodePort() int // ExternalPolicyLocal returns if a service has only node local endpoints for external traffic. ExternalPolicyLocal() bool // InternalPolicyLocal returns if a service has only node local endpoints for internal traffic. InternalPolicyLocal() bool // InternalTrafficPolicy returns service InternalTrafficPolicy InternalTrafficPolicy() *v1.ServiceInternalTrafficPolicyType // HintsAnnotation returns the value of the v1.AnnotationTopologyAwareHints annotation or // service.kubernetes.io/topology-mode annotation. HintsAnnotation() string // ExternallyAccessible returns true if the service port is reachable via something // other than ClusterIP (NodePort/ExternalIP/LoadBalancer) ExternallyAccessible() bool // UsesClusterEndpoints returns true if the service port ever sends traffic to // endpoints based on "Cluster" traffic policy UsesClusterEndpoints() bool // UsesLocalEndpoints returns true if the service port ever sends traffic to // endpoints based on "Local" traffic policy UsesLocalEndpoints() bool }
ServicePort is an interface which abstracts information about a service.
type ServicePortName ¶
type ServicePortName struct { types.NamespacedName Port string Protocol v1.Protocol }
ServicePortName carries a namespace + name + portname. This is the unique identifier for a load-balanced service.
func (ServicePortName) String ¶
func (spn ServicePortName) String() string
type UpdateServiceMapResult ¶
type UpdateServiceMapResult struct { // HCServiceNodePorts is a map of Service names to node port numbers which indicate the health of that Service on this Node. // The value(uint16) of HCServices map is the service health check node port. HCServiceNodePorts map[types.NamespacedName]uint16 // UDPStaleClusterIP holds stale (no longer assigned to a Service) Service IPs that had UDP ports. // Callers can use this to abort timeout-waits or clear connection-tracking information. UDPStaleClusterIP sets.Set[string] }
UpdateServiceMapResult is the updated results after applying service changes.