Merge pull request #190 in YUNIONIO/onecloud from ~LIZEXI/onecloud:feautre/lzx-webconsole-shell to release/2.1.0

* commit '1fba463cda118632c522b4bf3ee5330e2bfd5c4f':
  - use sh to connect k8s pod - ensure required binaries exist
This commit is contained in:
邱剑
2018-09-12 14:08:55 +08:00
4 changed files with 31 additions and 5 deletions
+3 -1
View File
@@ -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)
+15 -3
View File
@@ -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)
}
+3 -1
View File
@@ -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"`
}
+10
View File
@@ -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")
})