in pkg/cmd/ns.go [212:250]
func (o *NamespaceOptions) Run() error {
if len(o.userSpecifiedNamespace) > 0 && o.resultingContext != nil {
return o.setNamespace(o.resultingContext, o.resultingContextName)
}
namespaces := map[string]bool{}
for name, c := range o.rawConfig.Contexts {
if !o.listNamespaces && name == o.rawConfig.CurrentContext {
if len(c.Namespace) == 0 {
return fmt.Errorf("no namespace is set for your current context: %q", name)
}
fmt.Fprintf(o.Out, "%s\n", c.Namespace)
return nil
}
// skip if dealing with a namespace we have already seen
// or if the namespace for the current context is empty
if len(c.Namespace) == 0 {
continue
}
if namespaces[c.Namespace] {
continue
}
namespaces[c.Namespace] = true
}
if !o.listNamespaces {
return fmt.Errorf("unable to find information for the current namespace in your configuration")
}
for n := range namespaces {
fmt.Fprintf(o.Out, "%s\n", n)
}
return nil
}