Skip to content

[kubectl-plugin][Refactor] Standardize namespace resolution to respect kubeconfig context #4318

@justinyeh1995

Description

@justinyeh1995

Search before asking

  • I searched the issues and found no similar issues.

KubeRay Component

kubectl-plugin

Description

This is a follow up issue for #4291 (comment).
The kubectl-plugin has inconsistent namespace resolution patterns that all fail to respect the active kubeconfig context.

Current Behavior

Many Complete functions in get cluster, get workergroup, get nodes, delete, scale, and shell completion uses

if namespace == "" {
    namespace = "default"
}

Also in create cluster

namespace := "default"

These hardcoded values ignore the user's current kubeconfig context namespace.

Expected Behavior

All commands should consistently use the Factory's namespace resolution to respect kubeconfig context.

namespace, _, err := f.ToRawKubeConfigLoader().Namespace()
if err != nil {
    // error handling
}

Some examples of using Factory's namespace resolution in the upstream kubectl includes

Affected Areas

Hardcode in completion functions:

  • pkg/util/completion/completion.go (workerGroupCompletionFunc, nodeCompletionFunc)

Hardcode in Complete():

  • pkg/cmd/get/get_cluster.go
  • pkg/cmd/get/get_workergroup.go
  • pkg/cmd/get/get_nodes.go
  • pkg/cmd/get/get_token.go
  • pkg/cmd/create/create_workergroup.go
  • pkg/cmd/delete/delete.go
  • pkg/cmd/scale/scale_cluster.go
  • pkg/cmd/job/job_submit.go
  • pkg/cmd/log/log.go
  • pkg/cmd/session/session.go

resolveNamespace() in Run():

  • pkg/cmd/create/create_cluster.go

There might be more, so would appreciate checking more closely during implementation.

Are you willing to submit a PR?

  • Yes I am willing to submit a PR!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions