Skip to content

Commit

Permalink
ssh: Add experimental --tmp flag that will create and destroy an ephe…
Browse files Browse the repository at this point in the history
…meral instance.
  • Loading branch information
nichtverstehen committed Jul 29, 2024
1 parent 943d7b1 commit d6ad87a
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions internal/cli/cmd/cluster/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"os/signal"
"strings"
"syscall"
"time"

c "github.com/containerd/console"
"github.com/mattn/go-isatty"
Expand All @@ -36,6 +37,7 @@ func NewSshCmd() *cobra.Command {
}

tag := cmd.Flags().String("unique_tag", "", "If specified, creates a instance with the specified unique tag.")
tmp := cmd.Flags().Bool("tmp", false, "If specified, a temporary instance will be created and destroyed upon disconnection.")
sshAgent := cmd.Flags().BoolP("ssh_agent", "A", false, "If specified, forwards the local SSH agent.")
user := cmd.Flags().String("user", "", "The user to connect as.")
forcePty := cmd.Flags().BoolP("force-pty", "t", false, "Force pseudo-terminal allocation.")
Expand Down Expand Up @@ -68,6 +70,21 @@ func NewSshCmd() *cobra.Command {

return InlineSsh(ctx, cluster.Cluster, sshOpts, args)
}
if *tmp {
opts := api.CreateClusterOpts{
KeepAtExit: false,
Purpose: fmt.Sprintf("Temporary instance for SSH"),
WaitClusterOpts: api.WaitClusterOpts{WaitForService: "ssh", WaitKind: "kubernetes"},
Duration: time.Minute,
}

cluster, err := api.CreateAndWaitCluster(ctx, api.Methods, opts)
if err != nil {
return err
}

return InlineSsh(ctx, cluster.Cluster, sshOpts, args)
}

cluster, args, err := SelectRunningCluster(ctx, args)
if err != nil {
Expand All @@ -84,6 +101,7 @@ func NewSshCmd() *cobra.Command {

return InlineSsh(ctx, cluster, sshOpts, args)
})
cmd.Flags().MarkHidden("tmp")

return cmd
}
Expand Down

0 comments on commit d6ad87a

Please sign in to comment.