Skip to content

Commit

Permalink
factor our cloudprovider.DeprecationWarningForProvider
Browse files Browse the repository at this point in the history
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
  • Loading branch information
elmiko authored and k8s-publishing-bot committed Sep 27, 2024
1 parent 23264ab commit 3d043ef
Showing 1 changed file with 10 additions and 31 deletions.
41 changes: 10 additions & 31 deletions plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 3d043ef

Please sign in to comment.