diff --git a/pkg/volume/azure_file/azure_file_test.go b/pkg/volume/azure_file/azure_file_test.go index 1a82905157a..bb60288d236 100644 --- a/pkg/volume/azure_file/azure_file_test.go +++ b/pkg/volume/azure_file/azure_file_test.go @@ -87,14 +87,10 @@ func getAzureTestCloud(t *testing.T) *azure.Cloud { "aadClientSecret": "--aad-client-secret--" }` configReader := strings.NewReader(config) - cloud, err := azure.NewCloud(configReader) + azureCloud, err := azure.NewCloudWithoutFeatureGates(configReader) if err != nil { t.Error(err) } - azureCloud, ok := cloud.(*azure.Cloud) - if !ok { - t.Error("NewCloud returned incorrect type") - } return azureCloud } diff --git a/staging/src/k8s.io/legacy-cloud-providers/azure/BUILD b/staging/src/k8s.io/legacy-cloud-providers/azure/BUILD index a6f5a879ce2..d410cf087c2 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/azure/BUILD +++ b/staging/src/k8s.io/legacy-cloud-providers/azure/BUILD @@ -45,7 +45,6 @@ go_library( "//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/types:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/util/errors:go_default_library", - "//staging/src/k8s.io/apimachinery/pkg/util/runtime:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/util/uuid:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/util/wait:go_default_library", diff --git a/staging/src/k8s.io/legacy-cloud-providers/azure/azure.go b/staging/src/k8s.io/legacy-cloud-providers/azure/azure.go index 942b2c21e40..5dd572fcf0b 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/azure/azure.go +++ b/staging/src/k8s.io/legacy-cloud-providers/azure/azure.go @@ -32,7 +32,6 @@ import ( "github.com/Azure/go-autorest/autorest/azure" v1 "k8s.io/api/core/v1" - utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/wait" utilfeature "k8s.io/apiserver/pkg/util/feature" @@ -264,6 +263,18 @@ func init() { // NewCloud returns a Cloud with initialized clients func NewCloud(configReader io.Reader) (cloudprovider.Interface, error) { + az, err := NewCloudWithoutFeatureGates(configReader) + if err != nil { + return nil, err + } + az.ipv6DualStackEnabled = utilfeature.DefaultFeatureGate.Enabled(IPv6DualStack) + + return az, nil +} + +// NewCloudWithoutFeatureGates returns a Cloud without trying to wire the feature gates. This is used by the unit tests +// that don't load the actual features being used in the cluster. +func NewCloudWithoutFeatureGates(configReader io.Reader) (*Cloud, error) { config, err := parseConfig(configReader) if err != nil { return nil, err @@ -275,18 +286,6 @@ func NewCloud(configReader io.Reader) (cloudprovider.Interface, error) { unmanagedNodes: sets.NewString(), routeCIDRs: map[string]string{}, } - func() { - // this allows the code ot launch without featuregates defined. It is currently required for unit tests where the - // featuregates are not registered. This is effectively coding by side effect and an explicit register should - // be eventually created instead. - defer func() { - if r := recover(); r != nil { - utilruntime.HandleError(fmt.Errorf("%v", r)) - } - }() - - az.ipv6DualStackEnabled = utilfeature.DefaultFeatureGate.Enabled(IPv6DualStack) - }() err = az.InitializeCloudFromConfig(config, false) if err != nil { diff --git a/staging/src/k8s.io/legacy-cloud-providers/azure/azure_test.go b/staging/src/k8s.io/legacy-cloud-providers/azure/azure_test.go index e7005279d2f..9f54eb4f5e2 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/azure/azure_test.go +++ b/staging/src/k8s.io/legacy-cloud-providers/azure/azure_test.go @@ -1701,14 +1701,10 @@ func validateConfig(t *testing.T, config string) { func getCloudFromConfig(t *testing.T, config string) *Cloud { configReader := strings.NewReader(config) - cloud, err := NewCloud(configReader) + azureCloud, err := NewCloudWithoutFeatureGates(configReader) if err != nil { t.Error(err) } - azureCloud, ok := cloud.(*Cloud) - if !ok { - t.Error("NewCloud returned incorrect type") - } return azureCloud }