mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-06 07:57:35 +00:00
kube-proxy: update internal endpoints map with 'serving' and 'terminating' condition from EndpointSlice
Signed-off-by: Andrew Sy Kim <kim.andrewsy@gmail.com>
This commit is contained in:
@@ -49,6 +49,23 @@ type BaseEndpointInfo struct {
|
||||
// IsLocal indicates whether the endpoint is running in same host as kube-proxy.
|
||||
IsLocal bool
|
||||
Topology map[string]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
|
||||
}
|
||||
|
||||
var _ Endpoint = &BaseEndpointInfo{}
|
||||
@@ -63,6 +80,23 @@ func (info *BaseEndpointInfo) GetIsLocal() bool {
|
||||
return info.IsLocal
|
||||
}
|
||||
|
||||
// IsReady returns true if an endpoint is ready and not terminating.
|
||||
func (info *BaseEndpointInfo) IsReady() bool {
|
||||
return info.Ready
|
||||
}
|
||||
|
||||
// IsServing returns true if an endpoint is ready, regardless of if the
|
||||
// endpoint is terminating.
|
||||
func (info *BaseEndpointInfo) IsServing() bool {
|
||||
return info.Serving
|
||||
}
|
||||
|
||||
// IsTerminating retruns true if an endpoint is terminating. For pods,
|
||||
// that is any pod with a deletion timestamp.
|
||||
func (info *BaseEndpointInfo) IsTerminating() bool {
|
||||
return info.Terminating
|
||||
}
|
||||
|
||||
// GetTopology returns the topology information of the endpoint.
|
||||
func (info *BaseEndpointInfo) GetTopology() map[string]string {
|
||||
return info.Topology
|
||||
@@ -83,11 +117,15 @@ func (info *BaseEndpointInfo) Equal(other Endpoint) bool {
|
||||
return info.String() == other.String() && info.GetIsLocal() == other.GetIsLocal()
|
||||
}
|
||||
|
||||
func newBaseEndpointInfo(IP string, port int, isLocal bool, topology map[string]string) *BaseEndpointInfo {
|
||||
func newBaseEndpointInfo(IP string, port int, isLocal bool, topology map[string]string,
|
||||
ready, serving, terminating bool) *BaseEndpointInfo {
|
||||
return &BaseEndpointInfo{
|
||||
Endpoint: net.JoinHostPort(IP, strconv.Itoa(port)),
|
||||
IsLocal: isLocal,
|
||||
Topology: topology,
|
||||
Endpoint: net.JoinHostPort(IP, strconv.Itoa(port)),
|
||||
IsLocal: isLocal,
|
||||
Topology: topology,
|
||||
Ready: ready,
|
||||
Serving: serving,
|
||||
Terminating: terminating,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -383,8 +421,14 @@ func (ect *EndpointChangeTracker) endpointsToEndpointsMap(endpoints *v1.Endpoint
|
||||
continue
|
||||
}
|
||||
|
||||
// it is safe to assume that any address in endpoints.subsets[*].addresses is
|
||||
// ready and NOT terminating
|
||||
isReady := true
|
||||
isServing := true
|
||||
isTerminating := false
|
||||
isLocal := addr.NodeName != nil && *addr.NodeName == ect.hostname
|
||||
baseEndpointInfo := newBaseEndpointInfo(addr.IP, int(port.Port), isLocal, nil)
|
||||
|
||||
baseEndpointInfo := newBaseEndpointInfo(addr.IP, int(port.Port), isLocal, nil, isReady, isServing, isTerminating)
|
||||
if ect.makeEndpointInfo != nil {
|
||||
endpointsMap[svcPortName] = append(endpointsMap[svcPortName], ect.makeEndpointInfo(baseEndpointInfo))
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user