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
Add features package #1849
Changes from 15 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
97b19ff
Add features package
nrb 025794c
Make config a more generic map with acessors
nrb 379854e
Refactor to make features a global
nrb c67a97d
Provide known feature flags to plugins
nrb 575641e
Move feature flag argument parsing to command
nrb 79c13a0
Address review feedback and improve usage
nrb 2c618c6
Improve data type handling on config struct
nrb bb26cc6
Remove mutexes from feature flagset
nrb a80c59e
Move config processing into the main command
nrb 02f0794
Comment on PersistentPreRun function behavior
nrb 4340013
Only pass features arg to plugins when present
nrb 1f7274b
Log enabled features on server startup
nrb f522601
Add client feature list to bug template
nrb e4428f0
Fix spacing
nrb c2c365a
Add changelog
nrb fec779c
Remove blank line
nrb File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add `--features` argument to all velero commands to provide feature flags that can control enablement of pre-release features. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
Copyright 2019 the Velero contributors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package client | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestVeleroConfig(t *testing.T) { | ||
c := VeleroConfig{ | ||
"namespace": "foo", | ||
"features": "feature1,feature2", | ||
} | ||
|
||
assert.Equal(t, "foo", c.Namespace()) | ||
assert.Equal(t, []string{"feature1", "feature2"}, c.Features()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
Copyright 2019 the Velero contributors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package features | ||
|
||
import ( | ||
"strings" | ||
|
||
"k8s.io/apimachinery/pkg/util/sets" | ||
) | ||
|
||
type featureFlagSet struct { | ||
set sets.String | ||
} | ||
|
||
// featureFlags will store all the flags for this process until NewFeatureFlagSet is called. | ||
var featureFlags featureFlagSet | ||
|
||
// IsEnabled returns True if a specified flag is enabled. | ||
func IsEnabled(name string) bool { | ||
return featureFlags.set.Has(name) | ||
} | ||
|
||
// Enable adds a given slice of feature names to the current feature list. | ||
func Enable(names ...string) { | ||
// Initialize the flag set so that users don't have to | ||
if featureFlags.set == nil { | ||
NewFeatureFlagSet() | ||
} | ||
|
||
featureFlags.set.Insert(names...) | ||
} | ||
|
||
// Disable removes all feature flags in a given slice from the current feature list. | ||
func Disable(names ...string) { | ||
|
||
nrb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
featureFlags.set.Delete(names...) | ||
} | ||
|
||
// All returns enabled features as a slice of strings. | ||
func All() []string { | ||
return featureFlags.set.List() | ||
} | ||
|
||
// Serialize returns all features as a comma-separated string. | ||
func Serialize() string { | ||
return strings.Join(All(), ",") | ||
} | ||
|
||
// NewFeatureFlagSet initializes and populates a new FeatureFlagSet. | ||
// This must be called to properly initialize the set for tracking flags. | ||
// It is also useful for selectively controlling flags during tests. | ||
func NewFeatureFlagSet(flags ...string) { | ||
featureFlags = featureFlagSet{ | ||
set: sets.NewString(flags...), | ||
} | ||
} |
Oops, something went wrong.
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.
Very subjective, but I think this and the next function would read better if the check on the map key was all inlined.
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.
I think we can't do this here since
val
is used outside theif...
block?