mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 19:01:49 +00:00
Merge pull request #88979 from liggitt/crd-watch-cache
Clarify cached object type in apiserver log
This commit is contained in:
commit
a19942cbd7
@ -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",
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user