diff --git a/.chloggen/mx-psi_featuregate-validation.yaml b/.chloggen/mx-psi_featuregate-validation.yaml index ce25d669ede..5799edbfcf8 100755 --- a/.chloggen/mx-psi_featuregate-validation.yaml +++ b/.chloggen/mx-psi_featuregate-validation.yaml @@ -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]' diff --git a/featuregate/registry.go b/featuregate/registry.go index b43a33e4466..669f4ac6139 100644 --- a/featuregate/registry.go +++ b/featuregate/registry.go @@ -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. @@ -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) diff --git a/featuregate/registry_test.go b/featuregate/registry_test.go index 0149c45b209..e720d004d95 100644 --- a/featuregate/registry_test.go +++ b/featuregate/registry_test.go @@ -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: "",