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

Add features package #1849

Merged
merged 16 commits into from Sep 18, 2019
Merged

Add features package #1849

merged 16 commits into from Sep 18, 2019

Conversation

nrb
Copy link
Contributor

@nrb nrb commented Sep 5, 2019

This PR creates the features package and the necessary plumbing for flags to be enabled at the command line and in the configuration file.

Closes #1798

@nrb
Copy link
Contributor Author

nrb commented Sep 5, 2019

Looking at how this is currently written, how one might consume it, and based on the design proposal, I think it might make more sense to do an API like this within the features package:

var flags sets.String

func Enabled(name string) bool {
  flags.Has(name)
}

func Enable(names ...string) {
  flags.Insert(names....)
}

func All() []string {
  return flags.List()
}

This then skips requiring initializing our own flag set struct, and callers can simply use features.Enable("myfeature") and features.Enabled("myfeature").

I can simplify the enabling code by just doing features.Enable(config.Features()...) and features.Enable(cmdFeatures...).

What do others think of that?

@nrb
Copy link
Contributor Author

nrb commented Sep 5, 2019

I'm asking about this slightly different design because passing around a flag set on the client's factory seems a bit unwieldy for something that should be accessible ~anywhere in the code base easily.

I guess the last question I would have is if we're terribly concerned with concurrent access to the flag list, but I'm assuming that is something we don't have to address until later.

Signed-off-by: Nolan Brubaker <brubakern@vmware.com>
Signed-off-by: Nolan Brubaker <brubakern@vmware.com>
Signed-off-by: Nolan Brubaker <brubakern@vmware.com>
@nrb nrb force-pushed the fix-1798 branch 2 times, most recently from f04a276 to 2d65c2b Compare September 9, 2019 16:37
Feature flags must be consumed as the `--features` command line
argument. There is currently no plugin API change in order to minimize
changes.

Signed-off-by: Nolan Brubaker <brubakern@vmware.com>
Copy link
Contributor

@carlisia carlisia left a comment

Choose a reason for hiding this comment

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

One minor comment for now.

@@ -76,6 +81,24 @@ func SaveConfig(config map[string]string) error {
return json.NewEncoder(configFile).Encode(&config)
}

func (c VeleroConfig) Namespace() string {
ns, ok := c[ConfigKeyNamespace]
if !ok {
Copy link
Contributor

Choose a reason for hiding this comment

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

Very subjective, but I think this and the next function would read better if the check on the map key was all inlined.

Copy link
Member

Choose a reason for hiding this comment

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

I think we can't do this here since val is used outside the if... block?

@nrb
Copy link
Contributor Author

nrb commented Sep 11, 2019

@skriss @prydonius Curious about your thoughts on this approach before I proceed further.

@prydonius
Copy link
Contributor

because passing around a flag set on the client's factory seems a bit unwieldy for something that should be accessible ~anywhere in the code base easily.

I would agree, seems like a global here would be a lot easier. As far as concurrent access, seems like we'll only need to set the flags once at the start of the server, so not sure that we really need the mutexes?

@nrb
Copy link
Contributor Author

nrb commented Sep 12, 2019

As far as concurrent access, seems like we'll only need to set the flags once at the start of the server, so not sure that we really need the mutexes?

True - part of my concern there came when I realized this might be used by plugins. If we think it's overkill I can definitely remove.

@prydonius
Copy link
Contributor

Ah okay, do we expect plugins to enable/disable features?

@nrb
Copy link
Contributor Author

nrb commented Sep 12, 2019

I'm thinking they'll have to inside their process. As an example, this code passes the --features argument to any plugin processes, so they'll know what features have been activated by the main server process. For the in-tree plugins, they'll enable them because the root velero command enables them. Other plugins could consume and enable/disable these and they see fit, I presume.

As a concrete example of passing to plugins, I would think any CSI plugin would check for the relevant feature before doing any work, and exit as a no-op if it's not enabled.

Copy link
Member

@skriss skriss left a comment

Choose a reason for hiding this comment

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

Approach WFM, added some comments.

pkg/client/config.go Outdated Show resolved Hide resolved
pkg/client/config.go Outdated Show resolved Hide resolved
pkg/client/factory.go Outdated Show resolved Hide resolved
pkg/client/factory.go Outdated Show resolved Hide resolved
pkg/features/feature_flags.go Outdated Show resolved Hide resolved
pkg/features/feature_flags.go Outdated Show resolved Hide resolved
pkg/plugin/clientmgmt/client_builder.go Outdated Show resolved Hide resolved
The client factory isn't where the features flags should get
initialized, as it's not guaranteed to be around.

Signed-off-by: Nolan Brubaker <brubakern@vmware.com>
Users shouldn't have to call NewFeatureFlagSet, so Enable will call it
for them if necessary.

Signed-off-by: Nolan Brubaker <brubakern@vmware.com>
Signed-off-by: Nolan Brubaker <brubakern@vmware.com>
Signed-off-by: Nolan Brubaker <brubakern@vmware.com>
Signed-off-by: Nolan Brubaker <brubakern@vmware.com>
Signed-off-by: Nolan Brubaker <brubakern@vmware.com>
Signed-off-by: Nolan Brubaker <brubakern@vmware.com>
Signed-off-by: Nolan Brubaker <brubakern@vmware.com>
Signed-off-by: Nolan Brubaker <brubakern@vmware.com>
@nrb
Copy link
Contributor Author

nrb commented Sep 17, 2019

I believe I've addressed all the feedback now. Mutexes were removed since I don't think they provided much value.

I'm thinking it may be useful to add feature information to the ServerStatusRequest struct so that the client may request them along with the server's version; what do others think? If that's acceptable, I think I'd rather open a new issue/PR to add it versus continuing with this PR.

@nrb nrb marked this pull request as ready for review September 17, 2019 19:11
@skriss
Copy link
Member

skriss commented Sep 17, 2019

I'm thinking it may be useful to add feature information to the ServerStatusRequest struct so that the client may request them along with the server's version; what do others think? If that's acceptable, I think I'd rather open a new issue/PR to add it versus continuing with this PR.

It does seem useful though the only CLI command that exposes the ServerStatusRequest right now is velero version, which wouldn't really make sense for displaying this information. #1094 would probably be the more sensible path.

@nrb
Copy link
Contributor Author

nrb commented Sep 17, 2019

The velero plugins get command uses it, too, but I agree, it's not quite a good fit for velero version. That's part of the reason I'd like to move that to a different issue.

Copy link
Member

@skriss skriss left a comment

Choose a reason for hiding this comment

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

Mostly LGTM, just one style nit.

Have you been able to manually verify the flag-parsing for both server and CLI commands?

pkg/client/config.go Show resolved Hide resolved
@skriss
Copy link
Member

skriss commented Sep 17, 2019

The velero plugins get command uses it, too, but I agree, it's not quite a good fit for velero version. That's part of the reason I'd like to move that to a different issue.

Yep - makes sense to me.

Signed-off-by: Nolan Brubaker <brubakern@vmware.com>
@nrb
Copy link
Contributor Author

nrb commented Sep 17, 2019

Yeah, I've tested this with backup commands using the CLI option, CLI option + config file, and both. I've also done the same with the server command. I can see the feature getting passed down to plugins too.

There's one thing that may be an issue - now that we have the root velero command reading in the config, it can be used by velero server. This could lead to a feature being read in unintentionally during local development, though the file won't be present on actual server installs.

It could also be a local development convenience, so I'm unsure if I want to add any sort of conditional loading logic.

Signed-off-by: Nolan Brubaker <brubakern@vmware.com>
Copy link
Contributor

@prydonius prydonius left a comment

Choose a reason for hiding this comment

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

lgtm - one small formatting issue!

pkg/features/feature_flags.go Outdated Show resolved Hide resolved
@skriss
Copy link
Member

skriss commented Sep 18, 2019

There's one thing that may be an issue - now that we have the root velero command reading in the config, it can be used by velero server. This could lead to a feature being read in unintentionally during local development, though the file won't be present on actual server installs.

I'm not too worried about this atm, guessing it'll be pretty obvious if that's happening.

Ready to merge once adnan's comment is addressed!

Signed-off-by: Nolan Brubaker <brubakern@vmware.com>
@nrb nrb mentioned this pull request Sep 18, 2019
Copy link
Member

@skriss skriss left a comment

Choose a reason for hiding this comment

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

LGTM

@skriss skriss merged commit 8ec1548 into vmware-tanzu:master Sep 18, 2019
jessestuart added a commit to jessestuart/velero that referenced this pull request Sep 28, 2019
* upstream/master: (38 commits)
  sync controller: replace revision file with full diff each interval (vmware-tanzu#1892)
  Increment logging for item backupper (vmware-tanzu#1904)
  Add LD_LIBRARY_PATH as an env varible for the use of vsphere plugin (vmware-tanzu#1893)
  Remove unused flag (vmware-tanzu#1913)
  Use layers in the builder Dockerfile (vmware-tanzu#1907)
  Fix for vmware-tanzu#1888: check item's original namespace, not remapped one, for inclusion/exclusion (vmware-tanzu#1909)
  fail on make verify if generated CRDs differ (vmware-tanzu#1906)
  velero API type changes for structural schema CRDs (vmware-tanzu#1898)
  Generate CRDs with structural schema (vmware-tanzu#1885)
  Plan for moving plugin repos (vmware-tanzu#1870)
  move plugin proto updating into make update (vmware-tanzu#1887)
  Add features package (vmware-tanzu#1849)
  GCP: support specifying Cloud KMS key name for backup storage locations (vmware-tanzu#1879)
  Adds to website (vmware-tanzu#1882)
  proposal for generating Velero CRDs with structural schema (vmware-tanzu#1875)
  Improve contributing docs (vmware-tanzu#1852)
  [doc] Diagram (image) now mentions velero  (vmware-tanzu#1877)
  AWS: add support for arbitrary SSE algorithms, e.g. AES256 (vmware-tanzu#1869)
  update restic docs for PR vmware-tanzu#1807 (vmware-tanzu#1867)
  changelog for PR vmware-tanzu#1864
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement feature flag package
4 participants