kube-proxy: do not export network programming latency for deleted enpoints.

This commit is contained in:
Janek Łukaszewicz 2019-08-14 14:00:07 +02:00
parent 4ce69dd32e
commit e52110edcd
2 changed files with 8 additions and 3 deletions

View File

@ -143,7 +143,7 @@ func getPodTriggerTime(pod *v1.Pod) (triggerTime time.Time) {
if readyCondition := podutil.GetPodReadyCondition(pod.Status); readyCondition != nil { if readyCondition := podutil.GetPodReadyCondition(pod.Status); readyCondition != nil {
triggerTime = readyCondition.LastTransitionTime.Time triggerTime = readyCondition.LastTransitionTime.Time
} }
// TODO(mm4tt): Implement missing cases: deletionTime set, pod label change // TODO(#81360): Implement missing cases: deletionTime set, pod label change
return triggerTime return triggerTime
} }

View File

@ -25,7 +25,7 @@ import (
"k8s.io/klog" "k8s.io/klog"
"k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/sets"
"k8s.io/client-go/tools/record" "k8s.io/client-go/tools/record"
@ -140,10 +140,11 @@ func (ect *EndpointChangeTracker) Update(previous, current *v1.Endpoints) bool {
change.previous = ect.endpointsToEndpointsMap(previous) change.previous = ect.endpointsToEndpointsMap(previous)
ect.items[namespacedName] = change ect.items[namespacedName] = change
} }
if t := getLastChangeTriggerTime(endpoints); !t.IsZero() { if t := getLastChangeTriggerTime(current); !t.IsZero() {
ect.lastChangeTriggerTimes[namespacedName] = ect.lastChangeTriggerTimes[namespacedName] =
append(ect.lastChangeTriggerTimes[namespacedName], t) append(ect.lastChangeTriggerTimes[namespacedName], t)
} }
change.current = ect.endpointsToEndpointsMap(current) change.current = ect.endpointsToEndpointsMap(current)
// if change.previous equal to change.current, it means no change // if change.previous equal to change.current, it means no change
if reflect.DeepEqual(change.previous, change.current) { if reflect.DeepEqual(change.previous, change.current) {
@ -165,6 +166,10 @@ func (ect *EndpointChangeTracker) Update(previous, current *v1.Endpoints) bool {
// annotation stored in the given endpoints object or the "zero" time if the annotation wasn't set // annotation stored in the given endpoints object or the "zero" time if the annotation wasn't set
// or was set incorrectly. // or was set incorrectly.
func getLastChangeTriggerTime(endpoints *v1.Endpoints) time.Time { func getLastChangeTriggerTime(endpoints *v1.Endpoints) time.Time {
// TODO(#81360): ignore case when Endpoint is deleted.
if endpoints == nil {
return time.Time{}
}
if _, ok := endpoints.Annotations[v1.EndpointsLastChangeTriggerTime]; !ok { if _, ok := endpoints.Annotations[v1.EndpointsLastChangeTriggerTime]; !ok {
// It's possible that the Endpoints object won't have the EndpointsLastChangeTriggerTime // It's possible that the Endpoints object won't have the EndpointsLastChangeTriggerTime
// annotation set. In that case return the 'zero value', which is ignored in the upstream code. // annotation set. In that case return the 'zero value', which is ignored in the upstream code.