From bd0a17b30a3fdd5c3b4ca6550b128e24fbf8d069 Mon Sep 17 00:00:00 2001 From: Kit Patella Date: Mon, 28 Oct 2024 15:43:04 -0700 Subject: [PATCH 1/2] add logger to package list Signed-off-by: Kit Patella --- src/cmd/package.go | 4 ++++ src/pkg/cluster/cluster.go | 3 +++ 2 files changed, 7 insertions(+) diff --git a/src/cmd/package.go b/src/cmd/package.go index 91b46a2243..c5f1181b36 100644 --- a/src/cmd/package.go +++ b/src/cmd/package.go @@ -249,12 +249,14 @@ var packageListCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, _ []string) error { timeoutCtx, cancel := context.WithTimeout(cmd.Context(), cluster.DefaultTimeout) defer cancel() + // FIXME(mkcp): Add logger c, err := cluster.NewClusterWithWait(timeoutCtx) if err != nil { return err } ctx := cmd.Context() + // FIXME(mkcp): Add logger deployedZarfPackages, err := c.GetDeployedZarfPackages(ctx) if err != nil && len(deployedZarfPackages) == 0 { return fmt.Errorf("unable to get the packages deployed to the cluster: %w", err) @@ -275,8 +277,10 @@ var packageListCmd = &cobra.Command{ }) } + // NOTE(mkcp): Renders table with message. header := []string{"Package", "Version", "Components"} message.Table(header, packageData) + logger.From(ctx).Info("package info retrieved", "packageData", packageData) // Print out any unmarshalling errors if err != nil { diff --git a/src/pkg/cluster/cluster.go b/src/pkg/cluster/cluster.go index a97b3066bc..73557c4ce2 100644 --- a/src/pkg/cluster/cluster.go +++ b/src/pkg/cluster/cluster.go @@ -18,6 +18,7 @@ import ( "github.com/avast/retry-go/v4" + "github.com/zarf-dev/zarf/src/pkg/logger" "github.com/zarf-dev/zarf/src/pkg/message" "k8s.io/client-go/dynamic" "k8s.io/client-go/tools/clientcmd" @@ -40,8 +41,10 @@ type Cluster struct { // NewClusterWithWait creates a new Cluster instance and waits for the given timeout for the cluster to be ready. func NewClusterWithWait(ctx context.Context) (*Cluster, error) { + l := logger.From(ctx) spinner := message.NewProgressSpinner("Waiting for cluster connection") defer spinner.Stop() + l.Info("waiting for cluster connection") c, err := NewCluster() if err != nil { From 3ff886b797906fa9a9dc3a69ddfce18a999004be Mon Sep 17 00:00:00 2001 From: Kit Patella Date: Mon, 28 Oct 2024 16:00:24 -0700 Subject: [PATCH 2/2] keep listing packages with message table Signed-off-by: Kit Patella --- src/cmd/package.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cmd/package.go b/src/cmd/package.go index c5f1181b36..22e866cdbf 100644 --- a/src/cmd/package.go +++ b/src/cmd/package.go @@ -249,14 +249,12 @@ var packageListCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, _ []string) error { timeoutCtx, cancel := context.WithTimeout(cmd.Context(), cluster.DefaultTimeout) defer cancel() - // FIXME(mkcp): Add logger c, err := cluster.NewClusterWithWait(timeoutCtx) if err != nil { return err } ctx := cmd.Context() - // FIXME(mkcp): Add logger deployedZarfPackages, err := c.GetDeployedZarfPackages(ctx) if err != nil && len(deployedZarfPackages) == 0 { return fmt.Errorf("unable to get the packages deployed to the cluster: %w", err) @@ -279,8 +277,10 @@ var packageListCmd = &cobra.Command{ // NOTE(mkcp): Renders table with message. header := []string{"Package", "Version", "Components"} + // HACK(mkcp): Similar to `package inspect`, we do want to use message here but we have to make sure our feature + // flagging doesn't disable this. Nothing happens after this so it's safe, but still very hacky. + message.InitializePTerm(logger.DestinationDefault) message.Table(header, packageData) - logger.From(ctx).Info("package info retrieved", "packageData", packageData) // Print out any unmarshalling errors if err != nil {