@@ -17,10 +17,12 @@ limitations under the License.
17
17
package registry
18
18
19
19
import (
20
+ "fmt"
20
21
"sync"
21
22
22
23
"k8s.io/klog"
23
24
25
+ "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
24
26
"k8s.io/apimachinery/pkg/runtime"
25
27
"k8s.io/apiserver/pkg/registry/generic"
26
28
"k8s.io/apiserver/pkg/storage"
@@ -48,11 +50,11 @@ func StorageWithCacher(capacity int) generic.StorageDecorator {
48
50
return s , d , err
49
51
}
50
52
if capacity <= 0 {
51
- klog .V (5 ).Infof ("Storage caching is disabled for %T " , newFunc ())
53
+ klog .V (5 ).Infof ("Storage caching is disabled for %s " , objectTypeToString ( newFunc () ))
52
54
return s , d , nil
53
55
}
54
56
if klog .V (5 ) {
55
- klog .Infof ("Storage caching is enabled for %T with capacity %v" , newFunc (), capacity )
57
+ klog .Infof ("Storage caching is enabled for %s with capacity %v" , objectTypeToString ( newFunc () ), capacity )
56
58
}
57
59
58
60
// TODO: we would change this later to make storage always have cacher and hide low level KV layer inside.
@@ -88,6 +90,17 @@ func StorageWithCacher(capacity int) generic.StorageDecorator {
88
90
}
89
91
}
90
92
93
+ func objectTypeToString (obj runtime.Object ) string {
94
+ // special-case unstructured objects that tell us their apiVersion/kind
95
+ if u , isUnstructured := obj .(* unstructured.Unstructured ); isUnstructured {
96
+ if apiVersion , kind := u .GetAPIVersion (), u .GetKind (); len (apiVersion ) > 0 && len (kind ) > 0 {
97
+ return fmt .Sprintf ("apiVersion=%s, kind=%s" , apiVersion , kind )
98
+ }
99
+ }
100
+ // otherwise just return the type
101
+ return fmt .Sprintf ("%T" , obj )
102
+ }
103
+
91
104
// TODO : Remove all the code below when PR
92
105
// https://github.com/kubernetes/kubernetes/pull/50690
93
106
// merges as that shuts down storage properly
0 commit comments