Skip to content

Commit c91deb7

Browse files
authored
Added namespace support (#16)
1 parent b0c6ed3 commit c91deb7

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

main.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,17 @@ func (p ByPodName) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
5353

5454
func main() {
5555
kubeconfig := flag.String("kubeconfig", "", "Path to the kubeconfig file")
56-
containerFlag := flag.String("c", "", "Container to execute the command against")
57-
labelFlag := flag.String("l", "", "Label selector to filter pods")
56+
container := flag.String("c", "", "Container to execute the command against")
57+
labelSelector := flag.String("l", "", "Label selector to filter pods")
58+
namespace := flag.String("n", "", "Namespace filter")
5859
flag.Parse()
5960

60-
if *containerFlag == "" {
61+
if *container == "" {
6162
fmt.Println("Error: container name must be specified with -c")
6263
os.Exit(1)
6364
}
6465

65-
if *labelFlag == "" {
66+
if *labelSelector == "" {
6667
fmt.Println("Error: label selector must be specified with -l")
6768
os.Exit(1)
6869
}
@@ -86,8 +87,8 @@ func main() {
8687
panic(err)
8788
}
8889

89-
pods, err := clientset.CoreV1().Pods("").List(context.Background(), metav1.ListOptions{
90-
LabelSelector: *labelFlag,
90+
pods, err := clientset.CoreV1().Pods(*namespace).List(context.Background(), metav1.ListOptions{
91+
LabelSelector: *labelSelector,
9192
})
9293
if err != nil {
9394
panic(err)
@@ -100,7 +101,7 @@ func main() {
100101
wg.Add(1)
101102
go func(p v1.Pod) {
102103
defer wg.Done()
103-
resultsChan <- execCommand(config, clientset, p, *containerFlag, args)
104+
resultsChan <- execCommand(config, clientset, p, *container, args)
104105
}(pod)
105106
}
106107

0 commit comments

Comments
 (0)