in pkg/cmd/ns.go [273:289]
func (o *NamespaceOptions) setNamespace(fromContext *api.Context, withContextName string) error {
if len(fromContext.Namespace) == 0 {
return fmt.Errorf("a non-empty namespace must be provided")
}
configAccess := clientcmd.NewDefaultPathOptions()
// determine if we have already saved this context to the user's KUBECONFIG before
// if so, simply switch the current context to the existing one.
if existingResultingCtx, exists := o.rawConfig.Contexts[withContextName]; !exists || !isContextEqual(fromContext, existingResultingCtx) {
o.rawConfig.Contexts[withContextName] = fromContext
}
o.rawConfig.CurrentContext = withContextName
fmt.Fprintf(o.Out, "namespace changed to %q\n", fromContext.Namespace)
return clientcmd.ModifyConfig(configAccess, o.rawConfig, true)
}