Created
July 12, 2020 10:13
-
-
Save ahmagdy/fd93107d8653b6a204a2dbb65c5e8b08 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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