Skip to content

Commit 4061c3a

Browse files
Merge pull request #6367 from agullon/fix/reject-feature-gates-with-empty-featureset
OCPBUGS-78594: reject feature gate lists when FeatureSet is empty
2 parents c46ae08 + cc1a7cc commit 4061c3a

3 files changed

Lines changed: 22 additions & 1 deletion

File tree

etcd/vendor/github.com/openshift/microshift/pkg/config/apiserver.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/config/apiserver.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,18 @@ func (fg FeatureGates) GoString() string {
187187
// 4. If FeatureSet is CustomNoUpgrade, CustomNoUpgrade.Enabled/Disabled lists may be set but are not required.
188188
// 5. Required feature gates cannot be disabled.
189189
// 6. Feature gates cannot be both enabled and disabled within the same object.
190+
// 7. If FeatureSet is empty, CustomNoUpgrade and SpecialHandlingSupportExceptionRequired lists must also be empty.
190191
func (fg *FeatureGates) validateFeatureGates() error {
191192
if fg == nil || reflect.DeepEqual(*fg, FeatureGates{}) {
192193
return nil
193194
}
194195

195196
switch fg.FeatureSet {
196197
case "":
198+
if len(fg.CustomNoUpgrade.Enabled) > 0 || len(fg.CustomNoUpgrade.Disabled) > 0 ||
199+
len(fg.SpecialHandlingSupportExceptionRequired.Enabled) > 0 || len(fg.SpecialHandlingSupportExceptionRequired.Disabled) > 0 {
200+
return fmt.Errorf("CustomNoUpgrade and SpecialHandlingSupportExceptionRequired enabled/disabled lists must be empty when FeatureSet is empty")
201+
}
197202
return nil
198203
case FeatureSetCustomNoUpgrade:
199204
// Valid - continue with validation

pkg/config/config_test.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,18 @@ func TestValidate(t *testing.T) {
827827
c.ApiServer.FeatureGates.CustomNoUpgrade.Disabled = []string{"feature2"}
828828
return c
829829
}(),
830-
expectErr: false,
830+
expectErr: true,
831+
},
832+
{
833+
name: "feature-gates-special-handling-with-feature-set-empty",
834+
config: func() *Config {
835+
c := mkDefaultConfig()
836+
c.ApiServer.FeatureGates.FeatureSet = ""
837+
c.ApiServer.FeatureGates.SpecialHandlingSupportExceptionRequired.Enabled = []string{"feature1"}
838+
c.ApiServer.FeatureGates.SpecialHandlingSupportExceptionRequired.Disabled = []string{"feature2"}
839+
return c
840+
}(),
841+
expectErr: true,
831842
},
832843
{
833844
name: "feature-gates-custom-no-upgrade-valid",

0 commit comments

Comments
 (0)