From 4d6f6016f9b0e8117147ab6d8ed31900d86e314e Mon Sep 17 00:00:00 2001 From: encalada Date: Wed, 20 Mar 2024 13:32:16 +0100 Subject: [PATCH] Improve conversion webhook logging Ensure Info log is kept to a minimal Ensure log content is valuable: - provide conversion request UID - provide conversion response UID and status --- pkg/apis/build/v1beta1/build_conversion.go | 4 ++-- pkg/apis/build/v1beta1/buildrun_conversion.go | 4 ++-- pkg/apis/build/v1beta1/buildstrategy_conversion.go | 4 ++-- pkg/apis/build/v1beta1/clusterbuildstrategy_conversion.go | 4 ++-- pkg/webhook/conversion/conversion.go | 5 +++-- pkg/webhook/conversion/converter.go | 3 +-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/pkg/apis/build/v1beta1/build_conversion.go b/pkg/apis/build/v1beta1/build_conversion.go index 55a0b98fb2..21b442007e 100644 --- a/pkg/apis/build/v1beta1/build_conversion.go +++ b/pkg/apis/build/v1beta1/build_conversion.go @@ -27,7 +27,7 @@ var _ webhook.Conversion = (*Build)(nil) // ConvertTo converts this Build object to v1alpha1 format. func (src *Build) ConvertTo(ctx context.Context, obj *unstructured.Unstructured) error { - ctxlog.Debug(ctx, "Converting Build from beta to alpha", "namespace", src.Namespace, "name", src.Name) + ctxlog.Info(ctx, "converting Build from beta to alpha", "namespace", src.Namespace, "name", src.Name) var alphaBuild v1alpha1.Build @@ -75,7 +75,7 @@ func (src *Build) ConvertFrom(ctx context.Context, obj *unstructured.Unstructure ctxlog.Error(ctx, err, "failed unstructuring the convertedObject") } - ctxlog.Debug(ctx, "Converting Build from alpha to beta", "namespace", alphaBuild.Namespace, "name", alphaBuild.Name) + ctxlog.Info(ctx, "converting Build from alpha to beta", "namespace", alphaBuild.Namespace, "name", alphaBuild.Name) src.ObjectMeta = alphaBuild.ObjectMeta src.TypeMeta = alphaBuild.TypeMeta diff --git a/pkg/apis/build/v1beta1/buildrun_conversion.go b/pkg/apis/build/v1beta1/buildrun_conversion.go index 3587cd5645..7d0c2b6cad 100644 --- a/pkg/apis/build/v1beta1/buildrun_conversion.go +++ b/pkg/apis/build/v1beta1/buildrun_conversion.go @@ -21,7 +21,7 @@ var _ webhook.Conversion = (*BuildRun)(nil) // To Alpha func (src *BuildRun) ConvertTo(ctx context.Context, obj *unstructured.Unstructured) error { - ctxlog.Debug(ctx, "Converting BuildRun from beta to alpha", "namespace", src.Namespace, "name", src.Name) + ctxlog.Info(ctx, "converting BuildRun from beta to alpha", "namespace", src.Namespace, "name", src.Name) var alphaBuildRun v1alpha1.BuildRun @@ -194,7 +194,7 @@ func (src *BuildRun) ConvertFrom(ctx context.Context, obj *unstructured.Unstruct ctxlog.Error(ctx, err, "failed unstructuring the buildrun convertedObject") } - ctxlog.Debug(ctx, "Converting BuildRun from alpha to beta", "namespace", alphaBuildRun.Namespace, "name", alphaBuildRun.Name) + ctxlog.Info(ctx, "converting BuildRun from alpha to beta", "namespace", alphaBuildRun.Namespace, "name", alphaBuildRun.Name) src.ObjectMeta = alphaBuildRun.ObjectMeta src.TypeMeta = alphaBuildRun.TypeMeta diff --git a/pkg/apis/build/v1beta1/buildstrategy_conversion.go b/pkg/apis/build/v1beta1/buildstrategy_conversion.go index 1b0715faf9..7c546d50c8 100644 --- a/pkg/apis/build/v1beta1/buildstrategy_conversion.go +++ b/pkg/apis/build/v1beta1/buildstrategy_conversion.go @@ -22,7 +22,7 @@ var _ webhook.Conversion = (*BuildStrategy)(nil) // ConvertTo converts this object to its v1alpha1 equivalent func (src *BuildStrategy) ConvertTo(ctx context.Context, obj *unstructured.Unstructured) error { - ctxlog.Debug(ctx, "Converting BuildStrategy from beta to alpha", "namespace", src.Namespace, "name", src.Name) + ctxlog.Info(ctx, "converting BuildStrategy from beta to alpha", "namespace", src.Namespace, "name", src.Name) var bs v1alpha1.BuildStrategy bs.TypeMeta = src.TypeMeta @@ -154,7 +154,7 @@ func (src *BuildStrategy) ConvertFrom(ctx context.Context, obj *unstructured.Uns ctxlog.Error(ctx, err, "failed unstructuring the buildrun convertedObject") } - ctxlog.Debug(ctx, "Converting BuildStrategy from alpha to beta", "namespace", bs.Namespace, "name", bs.Name) + ctxlog.Info(ctx, "converting BuildStrategy from alpha to beta", "namespace", bs.Namespace, "name", bs.Name) src.ObjectMeta = bs.ObjectMeta src.TypeMeta = bs.TypeMeta diff --git a/pkg/apis/build/v1beta1/clusterbuildstrategy_conversion.go b/pkg/apis/build/v1beta1/clusterbuildstrategy_conversion.go index 6a15007f38..67470a309b 100644 --- a/pkg/apis/build/v1beta1/clusterbuildstrategy_conversion.go +++ b/pkg/apis/build/v1beta1/clusterbuildstrategy_conversion.go @@ -19,7 +19,7 @@ var _ webhook.Conversion = (*ClusterBuildStrategy)(nil) // ConvertTo converts this object to its v1alpha1 equivalent func (src *ClusterBuildStrategy) ConvertTo(ctx context.Context, obj *unstructured.Unstructured) error { - ctxlog.Debug(ctx, "Converting ClusterBuildStrategy from beta to alpha", "namespace", src.Namespace, "name", src.Name) + ctxlog.Info(ctx, "converting ClusterBuildStrategy from beta to alpha", "namespace", src.Namespace, "name", src.Name) var bs v1alpha1.ClusterBuildStrategy bs.TypeMeta = src.TypeMeta @@ -47,7 +47,7 @@ func (src *ClusterBuildStrategy) ConvertFrom(ctx context.Context, obj *unstructu ctxlog.Error(ctx, err, "failed unstructuring the buildrun convertedObject") } - ctxlog.Debug(ctx, "Converting ClusterBuildStrategy from alpha to beta", "namespace", cbs.Namespace, "name", cbs.Name) + ctxlog.Info(ctx, "converting ClusterBuildStrategy from alpha to beta", "namespace", cbs.Namespace, "name", cbs.Name) src.ObjectMeta = cbs.ObjectMeta src.TypeMeta = cbs.TypeMeta diff --git a/pkg/webhook/conversion/conversion.go b/pkg/webhook/conversion/conversion.go index d6229f50f3..120325407b 100644 --- a/pkg/webhook/conversion/conversion.go +++ b/pkg/webhook/conversion/conversion.go @@ -83,7 +83,7 @@ func serve(ctx context.Context, w http.ResponseWriter, r *http.Request, convert return } - ctxlog.Info(ctx, "handling request") + ctxlog.Debug(ctx, "handling request") obj, gvk, err := serializer.Decode(body, nil, nil) if err != nil { @@ -104,9 +104,10 @@ func serve(ctx context.Context, w http.ResponseWriter, r *http.Request, convert http.Error(w, msg, http.StatusBadRequest) return } + ctxlog.Info(ctx, "conversion request", "uid", convertReview.Request.UID) convertReview.Response = doConversion(ctx, convertReview.Request, convert) convertReview.Response.UID = convertReview.Request.UID - ctxlog.Info(ctx, fmt.Sprintf("sending response: %v", convertReview.Response)) + ctxlog.Info(ctx, "conversion response", "status", convertReview.Response.Result.Status, "uid", convertReview.Response.UID) convertReview.Request = &v1.ConversionRequest{} responseObj = convertReview diff --git a/pkg/webhook/conversion/converter.go b/pkg/webhook/conversion/converter.go index c7aca3317e..cdf73ae681 100644 --- a/pkg/webhook/conversion/converter.go +++ b/pkg/webhook/conversion/converter.go @@ -28,7 +28,7 @@ const ( // convertSHPCR takes an unstructured object with certain CR apiversion, parses it to a known Object type, // modify the type to a desired version of that type, and converts it back to unstructured func convertSHPCR(ctx context.Context, Object *unstructured.Unstructured, toVersion string) (*unstructured.Unstructured, metav1.Status) { - ctxlog.Info(ctx, "converting custom resource") + ctxlog.Debug(ctx, "converting custom resource") convertedObject := Object.DeepCopy() fromVersion := Object.GetAPIVersion() @@ -44,7 +44,6 @@ func convertSHPCR(ctx context.Context, Object *unstructured.Unstructured, toVers case alphaGroupVersion: if convertedObject.Object[KIND] == buildKind { - unstructured := convertedObject.UnstructuredContent() var build v1beta1.Build err := runtime.DefaultUnstructuredConverter.FromUnstructured(unstructured, &build)