Skip to content

Commit

Permalink
fix(kube): fix kube exec
Browse files Browse the repository at this point in the history
fix kube exec

Signed-off-by: ysicing <[email protected]>
  • Loading branch information
ysicing committed Sep 6, 2023
1 parent 98edbcb commit 8ecfb30
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
22 changes: 19 additions & 3 deletions cmd/app/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,32 @@ func NewCmdAppList(f factory.Factory) *cobra.Command {
Size: 5,
}
podit, _, _ := selectPod.Run()
log.Infof("select app %s pod %s", release[it].Name, podlist.Items[podit].Name)
podName := podlist.Items[podit].Name
log.Infof("select app %s pod %s", release[it].Name, podName)
selectAction := promptui.Select{
Label: "select action",
Items: []string{"logs", "exec"},
}
_, action, _ := selectAction.Run()
podNamespace := podlist.Items[podit].Namespace
selectPodContainer := promptui.Select{
Label: fmt.Sprintf("select %s's container", podName),
Items: podlist.Items[podit].Spec.Containers,
Templates: &promptui.SelectTemplates{
Label: "{{ . }}?",
Active: "\U0001F449 {{ .Name | cyan }}",
Inactive: " {{ .Name | cyan }}",
Selected: "\U0001F389 {{ .Name | red | cyan }}",
},
Size: 5,
}
podContainerit, _, _ := selectPodContainer.Run()
containerName := podlist.Items[podit].Spec.Containers[podContainerit].Name
log.Infof("select app %s pod %s's container %s", release[it].Name, podName, containerName)
if action == "logs" {
return k8sClient.GetFollowLogs(ctx, podlist.Items[podit].Namespace, podlist.Items[podit].Name, podlist.Items[podit].Spec.Containers[0].Name, false)
return k8sClient.GetFollowLogs(ctx, podNamespace, podName, containerName, false)
}
return k8sClient.ExecPodWithTTY(ctx, podlist.Items[podit].Namespace, podlist.Items[podit].Name, podlist.Items[podit].Spec.Containers[0].Name, []string{"/bin/sh", "-c", "sh"})
return k8sClient.ExecPodWithTTY(ctx, podNamespace, podName, containerName, []string{"/bin/sh", "-c", "sh"})
},
}
return app
Expand Down
11 changes: 6 additions & 5 deletions internal/pkg/k8s/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -633,11 +633,12 @@ func (c *Client) ExecPodWithTTY(ctx context.Context, namespace, podName, contain
Namespace(namespace).
SubResource("exec").
VersionedParams(&corev1.PodExecOptions{
Command: command,
Stdin: true,
Stdout: true,
Stderr: true,
TTY: true,
Command: command,
Container: container,
Stdin: true,
Stdout: true,
Stderr: true,
TTY: true,
}, scheme.ParameterCodec)
exec, err := remotecommand.NewSPDYExecutor(c.Config, "POST", req.URL())
if err != nil {
Expand Down

0 comments on commit 8ecfb30

Please sign in to comment.