-
Notifications
You must be signed in to change notification settings - Fork 23
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
Fix ctxName by adding a non-global val #839
Conversation
Issue is specifically here:
You can see it when you run debug and manually step and see ctxtName being lost. This is due to how Cobra works. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for the changes!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for the fixing this.
As you have already mentioned this is a temporary fix but we might need to fix this properly by not invoking NewRootCmd
at all.
The way we are creating NewRootCmd
will wipeout many other variables and not just ctxName. Basically when we do NewRootCmd
it will initialize all the commands again along with default values for example this line will reinitialize ctxName
to ""
string when command gets reinitialized.
@Jeremy-Boyle we will look into fixing this properly soon but we can go ahead and merge this to unblock you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After some discussion with the team we are exploring the proper fix to this issue. Until then we will be holding back on this PR from merging.
Okay sounds great ! I was thinking the same thing but it looked like it would need a bit of refactoring if NewRootCmd wasn't changed hence why I did what I did. Happy to help ! |
Another thing to note here a great improvement would be setting the tanzu-cli context that gets created via idp to something useful. for example with pinniped and tgks: This isn't exactly useful at all if you have multiple environments, I glanced over some of the code, but didn't notice anything useful that was being provided while stepping, I wasn't able to directly find where or how that pinniped plugin is being built. I assume its a private repo. Suggestion might be utilizing the endpoint for something useful but parse the http:// or another environment variable that would allow the user to change it. examples: tanzu context create tkgs-dev --endpoint https://some-dns-name.com
[email protected]
# Or the ip respectively
tanzu-cli-2ffcf2bc-4400-45a1-9868-39bf6740702b@ip-addr
# Or potentially use both along with ctxName
[email protected] I've been doing the following as a work around for the issue in the mr , but also to name the context something useful that then could be used for access to the supervisor. I did take a look around at the wcp nginx proxy, but unfortunately its not passing anything that I can see that would be useful to get the actual supervisor name from vCenter. # This will fail out and create a new context in your kubeconfig
tanzu context create context-name --endpoint https://some.fqdn.com
# Rename the newly created context name to something useful
kubectl config rename-context tanzu-cli-{guid-id}@{guid-id} new-context-name
# Add it to tanzu context create
tanzu context create context-name --kubeconfig ~/.kube/config --kubecontext new-context-name I'd be happy to provide a MR and move this discussion to a new issue/MR if its something that you think would be a improvement. |
Thanks for the investigation and root causing the issue. It made the fix much easier for us. We will mostly go ahead with #840 change to fix the mentioned issue and close this one once that is merged. |
Can you please file a Github Issue for this with your suggestion so that we can discuss more on a separate issue? I will bring this to the teams attention as well to get more opinions on this. |
#840 is merged. I am closing this PR now. We will cherry-pick the same fix to release 1.5 branch so that this can be included in |
Created for our discussion, its mostly the same comment :) #843 |
What this PR does / why we need it
Which issue(s) this PR fixes
Fixes #825
Describe testing done for PR
This fixes the ctxName which is currently a global value getting lost when NewRootCMD is called. Causing the new context to fail
Additional information
Special notes for your reviewer
A rework would probably be best to handle this due to how the NewRootCMD gets called and to not use a global value for CTX name, however, due to not wanting to refactor and make a specific type and change signatures this is the best option that i could come up with please review and make suggestions.