mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-07 03:03:59 +00:00
Merge pull request #122998 from MikeSpreitzer/add-deletion-handling
Add DeletionHandlingObjectToName
This commit is contained in:
commit
6efef796f6
@ -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