Merge pull request #88979 from liggitt/crd-watch-cache

Clarify cached object type in apiserver log
This commit is contained in:
Kubernetes Prow Robot 2020-03-21 05:28:43 -07:00 committed by GitHub
commit a19942cbd7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View File

@ -66,6 +66,7 @@ go_library(
"//staging/src/k8s.io/apimachinery/pkg/api/validation/path:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/api/validation/path:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/internalversion:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/apis/meta/internalversion:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/fields:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/fields:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/labels:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/labels:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",

View File

@ -17,10 +17,12 @@ limitations under the License.
package registry package registry
import ( import (
"fmt"
"sync" "sync"
"k8s.io/klog" "k8s.io/klog"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apiserver/pkg/registry/generic" "k8s.io/apiserver/pkg/registry/generic"
"k8s.io/apiserver/pkg/storage" "k8s.io/apiserver/pkg/storage"
@ -48,11 +50,11 @@ func StorageWithCacher(capacity int) generic.StorageDecorator {
return s, d, err return s, d, err
} }
if capacity <= 0 { if capacity <= 0 {
klog.V(5).Infof("Storage caching is disabled for %T", newFunc()) klog.V(5).Infof("Storage caching is disabled for %s", objectTypeToString(newFunc()))
return s, d, nil return s, d, nil
} }
if klog.V(5) { if klog.V(5) {
klog.Infof("Storage caching is enabled for %T with capacity %v", newFunc(), capacity) klog.Infof("Storage caching is enabled for %s with capacity %v", objectTypeToString(newFunc()), capacity)
} }
// TODO: we would change this later to make storage always have cacher and hide low level KV layer inside. // 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 {
} }
} }
func objectTypeToString(obj runtime.Object) string {
// special-case unstructured objects that tell us their apiVersion/kind
if u, isUnstructured := obj.(*unstructured.Unstructured); isUnstructured {
if apiVersion, kind := u.GetAPIVersion(), u.GetKind(); len(apiVersion) > 0 && len(kind) > 0 {
return fmt.Sprintf("apiVersion=%s, kind=%s", apiVersion, kind)
}
}
// otherwise just return the type
return fmt.Sprintf("%T", obj)
}
// TODO : Remove all the code below when PR // TODO : Remove all the code below when PR
// https://github.com/kubernetes/kubernetes/pull/50690 // https://github.com/kubernetes/kubernetes/pull/50690
// merges as that shuts down storage properly // merges as that shuts down storage properly