Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: ability to set the current context to "none". #3

Closed
stremblay opened this issue Jul 15, 2021 · 6 comments
Closed

Feature request: ability to set the current context to "none". #3

stremblay opened this issue Jul 15, 2021 · 6 comments
Assignees
Labels
enhancement New feature or request

Comments

@stremblay
Copy link

Hello!

First, I love the fact that you ported kubectx to PowerShell. This is really cool!

I would love to have a feature to set the context to "none" or empty. Is that possible? This would help to potentially avoid running commands by accident using the history and messing up a customer's production environment cluster for example.

Regards,

Stéphane

@thomasliddledba thomasliddledba self-assigned this Jul 19, 2021
@thomasliddledba
Copy link
Owner

Hi @stremblay
I think this is a great feature idea. I'll work on something this weekend.

Thanks

@thomasliddledba thomasliddledba added the enhancement New feature or request label Jul 19, 2021
@thomasliddledba
Copy link
Owner

thomasliddledba commented Jul 20, 2021

I'll be modifying this code

function switch_context($context) {
kubectl config use-context $context
}

to the following

function switch_context($context) {
    if ($context -eq 'n/a') {
        kubectl config set-context no-context
        kubectl config use-context no-context
    }
    else {
        kubectl config use-context $context
    }
}

I'm using the n/a because namespaces can't use special characters referenced in RFC 1123 for creating namespaces.

kubectl create ns n/a
The Namespace "n/a" is invalid: metadata.name: Invalid value: "n/a": a lowercase RFC 1123 label must consist of lower case alphanumeric characters or '-', and must start and end with an alphanumeric character (e.g. 'my-name',  or '123-abc', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?')

@thomasliddledba
Copy link
Owner

Hi @stremblay
I made the changes requested. Let me know if you have any questions or issues.

Thanks.

@stremblay
Copy link
Author

Amazing! Thank you! I will update immediately and let you know. :)

@stremblay
Copy link
Author

In case you want to make your tool as similar to the Linux kubectx, I think they use a flag such as -u --unset which I just found out was added last year.
kubectx -u, --unset : unset the current context

This could be an alternative as well.

@thomasliddledba
Copy link
Owner

I like the unset option also. I'll add that. Give me a few days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants