refactor(printer): unify stateful context-aware printer (#4698) - #4724
Open
SurbhiAgarwal1 wants to merge 1 commit into
Open
refactor(printer): unify stateful context-aware printer (#4698)#4724SurbhiAgarwal1 wants to merge 1 commit into
SurbhiAgarwal1 wants to merge 1 commit into
Conversation
- 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>
SurbhiAgarwal1
requested review from
efiacor,
kispaljr,
liamfallon and
mozesl-nokia
as code owners
September 1, 2026 14:11
✅ Deploy Preview for kptdocs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Currently, there are two separate printer implementations in the codebase:
pkg/printer(used by thekptCLI) andpkg/lib/kptops.packagePrinter(used by Porch viaklog). 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
Printerinterface inpkg/printer.Motivation
kptCLI and Porch by providing a single source of truth for package printing logic.WithField,WithFields,WithPackage,WithFunction) so metadata (e.g.image="set-labels" tag="latest" package="wordpress") is attached cleanly across log lines.PrintRunning,PrintPass,PrintFail,PrintResult,PrintSummary).packagePrinterinpkg/lib/kptops/render.goand provides a reusableFakePrinterfor unit testing across packages.Key Changes
Printerinterface inpkg/printer.WithField,WithFields,WithPackage, andWithFunction.PrintRunning,PrintPass,PrintFail,PrintResult,PrintSummary).packagePrinterimplementation inpkg/lib/kptops/render.go.Fixes #4698