From 23264abd053f39c6caff0bf6375b8348352351d7 Mon Sep 17 00:00:00 2001 From: elmiko Date: Thu, 26 Sep 2024 14:55:16 -0400 Subject: [PATCH 1/2] remove IsDeprecatedInternal from cloudprovider.plugins The internal cloud controller loops are disabled at this point, this function should not be used as it does not return accurate information. In its place we check for the presence of the external cloud provider as that is the only acceptable value. Kubernetes-commit: d1d05d3eba7d5627e9d010a5d3cce750ef974c99 --- plugins.go | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/plugins.go b/plugins.go index 458fff69..718016a2 100644 --- a/plugins.go +++ b/plugins.go @@ -85,18 +85,6 @@ func IsExternal(name string) bool { return name == externalCloudProvider } -// IsDeprecatedInternal is responsible for preventing cloud.Interface -// from being initialized in kubelet, kube-controller-manager or kube-api-server -func IsDeprecatedInternal(name string) bool { - for _, provider := range deprecatedCloudProviders { - if provider.name == name { - return true - } - } - - return false -} - // DisableWarningForProvider logs information about disabled cloud provider state func DisableWarningForProvider(providerName string) { for _, provider := range deprecatedCloudProviders { From 3d043efb7f47b5e11e0422b8708c910aff6544fb Mon Sep 17 00:00:00 2001 From: elmiko Date: Fri, 27 Sep 2024 10:03:18 -0400 Subject: [PATCH 2/2] 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. Kubernetes-commit: 38fe239ac44050c2ed83ffb8ea7e514db71f903f --- plugins.go | 41 ++++++++++------------------------------- 1 file changed, 10 insertions(+), 31 deletions(-) diff --git a/plugins.go b/plugins.go index 718016a2..8ef778b1 100644 --- a/plugins.go +++ b/plugins.go @@ -33,13 +33,8 @@ type Factory func(config io.Reader) (Interface, error) // All registered cloud providers. var ( - providersMutex sync.Mutex - providers = make(map[string]Factory) - deprecatedCloudProviders = []struct { - name string - external bool - detail string - }{} + providersMutex sync.Mutex + providers = make(map[string]Factory) ) const externalCloudProvider = "external" @@ -87,33 +82,17 @@ func IsExternal(name string) bool { // DisableWarningForProvider logs information about disabled cloud provider state func DisableWarningForProvider(providerName string) { - for _, provider := range deprecatedCloudProviders { - if provider.name == providerName { - klog.Infof("INFO: Please make sure you are running external cloud controller manager binary for provider %q."+ - "In-tree cloud providers are currently disabled. Refer to https://github.com/kubernetes/kubernetes/tree/master/staging/src/k8s.io/cloud-provider/sample"+ - "for example implementation.", providerName) - detail := fmt.Sprintf("Please reach to sig-cloud-provider and use 'external' cloud provider for %q: %s", providerName, provider.detail) - klog.Warningf("WARNING: %q built-in cloud provider is now disabled. %s", providerName, detail) - break - } + if !IsExternal(providerName) { + klog.Infof("INFO: Please make sure you are running an external cloud controller manager binary for provider %q."+ + "In-tree cloud providers are disabled. Refer to https://github.com/kubernetes/kubernetes/tree/master/staging/src/k8s.io/cloud-provider/sample "+ + "for an example implementation.", providerName) + klog.Warningf("WARNING: built-in cloud providers are disabled. Please set \"--cloud-provider=external\" and migrate to an external cloud controller manager for provider %q", providerName) } } -// DeprecationWarningForProvider logs information about deprecated cloud provider state -func DeprecationWarningForProvider(providerName string) { - for _, provider := range deprecatedCloudProviders { - if provider.name != providerName { - continue - } - - detail := provider.detail - if provider.external { - detail = fmt.Sprintf("Please use 'external' cloud provider for %s: %s", providerName, provider.detail) - } - - klog.Warningf("WARNING: %s built-in cloud provider is now deprecated. %s", providerName, detail) - break - } +// ErrorForDisabledProvider returns an error formatted with the supplied provider name +func ErrorForDisabledProvider(providerName string) error { + return 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", providerName) } // InitCloudProvider creates an instance of the named cloud provider.