diff --git a/pkg/webconsole/command/ipmi_command.go b/pkg/webconsole/command/ipmi_command.go index 94e656b754..da250ba9f1 100644 --- a/pkg/webconsole/command/ipmi_command.go +++ b/pkg/webconsole/command/ipmi_command.go @@ -3,6 +3,8 @@ package command import ( "fmt" "os/exec" + + o "yunion.io/x/onecloud/pkg/webconsole/options" ) type IpmiInfo struct { @@ -27,7 +29,7 @@ func NewIpmitoolSolCommand(info *IpmiInfo) (*IpmitoolSol, error) { if info.Password == "" { return nil, fmt.Errorf("Empty password") } - name := "ipmitool" + name := o.Options.IpmitoolPath cmd := NewBaseCommand(name, "-I", "lanplus") cmd.AppendArgs("-H", info.IpAddr) cmd.AppendArgs("-U", info.Username) diff --git a/pkg/webconsole/command/kube_command.go b/pkg/webconsole/command/kube_command.go index 34a9087a6d..c90b9bae8e 100644 --- a/pkg/webconsole/command/kube_command.go +++ b/pkg/webconsole/command/kube_command.go @@ -6,6 +6,8 @@ import ( "os/exec" "yunion.io/x/log" + + o "yunion.io/x/onecloud/pkg/webconsole/options" ) type Kubectl struct { @@ -14,7 +16,7 @@ type Kubectl struct { } func NewKubectlCommand(kubeconfig, namespace string) *Kubectl { - name := "kubectl" + name := o.Options.KubectlPath if len(namespace) == 0 { namespace = "default" } @@ -92,7 +94,7 @@ func NewPodBashCommand(kubeconfig, namespace, pod, container string) ICommand { TTY(). Pod(pod). Container(container). - Command("bash", "-i", "-l") + Command("sh") } type KubectlLog struct { @@ -120,8 +122,18 @@ func (c *KubectlLog) Pod(name string) *KubectlLog { return c } +func (c *KubectlLog) Container(name string) *KubectlLog { + if name == "" { + return c + } + // -c, --container='': Print the logs of this container + c.AppendArgs("-c", name) + return c +} + func NewPodLogCommand(kubeconfig, namespace, pod, container string) ICommand { return NewKubectlCommand(kubeconfig, namespace).Logs(). Follow(). - Pod(pod) + Pod(pod). + Container(container) } diff --git a/pkg/webconsole/options/options.go b/pkg/webconsole/options/options.go index 7561ce79eb..45e9235f00 100644 --- a/pkg/webconsole/options/options.go +++ b/pkg/webconsole/options/options.go @@ -11,5 +11,7 @@ var ( type WebConsoleOptions struct { cloudcommon.Options - ApiServer string `help:"API server url to handle websocket connection, usually with public access" default:"http://webconsole.yunion.io"` + ApiServer string `help:"API server url to handle websocket connection, usually with public access" default:"http://webconsole.yunion.io"` + KubectlPath string `help:"kubectl binary path used to connect k8s cluster" default:"/usr/bin/kubectl"` + IpmitoolPath string `help:"ipmitool binary path used to connect baremetal sol" default:"/usr/bin/ipmitool"` } diff --git a/pkg/webconsole/service/service.go b/pkg/webconsole/service/service.go index 29dc081d04..3836f618bb 100644 --- a/pkg/webconsole/service/service.go +++ b/pkg/webconsole/service/service.go @@ -17,6 +17,12 @@ import ( "yunion.io/x/onecloud/pkg/webconsole/server" ) +func ensureBinExists(binPath string) { + if _, err := os.Stat(binPath); os.IsNotExist(err) { + log.Fatalf("Binary %s not exists", binPath) + } +} + func StartService() { cloudcommon.ParseOptions(&o.Options, &o.Options.Options, os.Args, "webconsole.conf") @@ -28,6 +34,10 @@ func StartService() { log.Fatalf("invalid --api-server %s", o.Options.ApiServer) } + for _, binPath := range []string{o.Options.KubectlPath, o.Options.IpmitoolPath} { + ensureBinExists(binPath) + } + cloudcommon.InitAuth(&o.Options.Options, func() { log.Infof("Auth complete") })