summaryrefslogtreecommitdiff
path: root/vendor/k8s.io/kubernetes/pkg/proxy/service.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/k8s.io/kubernetes/pkg/proxy/service.go')
-rw-r--r--vendor/k8s.io/kubernetes/pkg/proxy/service.go60
1 files changed, 27 insertions, 33 deletions
diff --git a/vendor/k8s.io/kubernetes/pkg/proxy/service.go b/vendor/k8s.io/kubernetes/pkg/proxy/service.go
index ab8e6fa5d..72ff1c52a 100644
--- a/vendor/k8s.io/kubernetes/pkg/proxy/service.go
+++ b/vendor/k8s.io/kubernetes/pkg/proxy/service.go
@@ -327,35 +327,18 @@ func (sct *ServiceChangeTracker) Update(previous, current *v1.Service) bool {
return len(sct.items) > 0
}
-// 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 (sct *ServiceChangeTracker) PendingChanges() sets.String {
- sct.lock.Lock()
- defer sct.lock.Unlock()
-
- changes := sets.NewString()
- for name := range sct.items {
- changes.Insert(name.String())
- }
- return changes
-}
-
// UpdateServiceMapResult is the updated results after applying service changes.
type UpdateServiceMapResult struct {
+ // UpdatedServices lists the names of all services added/updated/deleted since the
+ // last Update.
+ UpdatedServices sets.Set[types.NamespacedName]
+
// 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.String
}
-// Update updates ServicePortMap base on the given changes.
-func (sm ServicePortMap) Update(changes *ServiceChangeTracker) (result UpdateServiceMapResult) {
- result.DeletedUDPClusterIPs = sets.NewString()
- sm.apply(changes, result.DeletedUDPClusterIPs)
- return result
-}
-
// HealthCheckNodePorts returns a map of Service names to HealthCheckNodePort values
// for all Services in sm with non-zero HealthCheckNodePort.
func (sm ServicePortMap) HealthCheckNodePorts() map[types.NamespacedName]uint16 {
@@ -405,24 +388,35 @@ func (sct *ServiceChangeTracker) serviceToServiceMap(service *v1.Service) Servic
return svcPortMap
}
-// apply the changes to ServicePortMap and update the deleted UDP cluster IP set.
-// apply triggers processServiceMapChange on every change.
-func (sm *ServicePortMap) apply(changes *ServiceChangeTracker, deletedUDPClusterIPs sets.String) {
- changes.lock.Lock()
- defer changes.lock.Unlock()
- for _, change := range changes.items {
- if changes.processServiceMapChange != nil {
- changes.processServiceMapChange(change.previous, change.current)
+// Update updates ServicePortMap base on the given changes, returns information about the
+// diff since the last Update, triggers processServiceMapChange on every change, and
+// clears the changes map.
+func (sm ServicePortMap) Update(sct *ServiceChangeTracker) UpdateServiceMapResult {
+ sct.lock.Lock()
+ defer sct.lock.Unlock()
+
+ result := UpdateServiceMapResult{
+ UpdatedServices: sets.New[types.NamespacedName](),
+ DeletedUDPClusterIPs: sets.NewString(),
+ }
+
+ for nn, change := range sct.items {
+ if sct.processServiceMapChange != nil {
+ sct.processServiceMapChange(change.previous, change.current)
}
+ result.UpdatedServices.Insert(nn)
+
sm.merge(change.current)
- // filter out the Update event of current changes from previous changes before calling unmerge() so that can
- // skip deleting the Update events.
+ // filter out the Update event of current changes from previous changes
+ // before calling unmerge() so that can skip deleting the Update events.
change.previous.filter(change.current)
- sm.unmerge(change.previous, deletedUDPClusterIPs)
+ sm.unmerge(change.previous, result.DeletedUDPClusterIPs)
}
// clear changes after applying them to ServicePortMap.
- changes.items = make(map[types.NamespacedName]*serviceChange)
+ sct.items = make(map[types.NamespacedName]*serviceChange)
metrics.ServiceChangesPending.Set(0)
+
+ return result
}
// merge adds other ServicePortMap's elements to current ServicePortMap.