Documentation ¶
Overview ¶
Package proxy implements the layer-3 network proxy.
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 BaseServicePortInfo
- func (bsvcPortInfo *BaseServicePortInfo) ClusterIP() net.IP
- func (bsvcPortInfo *BaseServicePortInfo) ExternalIPStrings() []string
- func (bsvcPortInfo *BaseServicePortInfo) ExternalPolicyLocal() bool
- func (bsvcPortInfo *BaseServicePortInfo) ExternallyAccessible() bool
- func (bsvcPortInfo *BaseServicePortInfo) HealthCheckNodePort() int
- func (bsvcPortInfo *BaseServicePortInfo) HintsAnnotation() string
- func (bsvcPortInfo *BaseServicePortInfo) InternalPolicyLocal() bool
- func (bsvcPortInfo *BaseServicePortInfo) InternalTrafficPolicy() *v1.ServiceInternalTrafficPolicy
- func (bsvcPortInfo *BaseServicePortInfo) LoadBalancerIPStrings() []string
- func (bsvcPortInfo *BaseServicePortInfo) LoadBalancerSourceRanges() []string
- func (bsvcPortInfo *BaseServicePortInfo) NodePort() int
- func (bsvcPortInfo *BaseServicePortInfo) Port() int
- func (bsvcPortInfo *BaseServicePortInfo) Protocol() v1.Protocol
- func (bsvcPortInfo *BaseServicePortInfo) SessionAffinityType() v1.ServiceAffinity
- func (bsvcPortInfo *BaseServicePortInfo) StickyMaxAgeSeconds() int
- func (bsvcPortInfo *BaseServicePortInfo) String() string
- func (bsvcPortInfo *BaseServicePortInfo) UsesClusterEndpoints() bool
- func (bsvcPortInfo *BaseServicePortInfo) UsesLocalEndpoints() bool
- type Endpoint
- type EndpointChangeTracker
- type EndpointSliceCache
- type EndpointsMap
- type NodePodCIDRHandler
- type Provider
- type ServiceChangeTracker
- type ServiceEndpoint
- type ServicePort
- type ServicePortMap
- type ServicePortName
- type UpdateEndpointMapResult
- 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 (*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 ¶
func (info *BaseEndpointInfo) GetNodeName() string
GetNodeName returns the NodeName for this endpoint.
func (*BaseEndpointInfo) GetZone ¶
func (info *BaseEndpointInfo) GetZone() string
GetZone returns the Zone for this endpoint.
func (*BaseEndpointInfo) GetZoneHints ¶
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 ¶
func (info *BaseEndpointInfo) IsReady() bool
IsReady returns true if an endpoint is ready and not terminating.
func (*BaseEndpointInfo) IsServing ¶
func (info *BaseEndpointInfo) IsServing() bool
IsServing returns true if an endpoint is ready, regardless of if the endpoint is terminating.
func (*BaseEndpointInfo) IsTerminating ¶
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 BaseServicePortInfo ¶
type BaseServicePortInfo struct {
// contains filtered or unexported fields
}
BaseServicePortInfo 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 (*BaseServicePortInfo) ClusterIP ¶
func (bsvcPortInfo *BaseServicePortInfo) ClusterIP() net.IP
ClusterIP is part of ServicePort interface.
func (*BaseServicePortInfo) ExternalIPStrings ¶
func (bsvcPortInfo *BaseServicePortInfo) ExternalIPStrings() []string
ExternalIPStrings is part of ServicePort interface.
func (*BaseServicePortInfo) ExternalPolicyLocal ¶
func (bsvcPortInfo *BaseServicePortInfo) ExternalPolicyLocal() bool
ExternalPolicyLocal is part of ServicePort interface.
func (*BaseServicePortInfo) ExternallyAccessible ¶
func (bsvcPortInfo *BaseServicePortInfo) ExternallyAccessible() bool
ExternallyAccessible is part of ServicePort interface.
func (*BaseServicePortInfo) HealthCheckNodePort ¶
func (bsvcPortInfo *BaseServicePortInfo) HealthCheckNodePort() int
HealthCheckNodePort is part of ServicePort interface.
func (*BaseServicePortInfo) HintsAnnotation ¶
func (bsvcPortInfo *BaseServicePortInfo) HintsAnnotation() string
HintsAnnotation is part of ServicePort interface.
func (*BaseServicePortInfo) InternalPolicyLocal ¶
func (bsvcPortInfo *BaseServicePortInfo) InternalPolicyLocal() bool
InternalPolicyLocal is part of ServicePort interface
func (*BaseServicePortInfo) InternalTrafficPolicy ¶
func (bsvcPortInfo *BaseServicePortInfo) InternalTrafficPolicy() *v1.ServiceInternalTrafficPolicy
InternalTrafficPolicy is part of ServicePort interface
func (*BaseServicePortInfo) LoadBalancerIPStrings ¶
func (bsvcPortInfo *BaseServicePortInfo) LoadBalancerIPStrings() []string
LoadBalancerIPStrings is part of ServicePort interface.
func (*BaseServicePortInfo) LoadBalancerSourceRanges ¶
func (bsvcPortInfo *BaseServicePortInfo) LoadBalancerSourceRanges() []string
LoadBalancerSourceRanges is part of ServicePort interface
func (*BaseServicePortInfo) NodePort ¶
func (bsvcPortInfo *BaseServicePortInfo) NodePort() int
NodePort is part of the ServicePort interface.
func (*BaseServicePortInfo) Port ¶
func (bsvcPortInfo *BaseServicePortInfo) Port() int
Port is part of ServicePort interface.
func (*BaseServicePortInfo) Protocol ¶
func (bsvcPortInfo *BaseServicePortInfo) Protocol() v1.Protocol
Protocol is part of ServicePort interface.
func (*BaseServicePortInfo) SessionAffinityType ¶
func (bsvcPortInfo *BaseServicePortInfo) SessionAffinityType() v1.ServiceAffinity
SessionAffinityType is part of the ServicePort interface.
func (*BaseServicePortInfo) StickyMaxAgeSeconds ¶
func (bsvcPortInfo *BaseServicePortInfo) StickyMaxAgeSeconds() int
StickyMaxAgeSeconds is part of the ServicePort interface
func (*BaseServicePortInfo) String ¶
func (bsvcPortInfo *BaseServicePortInfo) String() string
String is part of ServicePort interface.
func (*BaseServicePortInfo) UsesClusterEndpoints ¶
func (bsvcPortInfo *BaseServicePortInfo) UsesClusterEndpoints() bool
UsesClusterEndpoints is part of ServicePort interface.
func (*BaseServicePortInfo) UsesLocalEndpoints ¶
func (bsvcPortInfo *BaseServicePortInfo) UsesLocalEndpoints() bool
UsesLocalEndpoints is part of ServicePort interface.
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.
func CategorizeEndpoints ¶
func CategorizeEndpoints(endpoints []Endpoint, svcInfo ServicePort, nodeLabels map[string]string) (clusterEndpoints, localEndpoints, allReachableEndpoints []Endpoint, hasAnyEndpoints bool)
CategorizeEndpoints returns:
The service's usable Cluster-traffic-policy endpoints (taking topology into account, if relevant). This will be nil if the service does not ever use Cluster traffic policy.
The service's usable Local-traffic-policy endpoints (including terminating endpoints, if relevant). This will be nil if the service does not ever use Local traffic policy.
The combined list of all endpoints reachable from this node (which is the union of the previous two lists, but in the case where it is identical to one or the other, we avoid allocating a separate list).
An indication of whether the service has any endpoints reachable from anywhere in the cluster. (This may be true even if allReachableEndpoints is empty.)
type EndpointChangeTracker ¶
type EndpointChangeTracker struct {
// contains filtered or unexported fields
}
EndpointChangeTracker carries state about uncommitted changes to an arbitrary number of Endpoints, keyed by their namespace and name.
func NewEndpointChangeTracker ¶
func NewEndpointChangeTracker(hostname string, makeEndpointInfo makeEndpointFunc, ipFamily v1.IPFamily, recorder events.EventRecorder, processEndpointsMapChange processEndpointsMapChangeFunc) *EndpointChangeTracker
NewEndpointChangeTracker initializes an EndpointsChangeMap
func (*EndpointChangeTracker) EndpointSliceUpdate ¶
func (ect *EndpointChangeTracker) EndpointSliceUpdate(endpointSlice *discovery.EndpointSlice, removeSlice bool) bool
EndpointSliceUpdate updates given service's endpoints change map based on the <previous, current> endpoints pair. It returns true if items changed, otherwise return false. Will add/update/delete items of EndpointsChangeMap. If removeSlice is true, slice will be removed, otherwise it will be added or updated.
func (*EndpointChangeTracker) PendingChanges ¶
func (ect *EndpointChangeTracker) PendingChanges() sets.Set[string]
PendingChanges returns a set whose keys are the names of the services whose endpoints have changed since the last time ect was used to update an EndpointsMap. (You must call this _before_ calling em.Update(ect).)
type EndpointSliceCache ¶
type EndpointSliceCache struct {
// contains filtered or unexported fields
}
EndpointSliceCache is used as a cache of EndpointSlice information.
func NewEndpointSliceCache ¶
func NewEndpointSliceCache(hostname string, ipFamily v1.IPFamily, recorder events.EventRecorder, makeEndpointInfo makeEndpointFunc) *EndpointSliceCache
NewEndpointSliceCache initializes an EndpointSliceCache.
type EndpointsMap ¶
type EndpointsMap map[ServicePortName][]Endpoint
EndpointsMap maps a service name to a list of all its Endpoints.
func (EndpointsMap) LocalReadyEndpoints ¶
func (em EndpointsMap) LocalReadyEndpoints() map[types.NamespacedName]int
LocalReadyEndpoints returns a map of Service names to the number of local ready endpoints for that service.
func (EndpointsMap) Update ¶
func (em EndpointsMap) Update(changes *EndpointChangeTracker) (result UpdateEndpointMapResult)
Update updates endpointsMap base on the given changes.
type NodePodCIDRHandler ¶
type NodePodCIDRHandler struct {
// contains filtered or unexported fields
}
NodePodCIDRHandler handles the life cycle of kube-proxy based on the node PodCIDR assigned Implements the config.NodeHandler interface https://issues.k8s.io/111321
func NewNodePodCIDRHandler ¶
func NewNodePodCIDRHandler(podCIDRs []string) *NodePodCIDRHandler
func (*NodePodCIDRHandler) OnNodeAdd ¶
func (n *NodePodCIDRHandler) OnNodeAdd(node *v1.Node)
OnNodeAdd is a handler for Node creates.
func (*NodePodCIDRHandler) OnNodeDelete ¶
func (n *NodePodCIDRHandler) OnNodeDelete(node *v1.Node)
OnNodeDelete is a handler for Node deletes.
func (*NodePodCIDRHandler) OnNodeSynced ¶
func (n *NodePodCIDRHandler) OnNodeSynced()
OnNodeSynced is a handler for Node syncs.
func (*NodePodCIDRHandler) OnNodeUpdate ¶
func (n *NodePodCIDRHandler) OnNodeUpdate(_, node *v1.Node)
OnNodeUpdate is a handler for Node updates.
type Provider ¶
type Provider interface { config.EndpointSliceHandler config.ServiceHandler config.NodeHandler // Sync immediately synchronizes the Provider's current state to proxy rules. Sync() // 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() }
Provider is the interface provided by proxier implementations.
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 events.EventRecorder, processServiceMapChange processServiceMapChangeFunc) *ServiceChangeTracker
NewServiceChangeTracker initializes a ServiceChangeTracker
func (*ServiceChangeTracker) PendingChanges ¶
func (sct *ServiceChangeTracker) PendingChanges() sets.Set[string]
PendingChanges returns a set whose keys are the names of the services that have changed since the last time sct was used to update a ServiceMap. (You must call this _before_ calling sm.Update(sct).)
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 ServicePort ¶
type ServicePort interface { // String returns service string. An example format can be: `IP:Port/Protocol`. String() string // ClusterIP returns service cluster IP in net.IP format. ClusterIP() net.IP // Port returns service port if present. If return 0 means not present. Port() int // SessionAffinityType returns service session affinity type SessionAffinityType() v1.ServiceAffinity // StickyMaxAgeSeconds 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 // Protocol returns service protocol. Protocol() v1.Protocol // LoadBalancerSourceRanges returns service LoadBalancerSourceRanges if present empty array if not LoadBalancerSourceRanges() []string // HealthCheckNodePort returns service health check node port if present. If return 0, it means not present. HealthCheckNodePort() int // NodePort 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.ServiceInternalTrafficPolicy // HintsAnnotation returns the value of the v1.DeprecatedAnnotationTopologyAwareHints 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 ServicePortMap ¶
type ServicePortMap map[ServicePortName]ServicePort
ServicePortMap maps a service to its ServicePort.
func (ServicePortMap) HealthCheckNodePorts ¶
func (sm ServicePortMap) HealthCheckNodePorts() map[types.NamespacedName]uint16
HealthCheckNodePorts returns a map of Service names to HealthCheckNodePort values for all Services in sm with non-zero HealthCheckNodePort.
func (ServicePortMap) Update ¶
func (sm ServicePortMap) Update(changes *ServiceChangeTracker) (result UpdateServiceMapResult)
Update updates ServicePortMap base on the given changes.
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 UpdateEndpointMapResult ¶
type UpdateEndpointMapResult struct { // DeletedUDPEndpoints identifies UDP endpoints that have just been deleted. // Existing conntrack NAT entries pointing to these endpoints must be deleted to // ensure that no further traffic for the Service gets delivered to them. DeletedUDPEndpoints []ServiceEndpoint // NewlyActiveUDPServices identifies UDP Services that have just gone from 0 to // non-0 endpoints. Existing conntrack entries caching the fact that these // services are black holes must be deleted to ensure that traffic can immediately // begin flowing to the new endpoints. NewlyActiveUDPServices []ServicePortName // List of the trigger times for all endpoints objects that changed. It's used to export the // network programming latency. // NOTE(oxddr): this can be simplified to []time.Time if memory consumption becomes an issue. LastChangeTriggerTimes map[types.NamespacedName][]time.Time }
UpdateEndpointMapResult is the updated results after applying endpoints changes.
type UpdateServiceMapResult ¶
type UpdateServiceMapResult struct { // DeletedUDPClusterIPs 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. DeletedUDPClusterIPs sets.Set[string] }
UpdateServiceMapResult is the updated results after applying service changes.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package config provides decoupling between various configuration sources (etcd, files,...) and the pieces that actually care about them (loadbalancer, proxy).
|
Package config provides decoupling between various configuration sources (etcd, files,...) and the pieces that actually care about them (loadbalancer, proxy). |
Package healthcheck provides tools for serving kube-proxy healthchecks.
|
Package healthcheck provides tools for serving kube-proxy healthchecks. |