feat(plugin): check container name is not empty when call kubectl exec
This commit is contained in:
parent
b2808c9ff7
commit
7385a371f6
3 changed files with 21 additions and 6 deletions
|
@ -17,6 +17,8 @@ limitations under the License.
|
|||
package exec
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||
|
@ -60,7 +62,7 @@ func exec(flags *genericclioptions.ConfigFlags, podName string, deployment strin
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("exec in %s\n", pod.Name)
|
||||
args := []string{"exec"}
|
||||
if opts.TTY {
|
||||
args = append(args, "-t")
|
||||
|
@ -69,7 +71,10 @@ func exec(flags *genericclioptions.ConfigFlags, podName string, deployment strin
|
|||
args = append(args, "-i")
|
||||
}
|
||||
|
||||
args = append(args, []string{"-n", pod.Namespace, "-c", container, pod.Name, "--"}...)
|
||||
args = append(args, cmd...)
|
||||
args = append(args, "-n", pod.Namespace, pod.Name)
|
||||
if len(container) > 0 {
|
||||
args = append(args, "-c", container)
|
||||
}
|
||||
args = append(args, append([]string{"--"}, cmd...)...)
|
||||
return kubectl.Exec(flags, args)
|
||||
}
|
||||
|
|
|
@ -101,7 +101,10 @@ func logs(flags *genericclioptions.ConfigFlags, podName string, deployment strin
|
|||
return err
|
||||
}
|
||||
|
||||
cmd := []string{"logs", "-n", pod.Namespace, "-c", container, pod.Name}
|
||||
cmd := []string{"logs", "-n", pod.Namespace, pod.Name}
|
||||
if len(container) > 0 {
|
||||
cmd = append(cmd, "-c", container)
|
||||
}
|
||||
cmd = append(cmd, opts.toStrings()...)
|
||||
return kubectl.Exec(flags, cmd)
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@ limitations under the License.
|
|||
package ssh
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||
|
@ -50,6 +52,11 @@ func ssh(flags *genericclioptions.ConfigFlags, podName string, deployment string
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return kubectl.Exec(flags, []string{"exec", "-it", "-n", pod.Namespace, "-c", container, pod.Name, "--", "/bin/bash"})
|
||||
fmt.Printf("exec in %s\n", pod.Name)
|
||||
args := []string{"exec", "-it", "-n", pod.Namespace, pod.Name}
|
||||
if len(container) > 0 {
|
||||
args = append(args, "-c", container)
|
||||
}
|
||||
args = append(args, "--", "/bin/bash")
|
||||
return kubectl.Exec(flags, args)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue