From 0861231b9fcb2fd3c506f0e84384004d0238c6a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20Gustav=20Str=C3=A5b=C3=B8?= <65334626+nilsgstrabo@users.noreply.github.com> Date: Wed, 6 Nov 2024 09:01:05 +0100 Subject: [PATCH] handle objects from cache of type DeletedFinalStateUnknown (#353) --- replicate/common/strings.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/replicate/common/strings.go b/replicate/common/strings.go index ddeed5b4..a882deac 100644 --- a/replicate/common/strings.go +++ b/replicate/common/strings.go @@ -2,13 +2,15 @@ package common import ( "fmt" - "github.com/pkg/errors" - log "github.com/sirupsen/logrus" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "reflect" "regexp" "sort" "strings" + + "github.com/pkg/errors" + log "github.com/sirupsen/logrus" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/client-go/tools/cache" ) func GetKeysFromBinaryMap(data map[string][]byte) []string { @@ -48,10 +50,13 @@ func MustGetObject(obj interface{}) metav1.Object { return nil } - if oma, ok := obj.(metav1.ObjectMetaAccessor); ok { - return oma.GetObjectMeta() - } else if o, ok := obj.(metav1.Object); ok { + switch o := obj.(type) { + case metav1.ObjectMetaAccessor: + return o.GetObjectMeta() + case metav1.Object: return o + case cache.DeletedFinalStateUnknown: + return MustGetObject(o.Obj) } panic(errors.Errorf("Unknown type: %v", reflect.TypeOf(obj)))