MCPcopy
hub / github.com/kubernetes/client-go / Namespace

Method Namespace

tools/clientcmd/client_config.go:309–332  ·  view source on GitHub ↗

Namespace implements ClientConfig

()

Source from the content-addressed store, hash-verified

307
308// Namespace implements ClientConfig
309func (config *DirectClientConfig) Namespace() (string, bool, error) {
310 if config.overrides != nil && config.overrides.Context.Namespace != "" {
311 // In the event we have an empty config but we do have a namespace override, we should return
312 // the namespace override instead of having config.ConfirmUsable() return an error. This allows
313 // things like in-cluster clients to execute `kubectl get pods --namespace=foo` and have the
314 // --namespace flag honored instead of being ignored.
315 return config.overrides.Context.Namespace, true, nil
316 }
317
318 if err := config.ConfirmUsable(); err != nil {
319 return "", false, err
320 }
321
322 configContext, err := config.getContext()
323 if err != nil {
324 return "", false, err
325 }
326
327 if len(configContext.Namespace) == 0 {
328 return "default", false, nil
329 }
330
331 return configContext.Namespace, false, nil
332}
333
334// ConfigAccess implements ClientConfig
335func (config *DirectClientConfig) ConfigAccess() ConfigAccess {

Callers 1

TestNamespaceOverrideFunction · 0.95

Calls 2

ConfirmUsableMethod · 0.95
getContextMethod · 0.95

Tested by 1

TestNamespaceOverrideFunction · 0.76