k8s.io/kubernetes@v1.31.0-alpha.0.0.20240520171757-56147500dadc/cmd/kube-controller-manager/app/cloudproviders.go (about) 1 /* 2 Copyright 2018 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package app 18 19 import ( 20 "fmt" 21 22 utilfeature "k8s.io/apiserver/pkg/util/feature" 23 "k8s.io/klog/v2" 24 "k8s.io/kubernetes/pkg/features" 25 26 "k8s.io/client-go/informers" 27 cloudprovider "k8s.io/cloud-provider" 28 ) 29 30 // createCloudProvider helps consolidate what is needed for cloud providers, we explicitly list the things 31 // that the cloud providers need as parameters, so we can control 32 func createCloudProvider(logger klog.Logger, cloudProvider string, externalCloudVolumePlugin string, cloudConfigFile string, 33 allowUntaggedCloud bool, sharedInformers informers.SharedInformerFactory) (cloudprovider.Interface, ControllerLoopMode, error) { 34 var cloud cloudprovider.Interface 35 var loopMode ControllerLoopMode 36 var err error 37 38 if utilfeature.DefaultFeatureGate.Enabled(features.DisableCloudProviders) && cloudprovider.IsDeprecatedInternal(cloudProvider) { 39 cloudprovider.DisableWarningForProvider(cloudProvider) 40 return nil, ExternalLoops, fmt.Errorf( 41 "cloud provider %q was specified, but built-in cloud providers are disabled. Please set --cloud-provider=external and migrate to an external cloud provider", 42 cloudProvider) 43 } 44 45 if cloudprovider.IsExternal(cloudProvider) { 46 loopMode = ExternalLoops 47 if externalCloudVolumePlugin == "" { 48 // externalCloudVolumePlugin is temporary until we split all cloud providers out. 49 // So we just tell the caller that we need to run ExternalLoops without any cloud provider. 50 return nil, loopMode, nil 51 } 52 cloud, err = cloudprovider.InitCloudProvider(externalCloudVolumePlugin, cloudConfigFile) 53 } else { 54 cloudprovider.DeprecationWarningForProvider(cloudProvider) 55 56 loopMode = IncludeCloudLoops 57 cloud, err = cloudprovider.InitCloudProvider(cloudProvider, cloudConfigFile) 58 } 59 if err != nil { 60 return nil, loopMode, fmt.Errorf("cloud provider could not be initialized: %v", err) 61 } 62 63 if cloud != nil && !cloud.HasClusterID() { 64 if allowUntaggedCloud { 65 logger.Info("Warning: detected a cluster without a ClusterID. A ClusterID will be required in the future. Please tag your cluster to avoid any future issues") 66 } else { 67 return nil, loopMode, fmt.Errorf("no ClusterID Found. A ClusterID is required for the cloud provider to function properly. This check can be bypassed by setting the allow-untagged-cloud option") 68 } 69 } 70 71 if informerUserCloud, ok := cloud.(cloudprovider.InformerUser); ok { 72 informerUserCloud.SetInformers(sharedInformers) 73 } 74 return cloud, loopMode, err 75 }