Skip to content
This repository has been archived by the owner on Oct 10, 2023. It is now read-only.

Decouple Feature-Flags from cli/runtime library and move to it to plugin specific code #3665

Merged
merged 5 commits into from
Nov 4, 2022

Conversation

anujc25
Copy link
Contributor

@anujc25 anujc25 commented Oct 14, 2022

What this PR does / why we need it

  • This PR decouples feature-flag definitions from the cli/runtime library and move it to plugin specific code
  • This change uses PluginDescriptor for a specific plugin to set the defaults for the feature-flags and core CLI configures the default values during plugin installation or during plugin upgrade.
  • The same default feature-flag values can also be configured with tanzu config init command if config file is updated manually and defaults needs to be set again.

Which issue(s) this PR fixes

Fixes #3447

Describe testing done for PR

  • Manual tests:

    • Clean tanzu config file
    • Run tanzu config get command
      • It only adds tanzu cli specific default feature-flags to the config
    • Install all plugins with tanzu plugin sync to install all plugins
      • Run tanzu config get and verify plugin specific default feature-flags are configured correctly.
    • Manually update the config.yaml to remove certain default feature-flags for installed plugin and then run tanzu config init
      • Verify that all default feature-flags for installed plugin are configured as expected.
  • Unit tests are written and validated as part of CI

Release note

Decouple Feature-Flags from `cli/runtime` library and move to it to plugin specific code

Additional information

Special notes for your reviewer

@github-actions
Copy link

Cluster Generation A/B Results:
https://storage.googleapis.com/tkg-clustergen/3665/20221014001726/clustergen.diff.txt
Author/reviewers:
Please review to verify that the effects on the generated cluster configurations are exactly what the PR intended, and give a thumbs-up if so.

@anujc25 anujc25 force-pushed the feature-flag-dep-remove-v3 branch from eea7447 to 5b7d66d Compare October 17, 2022 19:58
@github-actions
Copy link

Cluster Generation A/B Results:
https://storage.googleapis.com/tkg-clustergen/3665/20221017200832/clustergen.diff.txt
Author/reviewers:
Please review to verify that the effects on the generated cluster configurations are exactly what the PR intended, and give a thumbs-up if so.

@anujc25 anujc25 force-pushed the feature-flag-dep-remove-v3 branch 2 times, most recently from 1aecc07 to ffdfa37 Compare October 18, 2022 18:17
@github-actions
Copy link

Cluster Generation A/B Results:
https://storage.googleapis.com/tkg-clustergen/3665/20221018182243/clustergen.diff.txt
Author/reviewers:
Please review to verify that the effects on the generated cluster configurations are exactly what the PR intended, and give a thumbs-up if so.

@github-actions
Copy link

Cluster Generation A/B Results:
https://storage.googleapis.com/tkg-clustergen/3665/20221018182756/clustergen.diff.txt
Author/reviewers:
Please review to verify that the effects on the generated cluster configurations are exactly what the PR intended, and give a thumbs-up if so.

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.

I haven't looked at the code yet, but I noticed that I still see the tkr-version-v1alpha3-beta feature flag under the global list. Is this correct?

$ rm ~/.config/tanzu/config.yaml
$ tanzu config init
✔  successfully initialized the config
$ tanzu config get |grep global: -A5
    global:
      context-aware-cli-for-plugins: "true"
      context-target: "false"
      tkr-version-v1alpha3-beta: "false"
    management-cluster:
      aws-instance-types-exclude-arm: "true"

@marckhouzam
Copy link
Contributor

I haven't looked at the code yet, but I noticed that I still see the tkr-version-v1alpha3-beta feature flag under the global list. Is this correct?

The constant used for this option is features.global.tkr-version-v1alpha3-beta which uses global instead of the plugin name. Maybe we cannot change it because of backwards compatibility?

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.

This is a vey nice decoupling. Some minor comments in line and one question below.

When we delete a plugin, we don't delete its feature flags from the config file. That is probably on purpose so that if the user installs the plugin back, they keep their configuration? I think this is a good approach, I just wanted to confirm in case the question comes up later.

cli/core/pkg/config/featureflags.go Outdated Show resolved Hide resolved
cli/core/pkg/config/featureflags.go Outdated Show resolved Hide resolved
cli/core/pkg/config/featureflags.go Outdated Show resolved Hide resolved
tkg/constants/featureflags.go Show resolved Hide resolved
FeatureFlagPackageBasedLCM = "features.global.package-based-lcm-beta"
// TKR version v1alpha3 feature flag determines whether to use Tanzu Kubernetes Release API version v1alpha3. Setting
// feature flag to true will allow to use the TKR version v1alpha3; false allows to use legacy TKR version v1alpha1
FeatureFlagTKRVersionV1Alpha3 = "features.global.tkr-version-v1alpha3-beta"
Copy link
Contributor

Choose a reason for hiding this comment

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

Was it a mistake that this constant uses "features.global"? I guess we cannot correct it because it would break existing user config files?

If that is the case, it would deserve a comment in the new location of this constant

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah. I believe this should have been used as a plugin specific constants but it was used as global assuming multiple plugin might rely on them.

Considering, these feature-flags are always false by default at the moment, we might be able to change it if required. But that means all testing scripts need to be updated as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

What testing scripts are you referring to? I don't see that string used in TF anywhere else.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was more talking about product level testing and not in TF testing.

cli/core/pkg/config/init.go Show resolved Hide resolved
cli/core/pkg/config/features.go Show resolved Hide resolved
cli/core/pkg/command/config.go Show resolved Hide resolved
cli/core/pkg/command/config.go Show resolved Hide resolved
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.

Also, we should update the config-feature.md file with the new approach.

For developers making use of this feature:
* To set a default value in the tanzu config file, add an entry to `DefaultCliFeatureFlags` (in pkg/v1/config/clientconfig.go)
* Users can change the value by using the command above, or by manually editing their tanzu config file
* Throughout your code, you may use `cfg.IsConfigFeatureActivated()` to check the flag value (in apis/config/v1alpha1/clientconfig.go)
If you want to make this feature available for a beta period:
* To let users know the feature is available but still under development, use a `false` default value; when ready for production, change to `true`. This will create an entry in
their config file so they can see the flag name.
* We recommend using two flags, one for the beta period and one for production. For the beta period, simply append `-beta` to the flag name that you expect to use in production.
For example, your production flag might be `features.cluster.foobar` and for the beta you could use `features.cluster.foobar-beta`. There are two advantages to this approach:
(1) The user is clear when they are using a beta flag and when they are using a production flag,
(2) There are no transition issues between beta flag use and production. (If you use the same flag name for beta and for production, then when the production code runs the
previous "beta" setting will be taken as the production setting. This would force either the user or an installation script to activate the flag from `false` to `true` using
the `tanzu set config` command above. Using two different flag names, there is no such issue.)
NOTE: there is no code that detects `-beta`; it is simply a recommended naming convention.

@codecov
Copy link

codecov bot commented Oct 25, 2022

Codecov Report

Merging #3665 (60b1d67) into main (0db3776) will decrease coverage by 0.98%.
The diff coverage is 17.04%.

❗ Current head 60b1d67 differs from pull request most recent head 468a334. Consider uploading reports for the commit 468a334 to get more accurate results

@@            Coverage Diff             @@
##             main    #3665      +/-   ##
==========================================
- Coverage   46.60%   45.62%   -0.99%     
==========================================
  Files         400      425      +25     
  Lines       39726    41277    +1551     
==========================================
+ Hits        18516    18832     +316     
- Misses      19513    20731    +1218     
- Partials     1697     1714      +17     
Impacted Files Coverage Δ
cli/core/pkg/command/config.go 37.60% <0.00%> (+1.44%) ⬆️
cli/core/pkg/command/context.go 6.97% <0.00%> (ø)
cli/core/pkg/command/doc.go 3.07% <0.00%> (ø)
cli/core/pkg/command/init.go 4.87% <0.00%> (ø)
cli/core/pkg/command/plugin_manager.go 7.58% <0.00%> (ø)
cli/core/pkg/command/root.go 0.00% <0.00%> (ø)
cli/core/pkg/command/update.go 5.19% <0.00%> (ø)
cli/core/pkg/pluginmanager/manager.go 62.37% <0.00%> (-0.31%) ⬇️
cmd/cli/plugin/cluster/main.go 0.00% <ø> (ø)
cmd/cli/plugin/package/main.go 0.00% <0.00%> (ø)
... and 48 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@anujc25 anujc25 force-pushed the feature-flag-dep-remove-v3 branch from ffdfa37 to 60b1d67 Compare October 26, 2022 07:46
@github-actions
Copy link

Cluster Generation A/B Results:
https://storage.googleapis.com/tkg-clustergen/3665/20221026075547/clustergen.diff.txt
Author/reviewers:
Please review to verify that the effects on the generated cluster configurations are exactly what the PR intended, and give a thumbs-up if so.

descriptors, err := cli.ListPlugins()

for _, desc := range append(serverPluginDescriptors, standalonePluginDescriptors...) {
config.AddDefaultFeatureFlagsIfMissing(cfg, desc.DefaultFeatureFlags)
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens when the core CLI is managing older plugins that do not provide these default flags?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Older plugins can take care of updating this DefaultFeatureFlag by themselves because of the way they are importing the tanzu-framework as a dependency. There is a func init that gets run every-time which configures this feature-flags if they are missing with each plugin invocation.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah, thanks.

// TODO: cli.ListPlugins is deprecated: Use pluginmanager.AvailablePluginsFromLocalSource or pluginmanager.AvailablePlugins instead
descriptors, err := cli.ListPlugins()

for _, desc := range append(serverPluginDescriptors, standalonePluginDescriptors...) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The (newly added) context-specific aspect of config init is not very intuitive (especially for folks who have used it before without having to think about this aspect). To properly reconstruct all the defaults in the config file, one may now have to switch contexts so that all plugins which offers default values are covered. If the user does not learn of this new behavior, he could think that a single config init would fix/initialize the config file, without realizing that it only partially initializes the file.

Would iterating through all installed plugins be an option?

If we choose to stick with the current implementation, I would still suggest

  • putting a comment to note this behavior
  • see if we can provide some doc and/or UX feedback to the user about the same (maybe in the help text of the config init command)

Copy link
Contributor Author

@anujc25 anujc25 Nov 1, 2022

Choose a reason for hiding this comment

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

I think iterating through all installed plugins might be overkill. Considering user might have substantial amount of plugins installed and some of them are not used anymore.

I think adding a more details in the tanzu config init help text and providing comment in the code should be sufficient I feel. I will do the necessary changes to add more details.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that sounds reasonable. We should make sure any docs we produce capture the details as well.
I suggest we tag the issue and this PR with docs-triage-needed to raise some awareness.

Signed-off-by: Anuj Chaudhari <anujc@vmware.com>
Signed-off-by: Anuj Chaudhari <anujc@vmware.com>
…ig init`

Signed-off-by: Anuj Chaudhari <anujc@vmware.com>
Signed-off-by: Anuj Chaudhari <anujc@vmware.com>
@anujc25 anujc25 force-pushed the feature-flag-dep-remove-v3 branch from 60b1d67 to 1e6d87d Compare November 1, 2022 18:03
Signed-off-by: Anuj Chaudhari <anujc@vmware.com>
@anujc25 anujc25 force-pushed the feature-flag-dep-remove-v3 branch from 1e6d87d to 468a334 Compare November 1, 2022 18:05
@github-actions
Copy link

github-actions bot commented Nov 1, 2022

Cluster Generation A/B Results:
https://storage.googleapis.com/tkg-clustergen/3665/20221101181406/clustergen.diff.txt
Author/reviewers:
Please review to verify that the effects on the generated cluster configurations are exactly what the PR intended, and give a thumbs-up if so.

@github-actions
Copy link

github-actions bot commented Nov 1, 2022

Cluster Generation A/B Results:
https://storage.googleapis.com/tkg-clustergen/3665/20221101181552/clustergen.diff.txt
Author/reviewers:
Please review to verify that the effects on the generated cluster configurations are exactly what the PR intended, and give a thumbs-up if so.

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
Sorry for the delay

@vuil vuil added ok-to-merge PRs should be labelled with this before merging docs-triage-needed labels Nov 3, 2022
Copy link
Contributor

@vuil vuil left a comment

Choose a reason for hiding this comment

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

lgtm

@anujc25 anujc25 merged commit 1c7edd7 into vmware-tanzu:main Nov 4, 2022
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
cla-not-required docs-triage-needed ok-to-merge PRs should be labelled with this before merging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Plugin specific Feature-Flags should not be defined in plugin runtime library (cli/runtime)
4 participants