From af6a7f6d1753afb71b8fa5e7ea2a6fb781d32066 Mon Sep 17 00:00:00 2001 From: hzxuzhonghu Date: Mon, 28 Aug 2017 14:49:13 +0800 Subject: [PATCH] fix Type transform panic --- core/pkg/ingress/annotations/alias/main.go | 2 +- .../annotations/clientbodybuffersize/main.go | 2 +- core/pkg/ingress/controller/controller.go | 30 +++++++++++++++++-- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/core/pkg/ingress/annotations/alias/main.go b/core/pkg/ingress/annotations/alias/main.go index ddfbab208..3f22f41e8 100644 --- a/core/pkg/ingress/annotations/alias/main.go +++ b/core/pkg/ingress/annotations/alias/main.go @@ -38,4 +38,4 @@ func NewParser() parser.IngressAnnotation { // used to add an alias to the provided hosts func (a alias) Parse(ing *extensions.Ingress) (interface{}, error) { return parser.GetStringAnnotation(annotation, ing) -} \ No newline at end of file +} diff --git a/core/pkg/ingress/annotations/clientbodybuffersize/main.go b/core/pkg/ingress/annotations/clientbodybuffersize/main.go index b722c484d..bf67f819f 100644 --- a/core/pkg/ingress/annotations/clientbodybuffersize/main.go +++ b/core/pkg/ingress/annotations/clientbodybuffersize/main.go @@ -38,4 +38,4 @@ func NewParser() parser.IngressAnnotation { // used to add an client-body-buffer-size to the provided locations func (a clientBodyBufferSize) Parse(ing *extensions.Ingress) (interface{}, error) { return parser.GetStringAnnotation(annotation, ing) -} \ No newline at end of file +} diff --git a/core/pkg/ingress/controller/controller.go b/core/pkg/ingress/controller/controller.go index 96cbfbe8b..979bce2a5 100644 --- a/core/pkg/ingress/controller/controller.go +++ b/core/pkg/ingress/controller/controller.go @@ -187,7 +187,20 @@ func newIngressController(config *Configuration) *GenericController { ic.syncQueue.Enqueue(obj) }, DeleteFunc: func(obj interface{}) { - delIng := obj.(*extensions.Ingress) + delIng, ok := obj.(*extensions.Ingress) + if !ok { + // If we reached here it means the ingress was deleted but its final state is unrecorded. + tombstone, ok := obj.(cache.DeletedFinalStateUnknown) + if !ok { + glog.Errorf("couldn't get object from tombstone %#v", obj) + return + } + delIng, ok = tombstone.Obj.(*extensions.Ingress) + if !ok { + glog.Errorf("Tombstone contained object that is not an Ingress: %#v", obj) + return + } + } if !class.IsValid(delIng, ic.cfg.IngressClass, ic.cfg.DefaultIngressClass) { glog.Infof("ignoring delete for ingress %v based on annotation %v", delIng.Name, class.IngressKey) return @@ -223,7 +236,20 @@ func newIngressController(config *Configuration) *GenericController { } }, DeleteFunc: func(obj interface{}) { - sec := obj.(*api.Secret) + sec, ok := obj.(*api.Secret) + if !ok { + // If we reached here it means the secret was deleted but its final state is unrecorded. + tombstone, ok := obj.(cache.DeletedFinalStateUnknown) + if !ok { + glog.Errorf("couldn't get object from tombstone %#v", obj) + return + } + sec, ok = tombstone.Obj.(*api.Secret) + if !ok { + glog.Errorf("Tombstone contained object that is not a Secret: %#v", obj) + return + } + } key := fmt.Sprintf("%v/%v", sec.Namespace, sec.Name) ic.sslCertTracker.DeleteAll(key) },