Skip to content
Open
Show file tree
Hide file tree
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
103 changes: 52 additions & 51 deletions cmd/lk/agent.go

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions cmd/lk/agent_private_link.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,19 +209,19 @@ func createPrivateLink(ctx context.Context, cmd *cli.Command) error {
}

if resp.PrivateLink == nil {
fmt.Println("Private link created")
out.Status("Private link created")
return nil
}

fmt.Printf("Created private link [%s]\n", util.Accented(resp.PrivateLink.PrivateLinkId))
out.Statusf("Created private link [%s]", util.Accented(resp.PrivateLink.PrivateLinkId))
if resp.PrivateLink.Endpoint != "" {
fmt.Printf("Endpoint [%s]\n", util.Accented(resp.PrivateLink.Endpoint))
out.Statusf("Endpoint [%s]", util.Accented(resp.PrivateLink.Endpoint))
}
if resp.PrivateLink.ConnectionEndpoint != "" {
fmt.Printf("Gateway DNS [%s]\n", util.Accented(resp.PrivateLink.ConnectionEndpoint))
out.Statusf("Gateway DNS [%s]", util.Accented(resp.PrivateLink.ConnectionEndpoint))
}
if resp.PrivateLink.CloudRegion != "" {
fmt.Printf("Cloud Region [%s]\n", util.Accented(resp.PrivateLink.CloudRegion))
out.Statusf("Cloud Region [%s]", util.Accented(resp.PrivateLink.CloudRegion))
}
return nil
}
Expand Down Expand Up @@ -275,13 +275,13 @@ func listPrivateLinks(ctx context.Context, cmd *cli.Command) error {
}

if len(resp.Items) == 0 {
fmt.Println("No private links found")
out.Status("No private links found")
return nil
}

rows := buildPrivateLinkListRows(resp.Items, healthByID, healthErrByID)
table := util.CreateTable().Headers("ID", "Name", "Region", "Cloud Region", "Port", "Endpoint", "DNS", "Health", "Updated At", "Reason").Rows(rows...)
fmt.Println(table)
out.Result(table)
return nil
}

Expand All @@ -298,7 +298,7 @@ func deletePrivateLink(ctx context.Context, cmd *cli.Command) error {
util.PrintJSON(resp)
return nil
}
fmt.Printf("Deleted private link [%s]\n", util.Accented(privateLinkID))
out.Statusf("Deleted private link [%s]", util.Accented(privateLinkID))
return nil
}

Expand Down Expand Up @@ -328,6 +328,6 @@ func getPrivateLinkHealthStatus(ctx context.Context, cmd *cli.Command) error {
table := util.CreateTable().
Headers("ID", "Health", "Updated At", "Reason").
Row(privateLinkID, formatPrivateLinkHealthStatus(resp.Value.Status), updatedAt, reason)
fmt.Println(table)
out.Result(table)
return nil
}
10 changes: 5 additions & 5 deletions cmd/lk/agent_reload.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,21 @@ func (rs *reloadServer) captureJobs(conn net.Conn) {
},
}
if err := ipc.WriteProto(conn, req); err != nil {
fmt.Printf("reload: failed to send capture request: %v\n", err)
out.Warnf("reload: failed to send capture request: %v", err)
return
}

resp := &agent.AgentDevMessage{}
if err := ipc.ReadProto(conn, resp); err != nil {
fmt.Printf("reload: failed to read capture response: %v\n", err)
out.Warnf("reload: failed to read capture response: %v", err)
return
}

if jobs := resp.GetGetRunningJobsResponse(); jobs != nil {
rs.mu.Lock()
rs.savedJobs = jobs
rs.mu.Unlock()
fmt.Printf("reload: captured %d running job(s)\n", len(jobs.Jobs))
out.Statusf("reload: captured %d running job(s)", len(jobs.Jobs))
}
}

Expand Down Expand Up @@ -90,9 +90,9 @@ func (rs *reloadServer) serveNewProcess(conn net.Conn) {
},
}
if err := ipc.WriteProto(conn, resp); err != nil {
fmt.Printf("reload: failed to send restore response: %v\n", err)
out.Warnf("reload: failed to send restore response: %v", err)
} else if len(saved.Jobs) > 0 {
fmt.Printf("reload: restored %d job(s) to new process\n", len(saved.Jobs))
out.Statusf("reload: restored %d job(s) to new process", len(saved.Jobs))
}
}

Expand Down
18 changes: 4 additions & 14 deletions cmd/lk/agent_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package main
import (
"context"
"fmt"
"io"
"os"
"os/signal"
"path/filepath"
Expand All @@ -35,15 +34,6 @@ func init() {
AgentCommands[0].Commands = append(AgentCommands[0].Commands, startCommand, devCommand)
}

var (
outputToStderr = func(p *loadParams) {
p.output = os.Stderr
}
quietOutput = func(p *loadParams) {
p.output = io.Discard
}
)

var agentRunFlags = []cli.Flag{
&cli.StringFlag{
Name: "log-level",
Expand Down Expand Up @@ -166,9 +156,9 @@ func runAgentStart(ctx context.Context, cmd *cli.Command) error {
if err != nil {
return err
}
fmt.Fprintf(os.Stderr, "Detected %s agent (%s in %s)\n", projectType.Lang(), entrypoint, projectDir)
out.Statusf("Detected %s agent (%s in %s)", projectType.Lang(), entrypoint, projectDir)

cliArgs, err := buildCLIArgs("start", cmd, quietOutput)
cliArgs, err := buildCLIArgs("start", cmd)
if err != nil {
return err
}
Expand Down Expand Up @@ -209,7 +199,7 @@ func runAgentDev(ctx context.Context, cmd *cli.Command) error {
return err
}

cliArgs, err := buildCLIArgs("start", cmd, outputToStderr)
cliArgs, err := buildCLIArgs("start", cmd)
if err != nil {
return err
}
Expand All @@ -226,7 +216,7 @@ func runAgentDev(ctx context.Context, cmd *cli.Command) error {
ForwardOutput: os.Stdout,
}

fmt.Fprintf(os.Stderr, "Detected %s agent (%s in %s)\n", projectType.Lang(), entrypoint, projectDir)
out.Statusf("Detected %s agent (%s in %s)", projectType.Lang(), entrypoint, projectDir)

// Take over signal handling from the global NotifyContext.
signal.Reset(syscall.SIGINT, syscall.SIGTERM)
Expand Down
12 changes: 6 additions & 6 deletions cmd/lk/agent_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (aw *agentWatcher) restart() error {
aw.agent.Kill()
}

fmt.Fprintln(os.Stderr, "Reloading agent...")
out.Status("Reloading agent...")

// 3. Start new process
agent, err := startAgent(aw.config)
Expand Down Expand Up @@ -227,10 +227,10 @@ func (aw *agentWatcher) Run(done <-chan struct{}) error {
case <-debounceCh:
debounceTimer = nil
debounceCh = nil
fmt.Fprintf(os.Stderr, "File changed: %s\n", changedFile)
out.Statusf("File changed: %s", changedFile)
if err := aw.restart(); err != nil {
fmt.Fprintf(os.Stderr, "Failed to restart agent: %v\n", err)
fmt.Fprintln(os.Stderr, "Waiting for file changes...")
out.Warnf("Failed to restart agent: %v", err)
out.Status("Waiting for file changes...")
} else {
exitCh = aw.agent.exitCh
}
Expand All @@ -239,7 +239,7 @@ func (aw *agentWatcher) Run(done <-chan struct{}) error {
if !ok {
return nil
}
fmt.Fprintf(os.Stderr, "Watcher error: %v\n", err)
out.Warnf("Watcher error: %v", err)

case <-exitCh:
// Nil the channel so this case won't fire again (nil channels block forever)
Expand All @@ -250,7 +250,7 @@ func (aw *agentWatcher) Run(done <-chan struct{}) error {
debounceTimer = nil
debounceCh = nil
}
fmt.Fprintln(os.Stderr, "Agent exited. Waiting for file changes to restart...")
out.Status("Agent exited. Waiting for file changes to restart...")
}
}
}
Loading
Loading