layer1: add namespace tombstone helper step 34
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"time"
|
||||
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
k8sCache "k8s.io/client-go/tools/cache"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -88,6 +89,32 @@ func NamespaceEventFromNamespace(eventType NamespaceEventType, namespace *corev1
|
||||
return NewNamespaceEvent(eventType, namespace.Name, namespace.Labels, source, observedAt)
|
||||
}
|
||||
|
||||
func NamespaceFromObject(obj interface{}) (*corev1.Namespace, bool) {
|
||||
switch typed := obj.(type) {
|
||||
case *corev1.Namespace:
|
||||
return typed, true
|
||||
case k8sCache.DeletedFinalStateUnknown:
|
||||
namespace, ok := typed.Obj.(*corev1.Namespace)
|
||||
return namespace, ok
|
||||
case *k8sCache.DeletedFinalStateUnknown:
|
||||
if typed == nil {
|
||||
return nil, false
|
||||
}
|
||||
namespace, ok := typed.Obj.(*corev1.Namespace)
|
||||
return namespace, ok
|
||||
default:
|
||||
return nil, false
|
||||
}
|
||||
}
|
||||
|
||||
func NamespaceEventFromObject(eventType NamespaceEventType, obj interface{}, source NamespaceSource, observedAt time.Time) NamespaceEvent {
|
||||
namespace, ok := NamespaceFromObject(obj)
|
||||
if !ok {
|
||||
return NewNamespaceEvent(eventType, "", nil, source, observedAt)
|
||||
}
|
||||
return NamespaceEventFromNamespace(eventType, namespace, source, observedAt)
|
||||
}
|
||||
|
||||
func (nr NamespaceRecord) Clone() NamespaceRecord {
|
||||
clone := nr
|
||||
clone.Labels = cloneStringMap(nr.Labels)
|
||||
|
||||
Reference in New Issue
Block a user