Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement new logger for Zarf connect #3208

Merged
merged 3 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
16 changes: 10 additions & 6 deletions src/cmd/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/zarf-dev/zarf/src/config/lang"
"github.com/zarf-dev/zarf/src/pkg/cluster"
"github.com/zarf-dev/zarf/src/pkg/logger"
"github.com/zarf-dev/zarf/src/pkg/message"
"github.com/zarf-dev/zarf/src/pkg/utils/exec"
)
Expand All @@ -25,6 +26,8 @@ var connectCmd = &cobra.Command{
Short: lang.CmdConnectShort,
Long: lang.CmdConnectLong,
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
l := logger.From(ctx)
target := ""
if len(args) > 0 {
target = args[0]
Expand All @@ -38,8 +41,6 @@ var connectCmd = &cobra.Command{
return err
}

ctx := cmd.Context()

var tunnel *cluster.Tunnel
if target == "" {
tunnel, err = c.ConnectTunnelInfo(ctx, zt)
Expand All @@ -61,14 +62,12 @@ var connectCmd = &cobra.Command{

defer tunnel.Close()

// Dump the tunnel URL to the console for other tools to use.
fmt.Print(tunnel.FullURL())
AustinAbro321 marked this conversation as resolved.
Show resolved Hide resolved

if cliOnly {
spinner.Updatef(lang.CmdConnectEstablishedCLI, tunnel.FullURL())
l.Info("Tunnel established, waiting for user to interrupt (ctrl-c to end)", "url", tunnel.FullURL())
} else {
spinner.Updatef(lang.CmdConnectEstablishedWeb, tunnel.FullURL())

l.Info("Tunnel established, opening your default web browser (ctrl-c to end)", "url", tunnel.FullURL())
if err := exec.LaunchURL(tunnel.FullURL()); err != nil {
return err
}
Expand Down Expand Up @@ -98,6 +97,11 @@ var connectListCmd = &cobra.Command{
if err != nil {
return err
}
// HACK: Re-initializing PTerm with a stderr writer isn't great, but it lets us render these
// tables for backwards compatibility
if logger.Enabled(cmd.Context()) {
message.InitializePTerm(logger.DestinationDefault)
}
message.PrintConnectStringTable(connections)
return nil
},
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/packager/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func (p *Packager) findImages(ctx context.Context) (map[string][]string, error)
for idx, k := range manifest.Kustomizations {
// Generate manifests from kustomizations and place in the package
kname := fmt.Sprintf("kustomization-%s-%d.yaml", manifest.Name, idx)
// Use the temp folder because if "helpers.CreatePathAndCopy" is provider with the same path it will result in the file being empty
// Use the temp folder because if "helpers.CreatePathAndCopy" is provided with the same path it will result in the file being empty
destination := filepath.Join(componentPaths.Temp, kname)
if err := kustomize.Build(k, destination, manifest.KustomizeAllowAnyDirectory); err != nil {
return nil, fmt.Errorf("unable to build the kustomization for %s: %w", k, err)
Expand Down