Skip to content

Instantly share code, notes, and snippets.

@ahmagdy
Created July 12, 2020 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahmagdy/fd93107d8653b6a204a2dbb65c5e8b08 to your computer and use it in GitHub Desktop.
Save ahmagdy/fd93107d8653b6a204a2dbb65c5e8b08 to your computer and use it in GitHub Desktop.
package k8s
import (
"fmt"
"os"
"text/tabwriter"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func (k8s *k8SClient) PrintAllNamespaces() error {
pods, err := k8s.clientset.CoreV1().Pods("").List(metav1.ListOptions{})
if err != nil {
return err
}
writer := tabwriter.NewWriter(os.Stdout, 0, 8, 1, '\t', tabwriter.AlignRight)
fmt.Fprintln(writer, "Namespace\tName")
for _, pod := range pods.Items {
fmt.Fprintln(writer, fmt.Sprintf("%s\t%s", pod.Namespace, pod.Name))
}
writer.Flush()
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment