Skip to content

Commit a19942c

Browse files
authored
Merge pull request kubernetes#88979 from liggitt/crd-watch-cache
Clarify cached object type in apiserver log
2 parents 2ede416 + a941755 commit a19942c

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

staging/src/k8s.io/apiserver/pkg/registry/generic/registry/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ go_library(
6666
"//staging/src/k8s.io/apimachinery/pkg/api/validation/path:go_default_library",
6767
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/internalversion:go_default_library",
6868
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
69+
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured:go_default_library",
6970
"//staging/src/k8s.io/apimachinery/pkg/fields:go_default_library",
7071
"//staging/src/k8s.io/apimachinery/pkg/labels:go_default_library",
7172
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",

staging/src/k8s.io/apiserver/pkg/registry/generic/registry/storage_factory.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ limitations under the License.
1717
package registry
1818

1919
import (
20+
"fmt"
2021
"sync"
2122

2223
"k8s.io/klog"
2324

25+
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2426
"k8s.io/apimachinery/pkg/runtime"
2527
"k8s.io/apiserver/pkg/registry/generic"
2628
"k8s.io/apiserver/pkg/storage"
@@ -48,11 +50,11 @@ func StorageWithCacher(capacity int) generic.StorageDecorator {
4850
return s, d, err
4951
}
5052
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()))
5254
return s, d, nil
5355
}
5456
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)
5658
}
5759

5860
// 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 {
8890
}
8991
}
9092

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+
91104
// TODO : Remove all the code below when PR
92105
// https://github.com/kubernetes/kubernetes/pull/50690
93106
// merges as that shuts down storage properly

0 commit comments

Comments
 (0)