Skip to content

Commit

Permalink
hotfix: ignore print cancel GRPC msg (#399)
Browse files Browse the repository at this point in the history
  • Loading branch information
wencaiwulue authored Dec 13, 2024
1 parent f046e47 commit 6e594fa
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 4 deletions.
5 changes: 5 additions & 0 deletions cmd/kubevpn/cmds/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
pkgerr "github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
utilcomp "k8s.io/kubectl/pkg/util/completion"
"k8s.io/kubectl/pkg/util/i18n"
Expand Down Expand Up @@ -140,6 +142,9 @@ func CmdClone(f cmdutil.Factory) *cobra.Command {
}
err = util.PrintGRPCStream[rpc.CloneResponse](resp)
if err != nil {
if status.Code(err) == codes.Canceled {
return nil
}
return err
}
util.Print(os.Stdout, config.Slogan)
Expand Down
8 changes: 8 additions & 0 deletions cmd/kubevpn/cmds/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/util/i18n"
"k8s.io/kubectl/pkg/util/templates"
Expand Down Expand Up @@ -107,6 +109,9 @@ func CmdConnect(f cmdutil.Factory) *cobra.Command {
}
err = util.PrintGRPCStream[rpc.ConnectResponse](resp)
if err != nil {
if status.Code(err) == codes.Canceled {
return nil
}
return err
}
if !foreground {
Expand All @@ -124,6 +129,9 @@ func CmdConnect(f cmdutil.Factory) *cobra.Command {
}
err = util.PrintGRPCStream[rpc.DisconnectResponse](disconnect)
if err != nil {
if status.Code(err) == codes.Canceled {
return nil
}
return err
}
_, _ = fmt.Fprint(os.Stdout, "Disconnect completed")
Expand Down
5 changes: 5 additions & 0 deletions cmd/kubevpn/cmds/disconnect.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"strconv"

"github.com/spf13/cobra"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/util/i18n"
"k8s.io/kubectl/pkg/util/templates"
Expand Down Expand Up @@ -71,6 +73,9 @@ func CmdDisconnect(f cmdutil.Factory) *cobra.Command {
}
err = util.PrintGRPCStream[rpc.DisconnectResponse](client)
if err != nil {
if status.Code(err) == codes.Canceled {
return nil
}
return err
}
_, _ = fmt.Fprint(os.Stdout, "Disconnect completed")
Expand Down
10 changes: 9 additions & 1 deletion cmd/kubevpn/cmds/leave.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package cmds

import (
"github.com/spf13/cobra"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/util/i18n"
"k8s.io/kubectl/pkg/util/templates"
Expand Down Expand Up @@ -39,7 +41,13 @@ func CmdLeave(f cmdutil.Factory) *cobra.Command {
return err
}
err = util.PrintGRPCStream[rpc.LeaveResponse](leave)
return err
if err != nil {
if status.Code(err) == codes.Canceled {
return nil
}
return err
}
return nil
},
}
return leaveCmd
Expand Down
10 changes: 9 additions & 1 deletion cmd/kubevpn/cmds/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package cmds

import (
"github.com/spf13/cobra"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/util/i18n"
"k8s.io/kubectl/pkg/util/templates"
Expand Down Expand Up @@ -36,7 +38,13 @@ func CmdLogs(f cmdutil.Factory) *cobra.Command {
return err
}
err = util.PrintGRPCStream[rpc.LogResponse](client)
return err
if err != nil {
if status.Code(err) == codes.Canceled {
return nil
}
return err
}
return nil
},
}
cmd.Flags().BoolVarP(&req.Follow, "follow", "f", false, "Specify if the logs should be streamed.")
Expand Down
8 changes: 8 additions & 0 deletions cmd/kubevpn/cmds/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (

log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
utilcomp "k8s.io/kubectl/pkg/util/completion"
"k8s.io/kubectl/pkg/util/i18n"
Expand Down Expand Up @@ -138,6 +140,9 @@ func CmdProxy(f cmdutil.Factory) *cobra.Command {
}
err = util.PrintGRPCStream[rpc.ConnectResponse](client)
if err != nil {
if status.Code(err) == codes.Canceled {
return nil
}
return err
}
util.Print(os.Stdout, config.Slogan)
Expand All @@ -154,6 +159,9 @@ func CmdProxy(f cmdutil.Factory) *cobra.Command {
}
err = util.PrintGRPCStream[rpc.LeaveResponse](stream)
if err != nil {
if status.Code(err) == codes.Canceled {
return nil
}
return err
}
}
Expand Down
5 changes: 5 additions & 0 deletions cmd/kubevpn/cmds/quit.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"os"

"github.com/spf13/cobra"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/util/i18n"
"k8s.io/kubectl/pkg/util/templates"
Expand Down Expand Up @@ -48,6 +50,9 @@ func quit(ctx context.Context, isSudo bool) error {
}
err = util.PrintGRPCStream[rpc.QuitResponse](client)
if err != nil {
if status.Code(err) == codes.Canceled {
return nil
}
return err
}
return nil
Expand Down
10 changes: 9 additions & 1 deletion cmd/kubevpn/cmds/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package cmds

import (
"github.com/spf13/cobra"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/util/i18n"
"k8s.io/kubectl/pkg/util/templates"
Expand Down Expand Up @@ -37,7 +39,13 @@ func CmdRemove(f cmdutil.Factory) *cobra.Command {
return err
}
err = util.PrintGRPCStream[rpc.RemoveResponse](leave)
return err
if err != nil {
if status.Code(err) == codes.Canceled {
return nil
}
return err
}
return nil
},
}
return cmd
Expand Down
10 changes: 9 additions & 1 deletion cmd/kubevpn/cmds/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package cmds
import (
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/util/i18n"
"k8s.io/kubectl/pkg/util/templates"
Expand Down Expand Up @@ -78,7 +80,13 @@ func CmdReset(f cmdutil.Factory) *cobra.Command {
return err
}
err = util.PrintGRPCStream[rpc.ResetResponse](resp)
return err
if err != nil {
if status.Code(err) == codes.Canceled {
return nil
}
return err
}
return nil
},
}

Expand Down

0 comments on commit 6e594fa

Please sign in to comment.