Add the key of the object to the log context (#1348)

* Add the key of the object to the log context

We don't log _what_ we convert, but only _what type_ it is.
And it's not very useful
So log all the stuff

* issues

* redo
This commit is contained in:
Victor Agababov 2020-05-25 12:49:47 -07:00 committed by GitHub
parent 4f178c83ca
commit 18ed8c75b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 4 deletions

View File

@ -22,12 +22,16 @@ import (
"fmt"
"go.uber.org/zap"
apixv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"knative.dev/pkg/apis"
"knative.dev/pkg/kmeta"
"knative.dev/pkg/logging"
"knative.dev/pkg/logging/logkey"
)
// Convert implements webhook.ConversionController
@ -78,8 +82,6 @@ func (r *reconciler) convert(
return ret, err
}
logger.Infof("Converting %s to version %s", formatGVK(inGVK), targetVersion)
inGK := inGVK.GroupKind()
conv, ok := r.kinds[inGK]
if !ok {
@ -109,17 +111,28 @@ func (r *reconciler) convert(
out := outZygote.DeepCopyObject().(ConvertibleObject)
hubGVK := inGVK.GroupKind().WithVersion(conv.HubVersion)
ctx = logging.WithLogger(ctx, logger.With(
logger = logger.With(
zap.String("inputType", formatGVK(inGVK)),
zap.String("outputType", formatGVK(outGVK)),
zap.String("hubType", formatGVK(hubGVK)),
))
)
// TODO(dprotaso) - potentially error on unknown fields
if err = json.Unmarshal(inRaw.Raw, &in); err != nil {
return ret, fmt.Errorf("unable to unmarshal input: %w", err)
}
if acc, err := kmeta.DeletionHandlingAccessor(in); err == nil {
// TODO: right now we don't convert any non-namespaced objects. If we ever do that
// this needs to updated to deal with it.
logger = logger.With(zap.String(logkey.Key, acc.GetNamespace()+"/"+acc.GetName()))
} else {
logger.Infof("Could not get Accessor for %s: %v", formatGK(inGVK.GroupKind()), err)
}
logger.Infof("Converting %s to version %s", formatGVK(inGVK), targetVersion)
ctx = logging.WithLogger(ctx, logger)
if inGVK.Version == conv.HubVersion {
hub = in
} else if err = hub.ConvertFrom(ctx, in); err != nil {