Skip to content

feat: stream deployment logs with --follow flag #51

@omattsson

Description

@omattsson

Problem

When running stackctl stack deploy or watching a running deployment, users can only fetch logs after the operation completes via stackctl stack history. There is no way to tail logs in real-time from the CLI.

Context

The k8s-stack-manager backend now streams deployment logs in real-time via WebSocket (see k8s-stack-manager#126, PR #188). WebSocket message types:

  • deployment.log{instance_id, log_id, line} — per-line Helm output
  • deployment.status{instance_id, status, log_id, error_message} — state transitions

Proposed Solution

Add a --follow / -f flag to relevant commands that connects to the WebSocket endpoint and streams log lines to stdout in real-time:

# Stream logs for a running deploy
stackctl stack logs <instance> --follow

# Deploy and stream logs until completion
stackctl stack deploy <instance> --follow

# Also useful for stop/clean/rollback
stackctl stack stop <instance> --follow

Implementation Details

  • Use gorilla/websocket (or similar) client to connect to the existing /ws endpoint
  • Authenticate with the same JWT token used for REST calls
  • Filter deployment.log messages by instance_id
  • Print each line to stdout as received
  • On deployment.status with terminal state (running, stopped, error, draft), disconnect and exit with appropriate exit code
  • --follow on deploy/stop/clean/rollback should trigger the operation via REST first, then attach to the WebSocket stream

Exit codes

  • 0: operation completed successfully
  • 1: operation failed (error status)
  • 130: interrupted (Ctrl+C)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions