mirror of
https://github.com/kubernetes/client-go.git
synced 2025-09-17 23:57:52 +00:00
Merge pull request #122998 from MikeSpreitzer/add-deletion-handling
Add DeletionHandlingObjectToName Kubernetes-commit: 6efef796f6f3ee4825359ec4f77d2c2ee936e363
This commit is contained in:
4
go.mod
4
go.mod
@@ -25,7 +25,7 @@ require (
|
||||
golang.org/x/time v0.3.0
|
||||
google.golang.org/protobuf v1.31.0
|
||||
k8s.io/api v0.0.0-20240305172515-3bd4693ef0c1
|
||||
k8s.io/apimachinery v0.0.0-20240305011844-67cb3a878cd3
|
||||
k8s.io/apimachinery v0.0.0-20240305184051-60d24f246fed
|
||||
k8s.io/klog/v2 v2.120.1
|
||||
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340
|
||||
k8s.io/utils v0.0.0-20230726121419-3b25d923346b
|
||||
@@ -62,5 +62,5 @@ require (
|
||||
|
||||
replace (
|
||||
k8s.io/api => k8s.io/api v0.0.0-20240305172515-3bd4693ef0c1
|
||||
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20240305011844-67cb3a878cd3
|
||||
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20240305184051-60d24f246fed
|
||||
)
|
||||
|
4
go.sum
4
go.sum
@@ -159,8 +159,8 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
k8s.io/api v0.0.0-20240305172515-3bd4693ef0c1 h1:Bk1KMpe+FJvuKidoJIbw5wInLRq1xqp/wa/vU4AMCdg=
|
||||
k8s.io/api v0.0.0-20240305172515-3bd4693ef0c1/go.mod h1:vubRQCvGk3ZRs8VJewbBCTFfaSYNGtDSO4rI+Ur8d0M=
|
||||
k8s.io/apimachinery v0.0.0-20240305011844-67cb3a878cd3 h1:OQnlxechgbZid21Q0KyffHDuHHZz+G7RTGDA3SIkC+o=
|
||||
k8s.io/apimachinery v0.0.0-20240305011844-67cb3a878cd3/go.mod h1:qPsrq6INURDMMgqxK78MEuC8GzI1f2oHvfHzg5ZOa6s=
|
||||
k8s.io/apimachinery v0.0.0-20240305184051-60d24f246fed h1:ZoEl1G+hctnaQwxZtVvWEyXfLKyhdJNQE1FZgs6esbQ=
|
||||
k8s.io/apimachinery v0.0.0-20240305184051-60d24f246fed/go.mod h1:qPsrq6INURDMMgqxK78MEuC8GzI1f2oHvfHzg5ZOa6s=
|
||||
k8s.io/klog/v2 v2.120.1 h1:QXU6cPEOIslTGvZaXvFWiP9VKyeet3sawzTOvdXb4Vw=
|
||||
k8s.io/klog/v2 v2.120.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
|
||||
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 h1:BZqlfIlq5YbRMFko6/PM7FjZpUb45WallggurYhKGag=
|
||||
|
10
tools/cache/controller.go
vendored
10
tools/cache/controller.go
vendored
@@ -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
|
||||
|
28
tools/cache/controller_test.go
vendored
28
tools/cache/controller_test.go
vendored
@@ -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)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user