Skip to content

Commit

Permalink
UPSTREAM: 70: Fix panic in cache informer
Browse files Browse the repository at this point in the history
  • Loading branch information
sjenning committed Sep 3, 2020
1 parent f7a4350 commit 6c96d2c
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions pkg/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
package cache

import (
"fmt"
"sync"
"time"

"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/labels"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/cache"
"k8s.io/klog"
Expand Down Expand Up @@ -118,7 +120,19 @@ func New(defaultAudience, prefix string, clientset kubernetes.Interface) Service
c.addSA(sa)
},
DeleteFunc: func(obj interface{}) {
sa := obj.(*v1.ServiceAccount)
sa, ok := obj.(*v1.ServiceAccount)
if !ok {
tombstone, ok := obj.(cache.DeletedFinalStateUnknown)
if !ok {
utilruntime.HandleError(fmt.Errorf("couldn't get object from tombstone %+v", obj))
return
}
sa, ok = tombstone.Obj.(*v1.ServiceAccount)
if !ok {
utilruntime.HandleError(fmt.Errorf("tombstone contained object that is not a ServiceAccount %#v", obj))
return
}
}
c.pop(sa.Name, sa.Namespace)
},
UpdateFunc: func(oldObj, newObj interface{}) {
Expand Down

0 comments on commit 6c96d2c

Please sign in to comment.