Skip to content
Open
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
28 changes: 28 additions & 0 deletions pkg/k8s/clientset.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ package k8s

import (
"context"
"encoding/base64"
"fmt"
"log/slog"
"strings"

"k8s.io/cli-runtime/pkg/printers"

"github.com/go-errors/errors"
tektonv1beta1client "github.com/tektoncd/pipeline/pkg/client/clientset/versioned/typed/pipeline/v1beta1"
Expand Down Expand Up @@ -89,6 +95,8 @@ func (c clientSet) Apply(ctx context.Context, obj runtime.Object, namespace stri
return errors.Errorf("%s/%s: could not convert runtime object into unstructured data: %w", namespace, name, err)
}

slog.Debug("applying object", "namespace", namespace, "forceConflicts", forceConflicts, "object", lazyObjectLogValue{obj})
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just used slog here without having a broader understanding how Smithy propagates desired log levels. Happy to make changes so it aligns better with how Smithy approaches logging.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we might move this internally and remove it from the OSS this week - do you mind if we hold the change for now?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, no rush.


_, err = c.dynamicClient.
Resource(gvr.Resource).
Namespace(namespace).
Expand All @@ -113,3 +121,23 @@ func (c clientSet) Apply(ctx context.Context, obj runtime.Object, namespace stri
func (c clientSet) RESTMapper() meta.RESTMapper {
return c.restMapper
}

type lazyObjectLogValue struct {
obj runtime.Object
}

// LogValue implements the slog.LogValuer interface.
func (l lazyObjectLogValue) LogValue() slog.Value {
sb := strings.Builder{}
yamlPrinter := printers.YAMLPrinter{}

err := yamlPrinter.PrintObj(l.obj, &sb)
if err != nil {
return slog.StringValue(fmt.Sprintf("(failed to print object: %v)", err))
}

// Base64-encode the YAML to maintain indentation etc.
b64 := base64.StdEncoding.EncodeToString([]byte(sb.String()))

return slog.StringValue(b64)
}