Skip to content

Commit

Permalink
add remove message.DebugWriter passthru and add some slogs to tunnel
Browse files Browse the repository at this point in the history
Signed-off-by: Kit Patella <[email protected]>
  • Loading branch information
mkcp committed Oct 28, 2024
1 parent abfb4e7 commit 5093b36
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
3 changes: 0 additions & 3 deletions src/internal/packager2/mirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/defenseunicorns/pkg/helpers/v2"
"github.com/google/go-containerregistry/pkg/authn"
"github.com/google/go-containerregistry/pkg/crane"
"github.com/google/go-containerregistry/pkg/logs"
v1 "github.com/google/go-containerregistry/pkg/v1"

"github.com/zarf-dev/zarf/src/config"
Expand Down Expand Up @@ -57,8 +56,6 @@ func Mirror(ctx context.Context, opt MirrorOptions) error {
}

func pushImagesToRegistry(ctx context.Context, c *cluster.Cluster, pkgLayout *layout.PackageLayout, filter filters.ComponentFilterStrategy, regInfo types.RegistryInfo, noImgChecksum bool, retries int) error {
logs.Warn.SetOutput(&message.DebugWriter{})
logs.Progress.SetOutput(&message.DebugWriter{})
l := logger.From(ctx)

components, err := filter.Apply(pkgLayout.Pkg)
Expand Down
14 changes: 14 additions & 0 deletions src/pkg/cluster/tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package cluster
import (
"context"
"fmt"
"github.com/zarf-dev/zarf/src/pkg/logger"
"io"
"net/http"
"net/url"
Expand Down Expand Up @@ -393,6 +394,7 @@ func (tunnel *Tunnel) Close() {
// establish opens a tunnel to a kubernetes resource, as specified by the provided tunnel struct.
func (tunnel *Tunnel) establish(ctx context.Context) (string, error) {
var err error
l := logger.From(ctx)

// Track this locally as we may need to retry if the tunnel fails.
localPort := tunnel.localPort
Expand All @@ -405,11 +407,13 @@ func (tunnel *Tunnel) establish(ctx context.Context) (string, error) {
// is available for selection again.
if localPort == 0 {
message.Debugf("Requested local port is 0. Selecting an open port on host system")
l.Debug("requested local port is 0. Selecting an open port on host system")
localPort, err = helpers.GetAvailablePort()
if err != nil {
return "", fmt.Errorf("unable to find an available port: %w", err)
}
message.Debugf("Selected port %d", localPort)
l.Debug("selected port", "port", localPort)
globalMutex.Lock()
defer globalMutex.Unlock()
}
Expand All @@ -422,13 +426,21 @@ func (tunnel *Tunnel) establish(ctx context.Context) (string, error) {
tunnel.namespace,
)
message.Debugf(msg)
l.Debug("opening tunnel",
"localPort", localPort,
"remotePort", tunnel.remotePort,
"resourceType", tunnel.resourceType,
"resourceName", tunnel.resourceName,
"namespace", tunnel.namespace,
)

// Find the pod to port forward to
podName, err := tunnel.getAttachablePodForResource(ctx)
if err != nil {
return "", fmt.Errorf("unable to find pod attached to given resource: %w", err)
}
message.Debugf("Selected pod %s to open port forward to", podName)
l.Debug("selected pod to open port forward to", "name", podName)

// Build url to the port forward endpoint.
// Example: http://localhost:8080/api/v1/namespaces/helm/pods/tiller-deploy-9itlq/portforward.
Expand All @@ -442,6 +454,7 @@ func (tunnel *Tunnel) establish(ctx context.Context) (string, error) {
URL()

message.Debugf("Using URL %s to create portforward", portForwardCreateURL)
l.Debug("using URL to create portforward", "url", portForwardCreateURL)

// Construct the spdy client required by the client-go portforward library.
transport, upgrader, err := spdy.RoundTripperFor(tunnel.restConfig)
Expand Down Expand Up @@ -477,6 +490,7 @@ func (tunnel *Tunnel) establish(ctx context.Context) (string, error) {
tunnel.errChan = errChan

message.Debugf("Creating port forwarding tunnel at %s", url)
l.Debug("creating port forwarding tunnel", "url", url)
return url, nil
}
}
Expand Down

0 comments on commit 5093b36

Please sign in to comment.