Skip to content

Commit

Permalink
Update resolver_k8s_handler.go
Browse files Browse the repository at this point in the history
Fixed an issue where span was denied due to k8s update event
  • Loading branch information
linliaoy authored Apr 20, 2024
1 parent 91227ad commit d0c0fdf
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions exporter/loadbalancingexporter/resolver_k8s_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,10 @@ func (h handler) OnUpdate(oldObj, newObj any) {
switch oldEps := oldObj.(type) {
case *corev1.Endpoints:
epRemove := convertToEndpoints(oldEps)
for _, ep := range epRemove {
h.endpoints.Delete(ep)
}
if len(epRemove) > 0 {
_, _ = h.callback(context.Background())
}

oldEpRemoveMap :=map[string]bool{}
for _,ep:=range EpRemove {
oldEpRemoveMap[ep]=true
}
newEps, ok := newObj.(*corev1.Endpoints)
if !ok {
h.logger.Warn("Got an unexpected Kubernetes data type during the update of the pods for a service", zap.Any("obj", newObj))
Expand All @@ -65,8 +62,19 @@ func (h handler) OnUpdate(oldObj, newObj any) {
if _, loaded := h.endpoints.LoadOrStore(ep, true); !loaded {
changed = true
}
if _,ok:=oldEpRemoveMap[ep];ok {
oldEpRemoveMap[ep]=false
}
}
if changed {
epDeleteNum:=0
for ep,status :=range oldEpRemoveMap{
if status {
epDeleteNum=epDeleteNum+1
h.endpoints.Delete(ep)
}
}

if ( changed || epDeleteNum > 0 ) {
_, _ = h.callback(context.Background())
}
default: // unsupported
Expand Down

0 comments on commit d0c0fdf

Please sign in to comment.