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

[featuregate] Allow underscores in featuregate IDs #8865

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .chloggen/mx-psi_featuregate-validation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ issues: [8766]
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext: |
Feature gates IDs are now explicitly restricted to ASCII alphanumerics and dots.
Feature gates IDs are now explicitly restricted to ASCII alphanumerics, underscores and dots.

# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
Expand Down
6 changes: 3 additions & 3 deletions featuregate/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ var (
globalRegistry = NewRegistry()

// idRegexp is used to validate the ID of a Gate.
// IDs' characters must be alphanumeric or dots.
idRegexp = regexp.MustCompile(`^[0-9a-zA-Z\.]*$`)
// IDs' characters must be alphanumeric, underscores or dots.
idRegexp = regexp.MustCompile(`^[0-9a-zA-Z_\.]*$`)
)

// GlobalRegistry returns the global Registry.
Expand Down Expand Up @@ -122,7 +122,7 @@ func validateID(id string) error {
}

// Register a Gate and return it. The returned Gate can be used to check if is enabled or not.
// id must be an ASCII alphanumeric nonempty string. Dots are allowed for namespacing.
// id must be an ASCII alphanumeric nonempty string. Dots are allowed for namespacing and underscores for snake casing.
func (r *Registry) Register(id string, stage Stage, opts ...RegisterOption) (*Gate, error) {
if err := validateID(id); err != nil {
return nil, fmt.Errorf("invalid ID %q: %w", id, err)
Expand Down
6 changes: 6 additions & 0 deletions featuregate/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ func TestRegisterGateLifecycle(t *testing.T) {
stage: StageAlpha,
shouldErr: true,
},
{
name: "Gate name with underscores",
id: "gcp.untyped_double_export",
stage: StageAlpha,
shouldErr: false,
},
{
name: "Invalid empty gate",
id: "",
Expand Down
Loading