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

GCP Server AutoDiscover: only log when the script fails #51117

Merged
merged 2 commits into from
Jan 24, 2025
Merged
Changes from all 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
19 changes: 14 additions & 5 deletions lib/cloud/gcp/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,26 +574,35 @@ https://cloud.google.com/solutions/connecting-securely#storing_host_keys_by_enab
HostKeyCallback: callback,
}

loggerWithVMMetadata := slog.With(
"project_id", req.ProjectID,
"zone", req.Zone,
"vm_name", req.Name,
"ips", ipAddrs,
)

var errs []error
for _, ip := range ipAddrs {
addr := net.JoinHostPort(ip, req.SSHPort)
stdout, stderr, err := sshutils.RunSSH(ctx, addr, req.Script, config, sshutils.WithDialer(req.dialContext))
slog.DebugContext(ctx, "Command completed",
"stdoout", string(stdout),
"stderr", string(stderr),
)
if err == nil {
return nil
}

// An exit error means the connection was successful, so don't try another address.
if errors.Is(err, &ssh.ExitError{}) {
loggerWithVMMetadata.ErrorContext(ctx, "Installing teleport in GCP VM failed after connecting",
"ip", ip,
"error", err,
"stdout", string(stdout),
"stderr", string(stderr),
)
return trace.Wrap(err)
}
errs = append(errs, err)
}

err = trace.NewAggregate(errs...)
slog.DebugContext(ctx, "Command exited with error", "error", err)
loggerWithVMMetadata.ErrorContext(ctx, "Installing teleport in GCP VM failed", "error", err)
return err
}
Loading