factor our cloudprovider.DeprecationWarningForProvider

this change removes the deprecation warning function in favor of using
the `cloudprovider.DisableWarningForProvider`. it also fixes some of the
logic to ensure that non-external providers are properly detected and
warned about.
This commit is contained in:
elmiko
2024-09-27 10:03:18 -04:00
parent d1d05d3eba
commit 38fe239ac4
5 changed files with 28 additions and 67 deletions

View File

@@ -19,9 +19,7 @@ package app
import (
"fmt"
utilfeature "k8s.io/apiserver/pkg/util/feature"
"k8s.io/klog/v2"
"k8s.io/kubernetes/pkg/features"
"k8s.io/client-go/informers"
cloudprovider "k8s.io/cloud-provider"
@@ -32,18 +30,10 @@ import (
func createCloudProvider(logger klog.Logger, cloudProvider string, externalCloudVolumePlugin string, cloudConfigFile string,
allowUntaggedCloud bool, sharedInformers informers.SharedInformerFactory) (cloudprovider.Interface, ControllerLoopMode, error) {
var cloud cloudprovider.Interface
var loopMode ControllerLoopMode
var err error
if utilfeature.DefaultFeatureGate.Enabled(features.DisableCloudProviders) && !cloudprovider.IsExternal(cloudProvider) {
cloudprovider.DisableWarningForProvider(cloudProvider)
return nil, ExternalLoops, fmt.Errorf(
"cloud provider %q was specified, but built-in cloud providers are disabled. Please set --cloud-provider=external and migrate to an external cloud provider",
cloudProvider)
}
loopMode := ExternalLoops
if cloudprovider.IsExternal(cloudProvider) {
loopMode = ExternalLoops
if externalCloudVolumePlugin == "" {
// externalCloudVolumePlugin is temporary until we split all cloud providers out.
// So we just tell the caller that we need to run ExternalLoops without any cloud provider.
@@ -51,10 +41,17 @@ func createCloudProvider(logger klog.Logger, cloudProvider string, externalCloud
}
cloud, err = cloudprovider.InitCloudProvider(externalCloudVolumePlugin, cloudConfigFile)
} else {
cloudprovider.DeprecationWarningForProvider(cloudProvider)
loopMode = IncludeCloudLoops
cloud, err = cloudprovider.InitCloudProvider(cloudProvider, cloudConfigFile)
// in the case where the cloudProvider is not set, we need to inform the caller that there
// is no cloud provider and that the default loops should be used, and there is no error.
// this will cause the kube-controller-manager to start the default controller contexts
// without being attached to a specific cloud.
if len(cloudProvider) == 0 {
loopMode = IncludeCloudLoops
} else {
// for all other cloudProvider values the internal cloud loops are disabled
cloudprovider.DisableWarningForProvider(cloudProvider)
err = cloudprovider.ErrorForDisabledProvider(cloudProvider)
}
}
if err != nil {
return nil, loopMode, fmt.Errorf("cloud provider could not be initialized: %v", err)

View File

@@ -651,16 +651,10 @@ func run(ctx context.Context, s *options.KubeletServer, kubeDeps *kubelet.Depend
}
if kubeDeps.Cloud == nil {
if !cloudprovider.IsExternal(s.CloudProvider) {
cloudprovider.DeprecationWarningForProvider(s.CloudProvider)
cloud, err := cloudprovider.InitCloudProvider(s.CloudProvider, s.CloudConfigFile)
if err != nil {
return err
}
if cloud != nil {
klog.V(2).InfoS("Successfully initialized cloud provider", "cloudProvider", s.CloudProvider, "cloudConfigFile", s.CloudConfigFile)
}
kubeDeps.Cloud = cloud
if !cloudprovider.IsExternal(s.CloudProvider) && len(s.CloudProvider) != 0 {
// internal cloud provider loops are disabled
cloudprovider.DisableWarningForProvider(s.CloudProvider)
return cloudprovider.ErrorForDisabledProvider(s.CloudProvider)
}
}