Skip to content

Commit

Permalink
fix: split an empty string will got an one-item-list with an empty st…
Browse files Browse the repository at this point in the history
…ring
  • Loading branch information
linfan committed Nov 10, 2021
1 parent c5b512e commit e03e82f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
6 changes: 3 additions & 3 deletions pkg/kt/cluster/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/kt/cluster/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/kt/cluster/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/kt/exec/sshuttle/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down

0 comments on commit e03e82f

Please # to comment.