Skip to content

Conversation

@kash2104
Copy link
Contributor

Why are these changes needed?

Currently kubectl-plugin failed to respect the kubeconfig context by hardcoding the namespace value to default.

This PR uses Factory's namespace resolution in order to use namespace configured in kubeconfig.

Related issue number

Closes #4318

Checks

  • I've made sure the tests are passing.
  • Testing Strategy
    • Unit tests
    • Manual tests
    • This PR is not tested :(

namespace, _, err := options.cmdFactory.ToRawKubeConfigLoader().Namespace()
if err != nil{
return "", fmt.Errorf("failed to get current namespace: %w", err)
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Config file namespace ignored due to always-set options.namespace

High Severity

The resolveNamespace() function can no longer use the namespace from a config file. Previously, cmd.Flags().GetString("namespace") returned an empty string when the user didn't pass --namespace, allowing the config file namespace to be used. Now, ToRawKubeConfigLoader().Namespace() always returns a value (at minimum "default"), so options.namespace is never empty. This causes the condition if options.namespace != "" to always be true, making the else if branch that uses rayClusterConfig.Namespace unreachable. Additionally, the error check at line 249 will now incorrectly fail when a config file specifies a namespace different from the kubeconfig default.

Additional Locations (2)

Fix in Cursor Fix in Web

Copy link
Contributor

@400Ping 400Ping Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, and I think you should add test to check this

Copy link
Member

@Future-Outlier Future-Outlier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kash2104
Copy link
Contributor Author

Currently working on resolving the failing tests.

@kash2104 kash2104 force-pushed the issue-4318 branch 3 times, most recently from 0d9c447 to f7a7f45 Compare January 16, 2026 18:51
cursor[bot]

This comment was marked as outdated.

@kash2104 kash2104 force-pushed the issue-4318 branch 3 times, most recently from ab69d83 to 1d28033 Compare January 17, 2026 06:06
cursor[bot]

This comment was marked as outdated.

Copy link
Member

@win5923 win5923 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kash2104
Copy link
Contributor Author

I tried but the CI that is failing is TestCompleteFoo from session_test.go where it keeps saying that old-context is not found and hence not taking the namespace and the context from it.

Would appreciate help for debugging and passing this test.

@AndySung320
Copy link
Contributor

Hi @kash2104 ,
in your new test, you're trying to use cmd.Flags().Set() but those flags don't exist anymore since you refactored to use Factory's namespace resolution.
Comparing with the old test (which directly set fakeSessionOptions.namespace), the new approach needs to properly configure ConfigFlags so the Factory can read from it.
You need to:

  1. Set ConfigFlags.Namespace and ConfigFlags.Context directly as pointers (not via cmd.Flags().Set())
  2. Move cmdFactory creation inside the test loop so each test case gets its own configured ConfigFlags
  3. Fix the kubeconfig: your contexts reference non-existent clusters, and "old-context" isn't defined in the contexts map

@kash2104 kash2104 force-pushed the issue-4318 branch 2 times, most recently from b8db8cb to e904e1a Compare January 22, 2026 02:04
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

@kash2104 kash2104 force-pushed the issue-4318 branch 3 times, most recently from 4b21de4 to b1ff884 Compare January 23, 2026 15:53
Copy link
Contributor

@AndySung320 AndySung320 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the Go-build-and-test / Lint (pre-commit) check is still failing.
Could you take a look and fix the lint issues?

@kash2104 kash2104 force-pushed the issue-4318 branch 2 times, most recently from 437850d to 16f91e9 Compare January 24, 2026 18:19
@kash2104
Copy link
Contributor Author

@AndySung320 Have fixed the failing tests.

Copy link
Member

@Future-Outlier Future-Outlier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also change completion.go?

@kash2104
Copy link
Contributor Author

If we change completion.go, then we need to modify it to include variable of cmdUtil.Factory type in order to just get the namespace from the kubeconfig. All the other flags like ray-cluster needs to be set using cobra command only since they are not included in the kubeconfig. So do we want that approach?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

5 participants