Refactor the kpt printer package
Present
There are currently 2 copies of the printer package pkg/printer.printer and pkg/lib/kptops.packagePrinter
with the difference that the latter uses klog to print.
kpt itself never uses packagePrinter, but Porch does. The two have drifted in output in the past.
Proposal
- Create a new, exported printer implementation that can handle both cases.
- Discuss if a klog adapter should live in kpt or Porch.
- Instead of the current weird way of passing the opts to
OptPrintf, have the opts as state inside the printer object.
- Things such as the package name, image/executable name (or function ID) should be printed with every log line.
- We could include additional, client-defined metadata (key-value pairs) that could be passed to the printer. For example, request ID, user, etc. from Porch.
Example
Old
Package "wordpress/mysql":
[RUNNING] "ghcr.io/kptdev/krm-functions-catalog/set-labels:latest" on package "wordpress/mysql"
[PASS] "ghcr.io/kptdev/krm-functions-catalog/set-labels:latest" in 311ms
[Results]:
[info]: set 7 labels in total
Package "wordpress":
[RUNNING] "ghcr.io/kptdev/krm-functions-catalog/set-annotations:latest" on 2 resource(s) on package "wordpress"
[PASS] "ghcr.io/kptdev/krm-functions-catalog/set-annotations:latest" in 223ms
[Results]:
[info] metadata.annotations: set annotations: {"tier":"mysql"}
[info] metadata.annotations: set annotations: {"tier":"mysql"}
[info] spec.template.metadata.annotations: set annotations: {"tier":"mysql"}
[RUNNING] "ghcr.io/kptdev/krm-functions-catalog/set-labels:latest" on package "wordpress"
[PASS] "ghcr.io/kptdev/krm-functions-catalog/set-labels:latest" in 204ms
[Results]:
[info]: set 14 labels in total
[RUNNING] "ghcr.io/kptdev/krm-functions-catalog/kubeconform:latest" on package "wordpress"
[PASS] "ghcr.io/kptdev/krm-functions-catalog/kubeconform:latest" in 431ms
Successfully executed 4 function(s) in 2 package(s).
New in kpt CLI (conceptually)
[RUNNING] image="set-labels" tag="latest" package="wordpress/wordpress-mysql"
[PASS] image="set-labels" tag="latest" package="wordpress/wordpress-mysql" time="311ms"
[Results]:
[info]: set 7 labels in total
[RUNNING] image="set-annotations" tag="latest" package="wordpress" resourceCount=2
[PASS] image="set-annotations" tag="latest" package="wordpress" time="223ms"
[Results]:
[info] metadata.annotations: set annotations: {"tier":"mysql"}
[info] metadata.annotations: set annotations: {"tier":"mysql"}
[info] spec.template.metadata.annotations: set annotations: {"tier":"mysql"}
[RUNNING] image="set-labels" tag="latest" package="wordpress"
[PASS] image="set-labels" tag="latest" package="wordpress" time="204ms"
[Results]:
[info]: set 14 labels in total
[RUNNING] image="kubeconform" tag="latest" package="wordpress"
[PASS] image="kubeconform" tag="latest" package="wordpress" time="431ms"
Successfully executed 4 function(s) in 2 package(s).
New in Porch (conceptually)
I0806 10:34:XX.YYYYY 1 runner.go:ZZZ] [RUNNING] image="set-labels" tag="latest" package="deployments.wordpress.wordpress-mysql.packagevariant-1" requestID="12d800e0-0ebe-4e92-8fee-3f6f58b5b59a" user="system:serviceaccount:porch-system:porch-controller"
I0806 10:34:XX.YYYYY 1 runner.go:ZZZ] [PASS] image="set-labels" tag="latest" package="deployments.wordpress.wordpress-mysql.packagevariant-1" time="311ms" requestID="12d800e0-0ebe-4e92-8fee-3f6f58b5b59a" user="system:serviceaccount:porch-system:porch-controller"
I0806 10:34:XX.YYYYY 1 runner.go:ZZZ] [Results]:
I0806 10:34:XX.YYYYY 1 runner.go:ZZZ] [info]: set 7 labels in total
I0806 10:34:XX.YYYYY 1 runner.go:ZZZ] [RUNNING] image="set-annotations" tag="latest" package="deployments.wordpress.packagevariant-1" resourceCount=2 requestID="12d800e0-0ebe-4e92-8fee-3f6f58b5b59a" user="system:serviceaccount:porch-system:porch-controller"
I0806 10:34:XX.YYYYY 1 runner.go:ZZZ] [PASS] image="set-annotations" tag="latest" package="deployments.wordpress.packagevariant-1" time="223ms" requestID="12d800e0-0ebe-4e92-8fee-3f6f58b5b59a" user="system:serviceaccount:porch-system:porch-controller"
I0806 10:34:XX.YYYYY 1 runner.go:ZZZ] [Results]:
I0806 10:34:XX.YYYYY 1 runner.go:ZZZ] [info] metadata.annotations: set annotations: {"tier":"mysql"}
I0806 10:34:XX.YYYYY 1 runner.go:ZZZ] [info] metadata.annotations: set annotations: {"tier":"mysql"}
I0806 10:34:XX.YYYYY 1 runner.go:ZZZ] [info] spec.template.metadata.annotations: set annotations: {"tier":"mysql"}
I0806 10:34:XX.YYYYY 1 runner.go:ZZZ] [RUNNING] image="set-labels" tag="latest" package="deployments.wordpress.packagevariant-1" requestID="12d800e0-0ebe-4e92-8fee-3f6f58b5b59a" user="system:serviceaccount:porch-system:porch-controller"
I0806 10:34:XX.YYYYY 1 runner.go:ZZZ] [PASS] image="set-labels" tag="latest" package="deployments.wordpress.packagevariant-1" time="204ms" requestID="12d800e0-0ebe-4e92-8fee-3f6f58b5b59a" user="system:serviceaccount:porch-system:porch-controller"
I0806 10:34:XX.YYYYY 1 runner.go:ZZZ] [Results]:
I0806 10:34:XX.YYYYY 1 runner.go:ZZZ] [info]: set 14 labels in total
I0806 10:34:XX.YYYYY 1 runner.go:ZZZ] [RUNNING] image="kubeconform" tag="latest" package="deployments.wordpress.packagevariant-1" requestID="12d800e0-0ebe-4e92-8fee-3f6f58b5b59a" user="system:serviceaccount:porch-system:porch-controller"
I0806 10:34:XX.YYYYY 1 runner.go:ZZZ] [PASS] image="kubeconform" tag="latest" package="deployments.wordpress.packagevariant-1" time="431ms" requestID="12d800e0-0ebe-4e92-8fee-3f6f58b5b59a" user="system:serviceaccount:porch-system:porch-controller"
I0806 10:34:XX.YYYYY 1 render_executor.go:ZZZ] Successfully executed 4 function(s) in 2 package(s) time="1.17s" requestID="12d800e0-0ebe-4e92-8fee-3f6f58b5b59a" user="system:serviceaccount:porch-system:porch-controller"
Refactor the kpt
printerpackagePresent
There are currently 2 copies of the printer package
pkg/printer.printerandpkg/lib/kptops.packagePrinterwith the difference that the latter uses klog to print.
kpt itself never uses
packagePrinter, but Porch does. The two have drifted in output in the past.Proposal
OptPrintf, have the opts as state inside the printer object.Example
Old
New in kpt CLI (conceptually)
New in Porch (conceptually)