diff --git a/pkg/kt/cluster/helper.go b/pkg/kt/cluster/helper.go index cf5ada7a..5d371e08 100644 --- a/pkg/kt/cluster/helper.go +++ b/pkg/kt/cluster/helper.go @@ -27,11 +27,11 @@ func getKubernetesClient(kubeConfig string) (clientset *kubernetes.Clientset, er return } -func getPodCidrs(ctx context.Context, clientset kubernetes.Interface, podCIDRs []string) ([]string, error) { +func getPodCidrs(ctx context.Context, clientset kubernetes.Interface, podCIDRs string) ([]string, error) { var cidrs []string - if len(podCIDRs) > 0 { - for _, cidr := range podCIDRs { + if podCIDRs != "" { + for _, cidr := range strings.Split(podCIDRs, ",") { cidrs = append(cidrs, cidr) } return cidrs, nil diff --git a/pkg/kt/cluster/helper_test.go b/pkg/kt/cluster/helper_test.go index d515670c..91639b8d 100644 --- a/pkg/kt/cluster/helper_test.go +++ b/pkg/kt/cluster/helper_test.go @@ -45,7 +45,7 @@ func Test_getPodCidrs(t *testing.T) { client := testclient.NewSimpleClientset(tt.objs...) - gotCidrs, err := getPodCidrs(context.TODO(), client, []string{}) + gotCidrs, err := getPodCidrs(context.TODO(), client, "") if (err != nil) != tt.wantErr { t.Errorf("getPodCidrs() error = %v, wantErr %v", err, tt.wantErr) return diff --git a/pkg/kt/cluster/kubernetes.go b/pkg/kt/cluster/kubernetes.go index 2190ed66..03cde491 100644 --- a/pkg/kt/cluster/kubernetes.go +++ b/pkg/kt/cluster/kubernetes.go @@ -386,7 +386,7 @@ func (k *Kubernetes) ClusterCidrs(ctx context.Context, namespace string, opt *op } if !opt.DisablePodIp { - cidrs, err = getPodCidrs(ctx, k.Clientset, strings.Split(opt.CIDRs, ",")) + cidrs, err = getPodCidrs(ctx, k.Clientset, opt.CIDRs) if err != nil { return } diff --git a/pkg/kt/exec/sshuttle/commands.go b/pkg/kt/exec/sshuttle/commands.go index 6c5196bc..a2a1f7a4 100644 --- a/pkg/kt/exec/sshuttle/commands.go +++ b/pkg/kt/exec/sshuttle/commands.go @@ -38,8 +38,10 @@ func (s *Cli) Connect(opt *options.ConnectOptions, req *SSHVPNRequest) *exec.Cmd subCommand := fmt.Sprintf("ssh -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -i %s", req.RemoteSSHPKPath) remoteAddr := fmt.Sprintf("root@%s:%d", req.RemoteSSHHost, opt.SSHPort) args = append(args, "--ssh-cmd", subCommand, "--remote", remoteAddr, "--exclude", req.RemoteSSHHost) - for _, ip := range strings.Split(opt.ExcludeIps, ",") { - args = append(args, "--exclude", ip) + if opt.ExcludeIps != "" { + for _, ip := range strings.Split(opt.ExcludeIps, ",") { + args = append(args, "--exclude", ip) + } } args = append(args, req.CustomCIDR...) cmd := exec.Command("sshuttle", args...)