mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
feat(webconsole,apigateway): display info for container exec (#20403)
This commit is contained in:
@@ -41,6 +41,9 @@ type K8sEnv struct {
|
||||
type Kubectl struct {
|
||||
*BaseCommand
|
||||
kubeconfig string
|
||||
// For display info
|
||||
InstanceName string
|
||||
IPs []string
|
||||
}
|
||||
|
||||
func NewKubectlCommand(s *mcclient.ClientSession, kubeconfig, namespace string) *Kubectl {
|
||||
@@ -55,6 +58,22 @@ func NewKubectlCommand(s *mcclient.ClientSession, kubeconfig, namespace string)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Kubectl) SetInstanceName(name string) {
|
||||
c.InstanceName = name
|
||||
}
|
||||
|
||||
func (c *Kubectl) GetInstanceName() string {
|
||||
return c.InstanceName
|
||||
}
|
||||
|
||||
func (c *Kubectl) SetIPs(ips []string) {
|
||||
c.IPs = ips
|
||||
}
|
||||
|
||||
func (c *Kubectl) GetIPs() []string {
|
||||
return c.IPs
|
||||
}
|
||||
|
||||
func (c *Kubectl) GetCommand() *exec.Cmd {
|
||||
cmd := c.BaseCommand.GetCommand()
|
||||
cmd.Env = append(cmd.Env, fmt.Sprintf("KUBECONFIG=%s", c.kubeconfig))
|
||||
@@ -135,12 +154,17 @@ func NewPodBashCommand(env *K8sEnv) ICommand {
|
||||
}
|
||||
args = append(args, shellRequest.Args...)
|
||||
|
||||
return NewKubectlCommand(env.Session, env.Kubeconfig, env.Namespace).Exec().
|
||||
kExec := NewKubectlCommand(env.Session, env.Kubeconfig, env.Namespace).Exec().
|
||||
Stdin().
|
||||
TTY().
|
||||
Pod(env.Pod).
|
||||
Container(env.Container).
|
||||
Command(shellRequest.Command, args...)
|
||||
if shellRequest.DisplayInfo != nil {
|
||||
kExec.SetInstanceName(shellRequest.DisplayInfo.InstanceName)
|
||||
kExec.SetIPs(shellRequest.DisplayInfo.IPs)
|
||||
}
|
||||
return kExec
|
||||
}
|
||||
|
||||
type KubectlLog struct {
|
||||
|
||||
@@ -106,6 +106,13 @@ type ISessionData interface {
|
||||
GetDisplayInfo(ctx context.Context) (*SDisplayInfo, error)
|
||||
}
|
||||
|
||||
type ISessionCommand interface {
|
||||
command.ICommand
|
||||
|
||||
GetInstanceName() string
|
||||
GetIPs() []string
|
||||
}
|
||||
|
||||
type RandomSessionData struct {
|
||||
command.ICommand
|
||||
id string
|
||||
@@ -134,6 +141,17 @@ func (s *RandomSessionData) GetDisplayInfo(ctx context.Context) (*SDisplayInfo,
|
||||
dispInfo := SDisplayInfo{}
|
||||
dispInfo.WaterMark = fetchWaterMark(userInfo)
|
||||
dispInfo.InstanceName = s.GetCommand().String()
|
||||
si, ok := s.ICommand.(ISessionCommand)
|
||||
if ok {
|
||||
iName := si.GetInstanceName()
|
||||
if iName != "" {
|
||||
dispInfo.InstanceName = iName
|
||||
}
|
||||
ips := si.GetIPs()
|
||||
if len(ips) > 0 {
|
||||
dispInfo.Ips = strings.Join(ips, ",")
|
||||
}
|
||||
}
|
||||
return &dispInfo, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user