feat(webconsole,apigateway): display info for container exec (#20403)

This commit is contained in:
Zexi Li
2024-05-30 15:16:06 +08:00
committed by GitHub
parent a6a1c410e3
commit 618c1a059a
4 changed files with 83 additions and 4 deletions
+25 -1
View File
@@ -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 {
+18
View File
@@ -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
}