Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve conversion webhook logging #1552

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/apis/build/v1beta1/build_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/build/v1beta1/buildrun_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/build/v1beta1/buildstrategy_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/build/v1beta1/clusterbuildstrategy_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions pkg/webhook/conversion/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions pkg/webhook/conversion/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand Down