MCPcopy Index your code
hub / github.com/devspace-sh/devspace / RunListNamespaces

Method RunListNamespaces

cmd/list/namespaces.go:45–115  ·  view source on GitHub ↗

RunListNamespaces runs the list namespaces command logic

(f factory.Factory, cobraCmd *cobra.Command, args []string)

Source from the content-addressed store, hash-verified

43
44// RunListNamespaces runs the list namespaces command logic
45func (cmd *namespacesCmd) RunListNamespaces(f factory.Factory, cobraCmd *cobra.Command, args []string) error {
46 logger := f.GetLog()
47 // Set config root
48 configLoader, err := f.NewConfigLoader(cmd.ConfigPath)
49 if err != nil {
50 return err
51 }
52 configExists, err := configLoader.SetDevSpaceRoot(logger)
53 if err != nil {
54 return err
55 }
56
57 // Get kubectl client
58 client, err := f.NewKubeClientFromContext(cmd.KubeContext, cmd.Namespace)
59 if err != nil {
60 return errors.Wrap(err, "new kube client")
61 }
62
63 // Load generated config if possible
64 var localCache localcache.Cache
65 if configExists {
66 localCache, err = configLoader.LoadLocalCache()
67 if err != nil {
68 return err
69 }
70 }
71
72 // If the current kube context or namespace is different from old,
73 // show warnings and reset kube client if necessary
74 client, err = kubectl.CheckKubeContext(client, localCache, cmd.NoWarn, cmd.SwitchContext, false, logger)
75 if err != nil {
76 return err
77 }
78
79 namespaces, err := client.KubeClient().CoreV1().Namespaces().List(context.TODO(), metav1.ListOptions{})
80 if err != nil {
81 return errors.Wrap(err, "list namespaces")
82 }
83
84 headerColumnNames := []string{
85 "Name",
86 "Default",
87 "Exists",
88 }
89
90 // Transform values into string arrays
91 namespaceRows := make([][]string, 0, len(namespaces.Items))
92 defaultFound := false
93 for _, namespace := range namespaces.Items {
94 namespaceRows = append(namespaceRows, []string{
95 namespace.Name,
96 strconv.FormatBool(namespace.Name == client.Namespace()),
97 "true",
98 })
99
100 if namespace.Name == client.Namespace() {
101 defaultFound = true
102 }

Callers 1

newNamespacesCmdFunction · 0.95

Calls 10

SetDevSpaceRootMethod · 0.95
LoadLocalCacheMethod · 0.95
CheckKubeContextFunction · 0.92
PrintTableFunction · 0.92
GetLogMethod · 0.65
NewConfigLoaderMethod · 0.65
ListMethod · 0.65
KubeClientMethod · 0.65
NamespaceMethod · 0.65

Tested by

no test coverage detected