remove feature gate from tests.

This commit is contained in:
Jiahui Feng 2022-03-28 12:40:45 -07:00
parent db3ec322d7
commit 84ef463481

View File

@ -23,49 +23,30 @@ import (
"testing" "testing"
"github.com/spf13/pflag" "github.com/spf13/pflag"
utilfeature "k8s.io/apiserver/pkg/util/feature"
featuregatetesting "k8s.io/component-base/featuregate/testing"
"k8s.io/controller-manager/config" "k8s.io/controller-manager/config"
"k8s.io/controller-manager/pkg/features"
migrationconfig "k8s.io/controller-manager/pkg/leadermigration/config" migrationconfig "k8s.io/controller-manager/pkg/leadermigration/config"
) )
func TestLeaderMigrationOptions(t *testing.T) { func TestLeaderMigrationOptions(t *testing.T) {
testCases := []struct { testCases := []struct {
name string name string
flags []string flags []string
configContent string configContent string
expectEnabled bool expectEnabled bool
expectErr bool expectErr bool
enableFeatureGate bool expectConfig *config.LeaderMigrationConfiguration
expectConfig *config.LeaderMigrationConfiguration
}{ }{
{ {
name: "default (disabled), with feature gate disabled", name: "enabled, with default configuration",
flags: []string{}, flags: []string{"--enable-leader-migration"},
enableFeatureGate: false, expectEnabled: true,
expectEnabled: false, expectErr: false,
expectErr: false, expectConfig: migrationconfig.DefaultLeaderMigrationConfiguration(),
}, },
{ {
name: "enabled, with feature gate disabled", name: "enabled, with custom configuration file",
flags: []string{"--enable-leader-migration"}, flags: []string{"--enable-leader-migration"},
enableFeatureGate: false, expectEnabled: true,
expectErr: true,
},
{
name: "enabled, with default configuration",
flags: []string{"--enable-leader-migration"},
enableFeatureGate: true,
expectEnabled: true,
expectErr: false,
expectConfig: migrationconfig.DefaultLeaderMigrationConfiguration(),
},
{
name: "enabled, with custom configuration file",
flags: []string{"--enable-leader-migration"},
enableFeatureGate: true,
expectEnabled: true,
configContent: ` configContent: `
apiVersion: controllermanager.config.k8s.io/v1alpha1 apiVersion: controllermanager.config.k8s.io/v1alpha1
kind: LeaderMigrationConfiguration kind: LeaderMigrationConfiguration
@ -81,10 +62,9 @@ controllerLeaders: []
}, },
}, },
{ {
name: "enabled, with custom configuration file (version v1beta1)", name: "enabled, with custom configuration file (version v1beta1)",
flags: []string{"--enable-leader-migration"}, flags: []string{"--enable-leader-migration"},
enableFeatureGate: true, expectEnabled: true,
expectEnabled: true,
configContent: ` configContent: `
apiVersion: controllermanager.config.k8s.io/v1beta1 apiVersion: controllermanager.config.k8s.io/v1beta1
kind: LeaderMigrationConfiguration kind: LeaderMigrationConfiguration
@ -102,7 +82,6 @@ controllerLeaders: []
} }
for _, tc := range testCases { for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.ControllerManagerLeaderMigration, tc.enableFeatureGate)()
flags := tc.flags flags := tc.flags
if tc.configContent != "" { if tc.configContent != "" {
configFile, err := ioutil.TempFile("", tc.name) configFile, err := ioutil.TempFile("", tc.name)