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

Refactor the deprecated APIs #616

Merged

Conversation

mpanchajanya
Copy link
Contributor

@mpanchajanya mpanchajanya commented Dec 15, 2023

What this PR does / why we need it

  • Remove Deprecated APIs usage like StoreClientConfig.

Which issue(s) this PR fixes

Fixes #

Describe testing done for PR

  • Test Setting, Getting feature flags

  • Set, Get features and env

mpanchajanya@mpanchajanF09MK ~/v/r/tanzu-cli (implement_feature_flags_apis)> tz version
version: v1.2.0-dev
buildDate: 2024-01-19
sha: 46cba354
arch: arm64
mpanchajanya@mpanchajanF09MK ~/v/r/tanzu-cli (implement_feature_flags_apis)> tz config get
clientOptions:
    features:
        global:
            context-target-v2: "true"
cli:
    ceipOptIn: "true"
    eulaStatus: accepted
    discoverySources:
        - oci:
            name: default
            image: projects.registry.vmware.com/tanzu_cli/plugins/plugin-inventory:latest
    cliId: 50314dbb-739f-46b1-8062-a68ba082ea1b
    telemetry:
        source: /Users/mpanchajanya/.config/tanzu-cli-telemetry/cli_metrics.db
mpanchajanya@mpanchajanF09MK ~/v/r/tanzu-cli (implement_feature_flags_apis)> tz config set
[x] : both PATH and <value> are required
mpanchajanya@mpanchajanF09MK ~/v/r/tanzu-cli (implement_feature_flags_apis) [1]> tz config set features
[x] : both PATH and <value> are required
mpanchajanya@mpanchajanF09MK ~/v/r/tanzu-cli (implement_feature_flags_apis) [1]> tz config set features.test test
[x] : unable to parse config path parameter into three parts [features.test]  (was expecting 'features.<plugin>.<feature>'
mpanchajanya@mpanchajanF09MK ~/v/r/tanzu-cli (implement_feature_flags_apis) [1]> tz config set features.global.foo true
mpanchajanya@mpanchajanF09MK ~/v/r/tanzu-cli (implement_feature_flags_apis)> tz config get
clientOptions:
    features:
        global:
            context-target-v2: "true"
            foo: "true"
cli:
    ceipOptIn: "true"
    eulaStatus: accepted
    discoverySources:
        - oci:
            name: default
            image: projects.registry.vmware.com/tanzu_cli/plugins/plugin-inventory:latest
    cliId: 50314dbb-739f-46b1-8062-a68ba082ea1b
    telemetry:
        source: /Users/mpanchajanya/.config/tanzu-cli-telemetry/cli_metrics.db
mpanchajanya@mpanchajanF09MK ~/v/r/tanzu-cli (implement_feature_flags_apis)> tz config set env
[x] : both PATH and <value> are required
mpanchajanya@mpanchajanF09MK ~/v/r/tanzu-cli (implement_feature_flags_apis) [1]> tz config set env.foo bar
mpanchajanya@mpanchajanF09MK ~/v/r/tanzu-cli (implement_feature_flags_apis)> tz config get
clientOptions:
    features:
        global:
            context-target-v2: "true"
            foo: "true"
    env:
        foo: bar
cli:
    ceipOptIn: "true"
    eulaStatus: accepted
    discoverySources:
        - oci:
            name: default
            image: projects.registry.vmware.com/tanzu_cli/plugins/plugin-inventory:latest
    cliId: 50314dbb-739f-46b1-8062-a68ba082ea1b
    telemetry:
        source: /Users/mpanchajanya/.config/tanzu-cli-telemetry/cli_metrics.db
mpanchajanya@mpanchajanF09MK ~/v/r/tanzu-cli (implement_feature_flags_apis)> 

Release note

Remove usage of deprecated Configuration APIs like StoreClientConfig

Additional information

Special notes for your reviewer

@mpanchajanya mpanchajanya self-assigned this Dec 15, 2023
@mpanchajanya mpanchajanya force-pushed the implement_feature_flags_apis branch 3 times, most recently from ae7f2b2 to 3f22b00 Compare January 10, 2024 13:29
@mpanchajanya mpanchajanya changed the title Update feature flag apis Refactor the deprecated APIs Jan 10, 2024
@mpanchajanya mpanchajanya marked this pull request as ready for review January 18, 2024 14:18
@mpanchajanya mpanchajanya requested a review from a team as a code owner January 18, 2024 14:18
@mpanchajanya mpanchajanya force-pushed the implement_feature_flags_apis branch 3 times, most recently from 402891c to a49ec0a Compare January 19, 2024 06:49
@mpanchajanya mpanchajanya added kind/cleanup Categorizes issue or PR as related to cleaning up code, process kind/refactor Categorizes issue or PR as related to a refactoring labels Jan 19, 2024
Copy link
Contributor

@marckhouzam marckhouzam left a comment

Choose a reason for hiding this comment

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

Some comments in-line.

Also, I think you can use configlib.GetAllFeatureFlags() in the function completionGetEnvAndFeatures() instead of accessing the content of the config struct directly.

Finally, I still see one more use of these functions in pkg/interfaces/config_client_interface.go, but considering the time, we can start with this PR.

pkg/command/ceip_participation.go Outdated Show resolved Hide resolved

config.PopulateContexts(cfg)

for _, c := range cfg.KnownContexts {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we doing this now? I don't see it being done before this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@marc pkg/config/In init.go we were already doing this sync of contexts and servers
// contexts could be lost when older plugins edit the config, so populate them from servers
addedContexts := config.PopulateContexts(c)

I removed the use of StoreClientConfig and used the Config APIs directly.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, now I understand two things:

  1. StoreClientConfig() would of course store the config, which config.PopulateContexts(c) does not do, so in this PR you save each context in the config file by looping and calling config.SetContext()
  2. StoreClientConfig() also made sure any missing servers were created based on the contexts, and now the loop achieves the same thing by the same calls to config.SetContext()

This is great, but could you add a comment before the loop to say something like // Now write the context to the configuration file. This will also create any missing server for its corresponding context

Also, I think there still one aspect missing:

  • config.PopulateContexts(c) might have change the value of the currentContext; this is not persisted in the config file because the loop never sets the currentContext

I was able to reproduce that last point as follows:

  1. manually delete a context from ~/.config/tanzu/config-ng.yaml
  2. set the deleted context as the current in ~/.config/tanzu/config.yaml
  3. => So now we have a server that is active that does not exist as a context.
  4. Now run tz context list (or any other command).
  5. => before this PR, the missing context would be added and be set to active, but with this PR the missing context is added but is not set to active.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the detailed review. I have added comments for SetContext and updated the code to use SetActiveContext.

pkg/pluginmanager/manager.go Outdated Show resolved Hide resolved
pkg/command/config.go Show resolved Hide resolved
pkg/command/config.go Outdated Show resolved Hide resolved
@marckhouzam marckhouzam dismissed their stale review January 19, 2024 18:42

Started a new review

Copy link
Contributor

@marckhouzam marckhouzam left a comment

Choose a reason for hiding this comment

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

One last comment and then I think we are good.

Copy link
Contributor

@marckhouzam marckhouzam left a comment

Choose a reason for hiding this comment

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

LGTM
Thanks for this cleanup!

@mpanchajanya mpanchajanya merged commit 3e6a2fb into vmware-tanzu:main Jan 21, 2024
7 checks passed
@marckhouzam marckhouzam added this to the v1.2.0 milestone Jan 22, 2024
vuil pushed a commit to vuil/tanzu-cli that referenced this pull request Jan 23, 2024
* Update deprecated apis like feature flag apis

* Remove unused builder publish command

* Address review comments

* Implement sync of active contexts and server
vuil pushed a commit that referenced this pull request Jan 23, 2024
* Update deprecated apis like feature flag apis

* Remove unused builder publish command

* Address review comments

* Implement sync of active contexts and server
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-not-required kind/cleanup Categorizes issue or PR as related to cleaning up code, process kind/refactor Categorizes issue or PR as related to a refactoring
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants