Skip to content

refactor(printer): unify stateful context-aware printer (#4698) - #4724

Open
SurbhiAgarwal1 wants to merge 1 commit into
kptdev:mainfrom
SurbhiAgarwal1:fix/4698-refactor-kpt-printer
Open

refactor(printer): unify stateful context-aware printer (#4698)#4724
SurbhiAgarwal1 wants to merge 1 commit into
kptdev:mainfrom
SurbhiAgarwal1:fix/4698-refactor-kpt-printer

Conversation

@SurbhiAgarwal1

Copy link
Copy Markdown
Contributor

Description

Currently, there are two separate printer implementations in the codebase: pkg/printer (used by the kpt CLI) and pkg/lib/kptops.packagePrinter (used by Porch via klog). Over time, these two implementations have drifted in output format and lack a clean mechanism for attaching structured contextual metadata (such as image name, tag, package, request ID, user, and execution time).

This PR consolidates both implementations into a single, exported, stateful Printer interface in pkg/printer.

Motivation

  • Unified Output & Logging: Eliminates code duplication and output drift between kpt CLI and Porch by providing a single source of truth for package printing logic.
  • Contextual Scoping: Introduces stateful scoping methods (WithField, WithFields, WithPackage, WithFunction) so metadata (e.g. image="set-labels" tag="latest" package="wordpress") is attached cleanly across log lines.
  • Structured Lifecycle Event Handlers: Adds explicit lifecycle event methods (PrintRunning, PrintPass, PrintFail, PrintResult, PrintSummary).
  • Clean Architecture & Testability: Removes the duplicated packagePrinter in pkg/lib/kptops/render.go and provides a reusable FakePrinter for unit testing across packages.

Key Changes

  • Consolidate CLI and Porch klog printer logic into an exported Printer interface in pkg/printer.
  • Introduce stateful contextual scoping via WithField, WithFields, WithPackage, and WithFunction.
  • Provide structured lifecycle event printing (PrintRunning, PrintPass, PrintFail, PrintResult, PrintSummary).
  • Remove duplicate packagePrinter implementation in pkg/lib/kptops/render.go.
  • Add comprehensive unit tests verifying stateful field scoping and formatting.

Fixes #4698

- Consolidate CLI and Porch klog printer logic into an exported Printer interface in pkg/printer.
- Introduce stateful contextual scoping via WithField, WithFields, WithPackage, and WithFunction.
- Provide structured lifecycle event printing (PrintRunning, PrintPass, PrintFail, PrintResult, PrintSummary).
- Remove duplicate packagePrinter implementation in pkg/lib/kptops/render.go.
- Add comprehensive unit tests verifying stateful field scoping and formatting.

Signed-off-by: SurbhiAgarwal1 <surbhi.agarwal@example.com>
@netlify

netlify Bot commented Sep 1, 2026

Copy link
Copy Markdown

Deploy Preview for kptdocs ready!

Name Link
🔨 Latest commit 6abab2d
🔍 Latest deploy log https://app.netlify.com/projects/kptdocs/deploys/6a96dd2b84c56400086966e1
😎 Deploy Preview https://deploy-preview-4724--kptdocs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor the kpt printer package

1 participant