Merge pull request #98287 from lala123912/log_format_registry
staging/src/k8s.io/apiserver/pkg/registry:migrate to structured logs Kubernetes-commit: b5243341053cf9f67b1a163ccfea07517755b7a8
This commit is contained in:
commit
3492629d2b
4
go.mod
4
go.mod
|
@ -41,7 +41,7 @@ require (
|
|||
k8s.io/api v0.0.0-20210619071639-0f1d05d0f338
|
||||
k8s.io/apimachinery v0.0.0-20210619071501-4713ab59dd88
|
||||
k8s.io/client-go v0.0.0-20210619071903-3fae6f05ac95
|
||||
k8s.io/component-base v0.0.0-20210620135651-d1788e4aa23f
|
||||
k8s.io/component-base v0.0.0-20210622112647-573397b706f6
|
||||
k8s.io/klog/v2 v2.9.0
|
||||
k8s.io/kube-openapi v0.0.0-20210421082810-95288971da7e
|
||||
k8s.io/utils v0.0.0-20210521133846-da695404a2bc
|
||||
|
@ -54,5 +54,5 @@ replace (
|
|||
k8s.io/api => k8s.io/api v0.0.0-20210619071639-0f1d05d0f338
|
||||
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20210619071501-4713ab59dd88
|
||||
k8s.io/client-go => k8s.io/client-go v0.0.0-20210619071903-3fae6f05ac95
|
||||
k8s.io/component-base => k8s.io/component-base v0.0.0-20210620135651-d1788e4aa23f
|
||||
k8s.io/component-base => k8s.io/component-base v0.0.0-20210622112647-573397b706f6
|
||||
)
|
||||
|
|
4
go.sum
4
go.sum
|
@ -785,8 +785,8 @@ k8s.io/apimachinery v0.0.0-20210619071501-4713ab59dd88 h1:9Qc+08Nttbg1dtl8dElWJv
|
|||
k8s.io/apimachinery v0.0.0-20210619071501-4713ab59dd88/go.mod h1:AZCsxGyiXb/4yTvUIiY+4LESjQ12B77LFrbW2xd61is=
|
||||
k8s.io/client-go v0.0.0-20210619071903-3fae6f05ac95 h1:Wp1xPF8rzpQlkLEPswI7WKJjUQosHDZuXQRXIj1T1Z8=
|
||||
k8s.io/client-go v0.0.0-20210619071903-3fae6f05ac95/go.mod h1:KdxPzTHgLRCmXpcnSOA+LaZEp8WyV8TQMVbFMTeJWIA=
|
||||
k8s.io/component-base v0.0.0-20210620135651-d1788e4aa23f h1:L0LpTzDCM1NG30SKuCFa0JzshAN5bDA63gg5/VlhMBo=
|
||||
k8s.io/component-base v0.0.0-20210620135651-d1788e4aa23f/go.mod h1:RwSvrG7yEBwMDhwYXuMGl6zz/ufmJuveaOC/GspqdRE=
|
||||
k8s.io/component-base v0.0.0-20210622112647-573397b706f6 h1:fqgjYHQo/UQtfRXsTIv6ZOCPEcdSAooyUOU8OZAmZmY=
|
||||
k8s.io/component-base v0.0.0-20210622112647-573397b706f6/go.mod h1:RwSvrG7yEBwMDhwYXuMGl6zz/ufmJuveaOC/GspqdRE=
|
||||
k8s.io/gengo v0.0.0-20200413195148-3a45101e95ac/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
|
||||
k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE=
|
||||
k8s.io/klog/v2 v2.9.0 h1:D7HV+n1V57XeZ0m6tdRkfknthUaM06VFbWldOFh8kzM=
|
||||
|
|
|
@ -50,7 +50,7 @@ func StorageWithCacher() generic.StorageDecorator {
|
|||
return s, d, err
|
||||
}
|
||||
if klog.V(5).Enabled() {
|
||||
klog.Infof("Storage caching is enabled for %s", objectTypeToString(newFunc()))
|
||||
klog.InfoS("Storage caching is enabled", objectTypeToArgs(newFunc())...)
|
||||
}
|
||||
|
||||
cacherConfig := cacherstorage.Config{
|
||||
|
@ -83,15 +83,16 @@ func StorageWithCacher() generic.StorageDecorator {
|
|||
}
|
||||
}
|
||||
|
||||
func objectTypeToString(obj runtime.Object) string {
|
||||
func objectTypeToArgs(obj runtime.Object) []interface{} {
|
||||
// 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)
|
||||
return []interface{}{"apiVersion", apiVersion, "kind", kind}
|
||||
}
|
||||
}
|
||||
|
||||
// otherwise just return the type
|
||||
return fmt.Sprintf("%T", obj)
|
||||
return []interface{}{"type", fmt.Sprintf("%T", obj)}
|
||||
}
|
||||
|
||||
// TODO : Remove all the code below when PR
|
||||
|
|
|
@ -464,7 +464,7 @@ func ShouldDeleteDuringUpdate(ctx context.Context, key string, obj, existing run
|
|||
// Used for objects that are either been finalized or have never initialized.
|
||||
func (e *Store) deleteWithoutFinalizers(ctx context.Context, name, key string, obj runtime.Object, preconditions *storage.Preconditions, options *metav1.DeleteOptions) (runtime.Object, bool, error) {
|
||||
out := e.NewFunc()
|
||||
klog.V(6).Infof("going to delete %s from registry, triggered by update", name)
|
||||
klog.V(6).InfoS("Going to delete object from registry, triggered by update", "object", klog.KRef(genericapirequest.NamespaceValue(ctx), name))
|
||||
// Using the rest.ValidateAllObjectFunc because the request is an UPDATE request and has already passed the admission for the UPDATE verb.
|
||||
if err := e.Storage.Delete(ctx, key, out, preconditions, rest.ValidateAllObjectFunc, dryrun.IsDryRun(options.DryRun), nil); err != nil {
|
||||
// Deletion is racy, i.e., there could be multiple update
|
||||
|
@ -935,7 +935,8 @@ func (e *Store) updateForGracefulDeletionAndFinalizers(ctx context.Context, name
|
|||
if !graceful {
|
||||
// set the DeleteGracePeriods to 0 if the object has pendingFinalizers but not supporting graceful deletion
|
||||
if pendingFinalizers {
|
||||
klog.V(6).Infof("update the DeletionTimestamp to \"now\" and GracePeriodSeconds to 0 for object %s, because it has pending finalizers", name)
|
||||
klog.V(6).InfoS("Object has pending finalizers, so the registry is going to update its status to deleting",
|
||||
"object", klog.KRef(genericapirequest.NamespaceValue(ctx), name), "gracePeriod", time.Second*0)
|
||||
err = markAsDeleting(existing, time.Now())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -1055,7 +1056,7 @@ func (e *Store) Delete(ctx context.Context, name string, deleteValidation rest.V
|
|||
}
|
||||
|
||||
// delete immediately, or no graceful deletion supported
|
||||
klog.V(6).Infof("going to delete %s from registry: ", name)
|
||||
klog.V(6).InfoS("Going to delete object from registry", "object", klog.KRef(genericapirequest.NamespaceValue(ctx), name))
|
||||
out = e.NewFunc()
|
||||
if err := e.Storage.Delete(ctx, key, out, &preconditions, storage.ValidateObjectFunc(deleteValidation), dryrun.IsDryRun(options.DryRun), nil); err != nil {
|
||||
// Please refer to the place where we set ignoreNotFound for the reason
|
||||
|
@ -1148,7 +1149,7 @@ func (e *Store) DeleteCollection(ctx context.Context, deleteValidation rest.Vali
|
|||
return
|
||||
}
|
||||
if _, _, err := e.Delete(ctx, accessor.GetName(), deleteValidation, options); err != nil && !apierrors.IsNotFound(err) {
|
||||
klog.V(4).Infof("Delete %s in DeleteCollection failed: %v", accessor.GetName(), err)
|
||||
klog.V(4).InfoS("Delete object in DeleteCollection failed", "object", klog.KObj(accessor), "err", err)
|
||||
errs <- err
|
||||
return
|
||||
}
|
||||
|
@ -1425,12 +1426,12 @@ func (e *Store) CompleteWithOptions(options *generic.StoreOptions) error {
|
|||
func (e *Store) startObservingCount(period time.Duration) func() {
|
||||
prefix := e.KeyRootFunc(genericapirequest.NewContext())
|
||||
resourceName := e.DefaultQualifiedResource.String()
|
||||
klog.V(2).Infof("Monitoring %v count at <storage-prefix>/%v", resourceName, prefix)
|
||||
klog.V(2).InfoS("Monitoring resource count at path", "resource", resourceName, "path", "<storage-prefix>/"+prefix)
|
||||
stopCh := make(chan struct{})
|
||||
go wait.JitterUntil(func() {
|
||||
count, err := e.Storage.Count(prefix)
|
||||
if err != nil {
|
||||
klog.V(5).Infof("Failed to update storage count metric: %v", err)
|
||||
klog.V(5).InfoS("Failed to update storage count metric", "err", err)
|
||||
metrics.UpdateObjectCount(resourceName, -1)
|
||||
} else {
|
||||
metrics.UpdateObjectCount(resourceName, count)
|
||||
|
|
Loading…
Reference in New Issue