-
Notifications
You must be signed in to change notification settings - Fork 192
Tanzu CLI Configuration - Multi file approach #3954
Conversation
56569c3
to
97e9b60
Compare
17b77f8
to
0b9f7b6
Compare
Codecov Report
@@ Coverage Diff @@
## main #3954 +/- ##
==========================================
- Coverage 48.41% 47.69% -0.73%
==========================================
Files 434 462 +28
Lines 43288 45133 +1845
==========================================
+ Hits 20957 21525 +568
- Misses 20340 21564 +1224
- Partials 1991 2044 +53
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
a56f703
to
8fd1dc1
Compare
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.
Will send additional comments shortly.
Nit: did you mean the section headers in the PR description to be rendered differently in markdown (they are not ATM)
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 is a review for below code in in node_types.go file:
type CfgNode struct {
ForceCreate bool // Set to True to create nodes of missing keys. Ex: True for Add/Update operations on yaml node, False for Get/Delete operations on yaml node
Keys []Key // keys of config nodes passed in hierarchical order. Ex: [ClientOptions, CLI, DiscoverySources] to get the DiscoverySources node from ClientOptions yaml node
}
its not part of this PR, it was there in previous PR #3905
if the flag ForceCreate
is set true in case of Get/Delete, then it creates new node with given key, i don't think its good approach, because assume that i am checking if a context or server is available, if not then we are creating server/context with given key and empty value, later if i want to create server/context, i can not create as its already exists.
I feel better to restrict the flag ForceCreate
for just Add/Update operations.
its being used in api func FindNode(node *yaml.Node, opts ...Options)
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.
/test install-vc7
yea fixed it |
c73a13e
to
c5eab42
Compare
6e198c2
to
95042b8
Compare
…nd new types contexts and currentContexts into config-ng yaml
79fdc19
to
48b9665
Compare
as discussed in earlier meeting closing the comment |
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.
/test install-vc7
/test install-vc7 |
cli/runtime/config/config_factory.go
Outdated
} | ||
|
||
// Store the config data to legacy client config file/location | ||
err = persistLegacyClientConfig(node) |
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.
Thanks for updating the implementation. It is cleaner and more durable to future config definition changes now.
Unless I am missing something, doesn't this line override what L145 is trying to do?
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.
legacy referred is .tanzu folder L145 is config.yaml.
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.
You are right, misread.
The legacy file is being used by any plugins we support at this point. The only place where it even plays any part is in cli/runtime/config/legacy_clientconfig.go CopyLegacyConfigDir() where function will copy the legacy to the main config file if legacy exist and the main file doesn't (which should not be the case given how aggressively we initialize the main config.yaml).
Keeping the line as is okay, but we should eliminate any code dealing as a followup.
@@ -0,0 +1,37 @@ | |||
// Copyright 2022 VMware, Inc. All Rights Reserved. | |||
// SPDX-License-Identifier: Apache-2.0 | |||
|
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.
question: what's the rationale for naming a set of files in this dir _filesystem.go?
maybe _file.go would be more appropriate?
(If we elect to change, and especially since there are preexisting files already committed, let's do it as a followup.)
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.
Thanks for the changes! Looks good to me.
Couple of minor things.
At top of the PR description, where you described a lot of what the PR does, please also add a line or two about the why.
} | ||
|
||
func TestPersistConfig(t *testing.T) { | ||
// Setup config test data |
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.
not block, but should you need to rebase, one more suggestion:
As implemented the persistConfig functionality will actually preserve any nodes in the main config.yaml that is not on the hardcode list. It would be good to have a test communicate that behavior.
perhaps something like this in TestPersistConfig
--- a/cli/runtime/config/config_factory_test.go
+++ b/cli/runtime/config/config_factory_test.go
@@ -25,6 +25,7 @@ clientOptions:
local:
name: default-local
path: standalone
+ # extra comment my local admin source
- local:
name: admin-local
path: admin
@@ -99,6 +100,9 @@ contexts:
contextType: tmc
currentContext:
k8s: test-mc
+# extraneous fiels/comments are preserved on file update
+extrafield:
+ extrasubfield: 1
`
expectedCfg := `apiVersion: config.tanzu.vmware.com/v1alpha1
clientOptions:
@@ -110,6 +114,7 @@ clientOptions:
local:
name: default-local
path: standalone
+ # extra comment my local admin source
- local:
name: admin-local
path: admin
@@ -184,6 +189,9 @@ contexts:
contextType: tmc
currentContext:
k8s: test-mc
+# extraneous fiels/comments are preserved on file update
+extrafield:
+ extrasubfield: 1
`
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.
addressing this in follow up PR
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.
Looks good to me.
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.
Great job. LGTM!
Thanks.
This PR looks good to get in. If there are any other minor changes required, we can do it as a followup. |
What this PR does / why we need it
Introduce Multi Config files
config.yaml
andconfig-ng.yaml
to manage client config data.Introduce new API's to config-metadata to manage what goes into
config-ng.yaml
.contexts
andcurrentContexts
will be moved toconfig-ng.yaml
.New type
settings
has been added toconfig-metadata.yaml
to store any internal settings related to config operations which are controlled by core cli.useUnifiedConfig
- Used to move all the config related operations toconfig-ng.yaml
. By default this setting is disabled and will be enabled in next future versions of cli.Existing
getClientConfigNode
andgetClientConfigNodeNoLock
function implementation is updated to handle multiple config files.New factory and filesytem files are added to perform operations on
config-ng.yaml
.TANZU_CONFIG_NEXT_GEN
Env key is defined to explicitly setconfig-ng.yaml
file.Major changes
Read from Config
useUnifiedConfig
settings inconfig-metadata.yaml
.config-ng.yaml
and construct yaml node.Write to Config
useUnifiedConfig
settings inconfig-metadata.yaml
.config-ng.yaml
..tanzu
.Tanzu Command changes
tanzu config get
cmd implementation is changed to handle multi files. now it will retrieve the combination of bothconfig.yaml
andconfig-ng.yaml
Minor Bug Fix
.tanzu
directory to not rely onTANZU_CONFIG
env variable that is conflicted withconfig.yaml
.Example:- Default behaviour
Outcome :- Only contexts and currentContexts read and write to config-ng.yaml
Example :-
Outcome :- All config item read and write to config-ng.yaml
Which issue(s) this PR fixes
Fixes #2652
Fixes #3810
Describe testing done for PR
Unit Testing and Integration Testing
Tested
tanzu config get
,tanzu login
,tanzu context create
etc..Release note
Additional information
Special notes for your reviewer
Review the
clientconfig_factory.go
andconfig_factory.go
first to familiarize with the Multi File Read/Write works.