Skip to content

Commit

Permalink
FEATURE: support for multiple containers in a pod (sku enter, sku logs)
Browse files Browse the repository at this point in the history
  • Loading branch information
skurfuerst committed Feb 28, 2023
1 parent 75e978b commit 620bd21
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
20 changes: 18 additions & 2 deletions internal/app/commands/enter.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,26 @@ selector.
i = getNumberChoice()
}

fmt.Printf("Connecting to %v in %v:\n", aurora.Green(podList.Items[i].Name), aurora.Green(currentContext))
containerName := ""
if len(podList.Items[i].Spec.Containers) > 1 {
fmt.Printf("Which container?.\n")
for ci, c := range podList.Items[i].Spec.Containers {
fmt.Printf("%d: %v\n", ci, aurora.Green(c.Name))
}
ci := getNumberChoice()

containerName = podList.Items[i].Spec.Containers[ci].Name
}

fmt.Printf("Connecting to %v %s in %v:\n", aurora.Green(podList.Items[i].Name), containerName, aurora.Green(currentContext))

kubectlArgs := []string{"kubectl", "exec", "-it"}
if containerName != "" {
kubectlArgs = append(kubectlArgs, "-c", containerName)
}
// enter bash or sh
syscall.Exec("/usr/local/bin/kubectl", []string{"kubectl", "exec", "-it", podList.Items[i].Name, "--", "/bin/sh", "-c", "[ -e /bin/bash ] && exec /bin/bash || exec /bin/sh"}, os.Environ())
kubectlArgs = append(kubectlArgs, podList.Items[i].Name, "--", "/bin/sh", "-c", "[ -e /bin/bash ] && exec /bin/bash || exec /bin/sh")
syscall.Exec("/usr/local/bin/kubectl", kubectlArgs, os.Environ())
},
}

Expand Down
20 changes: 18 additions & 2 deletions internal/app/commands/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,25 @@ selector.

i := getNumberChoice()

fmt.Printf("Showing Logs to %v in %v:\n", aurora.Green(podList.Items[i].Name), aurora.Green(currentContext))
containerName := ""
if len(podList.Items[i].Spec.Containers) > 1 {
fmt.Printf("Which container?.\n")
for ci, c := range podList.Items[i].Spec.Containers {
fmt.Printf("%d: %v\n", ci, aurora.Green(c.Name))
}
ci := getNumberChoice()

containerName = podList.Items[i].Spec.Containers[ci].Name
}

syscall.Exec("/usr/local/bin/kubectl", []string{"kubectl", "logs", "-f", podList.Items[i].Name}, os.Environ())
fmt.Printf("Showing Logs to %v %s in %v:\n", aurora.Green(podList.Items[i].Name), containerName, aurora.Green(currentContext))

kubectlArgs := []string{"kubectl", "logs", "-f"}
if containerName != "" {
kubectlArgs = append(kubectlArgs, "-c", containerName)
}
kubectlArgs = append(kubectlArgs, podList.Items[i].Name)
syscall.Exec("/usr/local/bin/kubectl", kubectlArgs, os.Environ())
},
}

Expand Down

0 comments on commit 620bd21

Please sign in to comment.