diff --git a/featuregate/gate.go b/featuregate/gate.go index a250ceb9a86..f93c86db663 100644 --- a/featuregate/gate.go +++ b/featuregate/gate.go @@ -52,7 +52,8 @@ func (g *Gate) FromVersion() string { return fmt.Sprintf("v%s", g.fromVersion) } -// ToVersion returns the version information when Gate's in StageStable. +// ToVersion specifies the version in which a feature gate in StageStable +// is scheduled to be removed. This is only applicable for features in StageStable and should be set to nil for features in other stages. func (g *Gate) ToVersion() string { return fmt.Sprintf("v%s", g.toVersion) } diff --git a/featuregate/registry.go b/featuregate/registry.go index 00e6ec21518..ebaa355411d 100644 --- a/featuregate/registry.go +++ b/featuregate/registry.go @@ -142,7 +142,12 @@ func (r *Registry) Register(id string, stage Stage, opts ...RegisterOption) (*Ga return nil, fmt.Errorf("failed to apply option: %w", err) } } - switch g.stage { + if g.ToVersion != nil { + if g.Stage != StageStable && !g.Stage.IsDeprecated(){ + return fmt.Errorf("ToVersion can only be set for stable or deprecated stages") + } + } + switch g.stage { case StageAlpha, StageDeprecated: g.enabled = &atomic.Bool{} case StageBeta, StageStable: