Skip to content

Commit

Permalink
Revert "feat: add ssh foreground"
Browse files Browse the repository at this point in the history
This reverts commit b80e282.
  • Loading branch information
wencaiwulue committed Oct 13, 2023
1 parent b80e282 commit 7d92b06
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 393 deletions.
83 changes: 0 additions & 83 deletions cmd/kubevpn/cmds/connect-fork.go

This file was deleted.

53 changes: 29 additions & 24 deletions cmd/kubevpn/cmds/connect.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package cmds

import (
"context"
"fmt"
"io"
"os"
"time"

log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -61,46 +63,49 @@ func CmdConnect(f cmdutil.Factory) *cobra.Command {

SshJump: sshConf.ToRPC(),
TransferImage: transferImage,
Foreground: foreground,
Image: config.Image,
Level: int32(log.DebugLevel),
}
// if is foreground, send to sudo daemon server
if foreground {
cli := daemon.GetClient(true)
resp, err := cli.ConnectFork(cmd.Context(), req)
if err != nil {
cli := daemon.GetClient(false)
resp, err := cli.Connect(cmd.Context(), req)
if err != nil {
return err
}
for {
recv, err := resp.Recv()
if err == io.EOF {
break
} else if code := status.Code(err); code == codes.DeadlineExceeded || code == codes.Canceled {
return nil
} else if err != nil {
return err
}
for {
recv, err := resp.Recv()
if err == io.EOF {
break
} else if code := status.Code(err); code == codes.DeadlineExceeded || code == codes.Canceled {
return nil
} else if err != nil {
return err
}
fmt.Fprint(os.Stdout, recv.GetMessage())
}
} else {
cli := daemon.GetClient(false)
resp, err := cli.Connect(cmd.Context(), req)
fmt.Fprint(os.Stdout, recv.GetMessage())
}
util.Print(os.Stdout, "Now you can access resources in the kubernetes cluster, enjoy it :)")
// hangup
if foreground {
// disconnect from cluster network
<-cmd.Context().Done()

now := time.Now()
stream, err := cli.Disconnect(context.Background(), &rpc.DisconnectRequest{})
fmt.Printf("call api disconnect use %s\n", time.Now().Sub(now).String())
if err != nil {
return err
}
var resp *rpc.DisconnectResponse
for {
recv, err := resp.Recv()
resp, err = stream.Recv()
if err == io.EOF {
break
return nil
} else if code := status.Code(err); code == codes.DeadlineExceeded || code == codes.Canceled {
return nil
} else if err != nil {
return err
}
fmt.Fprint(os.Stdout, recv.GetMessage())
fmt.Fprint(os.Stdout, resp.Message)
}
util.Print(os.Stdout, "Now you can access resources in the kubernetes cluster, enjoy it :)")
}
return nil
},
Expand Down
1 change: 0 additions & 1 deletion cmd/kubevpn/cmds/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ func NewKubeVPNCommand() *cobra.Command {
Message: "Develop commands:",
Commands: []*cobra.Command{
CmdConnect(factory),
CmdConnectFork(factory),
CmdDisconnect(factory),
CmdProxy(factory),
CmdLeave(factory),
Expand Down
105 changes: 0 additions & 105 deletions pkg/daemon/action/connect-fork.go

This file was deleted.

Loading

0 comments on commit 7d92b06

Please sign in to comment.