Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This optimization is quite clean and much appreciated.
I am not sure if we had in the past rely on this to update existing (not create new) entry to correct for any inconsistencies. cc @prkalle
If we want to be really safe, we can consider some undocumented env var to restore back the old behavior for any user who needs it.
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.
Looking at the #616 and what was being done before, I see that we were calling https://github.com/vmware-tanzu/tanzu-plugin-runtime/blob/7278b2554915a10ad3abc9e8befe0a3eb196e1a3/config/legacy_clientconfig_factory.go#L21. I based my check on that code to know if there was any servers needing to be updated. So I feel we are covered on that front.
However, there is another aspect to consider. When saving the configuration to file I notice that there is some cleanup of "legacyDiscardedContexts" done here: https://github.com/vmware-tanzu/tanzu-plugin-runtime/blob/7278b2554915a10ad3abc9e8befe0a3eb196e1a3/config/config_factory.go#L144-L152
To reproduce the situation I installed
cluster:k8s:v0.25.4
and simply rantanzu cluster version
. What I see is that theconfig.yaml
file now has acontexts
node with all the servers included there. Before this PR, thatcontexts
node would be removed on the next CLI run. With this PR it is only cleaned up whenever the configuration is changed later on.I don't think keeping this
contexts
node is problematic, but let's discuss it