Skip to content

Commit

Permalink
Merge pull request #88979 from liggitt/crd-watch-cache
Browse files Browse the repository at this point in the history
Clarify cached object type in apiserver log
  • Loading branch information
k8s-ci-robot committed Mar 21, 2020
2 parents 2ede416 + a941755 commit a19942c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ go_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/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/labels:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ limitations under the License.
package registry

import (
"fmt"
"sync"

"k8s.io/klog"

"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apiserver/pkg/registry/generic"
"k8s.io/apiserver/pkg/storage"
Expand Down Expand Up @@ -48,11 +50,11 @@ func StorageWithCacher(capacity int) generic.StorageDecorator {
return s, d, err
}
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
}
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.
Expand Down Expand Up @@ -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
// https://github.com/kubernetes/kubernetes/pull/50690
// merges as that shuts down storage properly
Expand Down

0 comments on commit a19942c

Please sign in to comment.