mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-10 04:27:54 +00:00
Add DeletionHandlingObjectToName
Signed-off-by: Mike Spreitzer <mspreitz@us.ibm.com>
This commit is contained in:
parent
7811ba3d4d
commit
d60a25b2db
@ -336,6 +336,16 @@ func DeletionHandlingMetaNamespaceKeyFunc(obj interface{}) (string, error) {
|
||||
return MetaNamespaceKeyFunc(obj)
|
||||
}
|
||||
|
||||
// DeletionHandlingObjectToName checks for
|
||||
// DeletedFinalStateUnknown objects before calling
|
||||
// ObjectToName.
|
||||
func DeletionHandlingObjectToName(obj interface{}) (ObjectName, error) {
|
||||
if d, ok := obj.(DeletedFinalStateUnknown); ok {
|
||||
return ParseObjectName(d.Key)
|
||||
}
|
||||
return ObjectToName(obj)
|
||||
}
|
||||
|
||||
// NewInformer returns a Store and a controller for populating the store
|
||||
// while also providing event notifications. You should only used the returned
|
||||
// Store for Get/List operations; Add/Modify/Deletes will cause the event
|
||||
|
@ -574,3 +574,31 @@ func TestTransformingInformer(t *testing.T) {
|
||||
|
||||
close(stopCh)
|
||||
}
|
||||
|
||||
func TestDeletionHandlingObjectToName(t *testing.T) {
|
||||
cm := &v1.ConfigMap{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "testname",
|
||||
Namespace: "testnamespace",
|
||||
},
|
||||
}
|
||||
stringKey, err := MetaNamespaceKeyFunc(cm)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
deleted := DeletedFinalStateUnknown{
|
||||
Key: stringKey,
|
||||
Obj: cm,
|
||||
}
|
||||
expected, err := ObjectToName(cm)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
actual, err := DeletionHandlingObjectToName(deleted)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if expected != actual {
|
||||
t.Errorf("Expected %#v, got %#v", expected, actual)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user