Skip to content
This repository was archived by the owner on Mar 22, 2018. It is now read-only.

Commit 8c295d2

Browse files
author
Kubernetes Submit Queue
authored
Merge pull request #58549 from dims/backup-default-location-for-cloud-config
Automatic merge from submit-queue (batch tested with PRs 58480, 58549). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Use backup location to load cloud config for OpenStack **What this PR does / why we need it**: Since we are transitioning to external cloud provider, we need a way to use the existing cinder volume plugin (from kubelet). With external cloud manager kubelet will be run with --cloud=provider=external and no --cloud-config file will be in the command line. So we need a way to load the openstack config file from somewhere. Taking a cue from kubeadm, which currently is picking up "/etc/kubernetes/cloud-config" https://github.com/kubernetes/kubernetes/blob/master/cmd/kubeadm/app/phases/controlplane/manifests.go#L44 let's support the scenario where we fall back to this static location if there is no cloud provider specified in the command line. This has been tested with local-up-cluster using the following params: EXTERNAL_CLOUD_PROVIDER=true CLOUD_PROVIDER=openstack CLOUD_CONFIG=/etc/kubernetes/cloud-config **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes # **Special notes for your reviewer**: **Release note**: ```release-note NONE ```
2 parents 4321fef + d376b58 commit 8c295d2

2 files changed

Lines changed: 22 additions & 12 deletions

File tree

pkg/volume/cinder/attacher.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const (
5757
)
5858

5959
func (plugin *cinderPlugin) NewAttacher() (volume.Attacher, error) {
60-
cinder, err := getCloudProvider(plugin.host.GetCloudProvider())
60+
cinder, err := plugin.getCloudProvider()
6161
if err != nil {
6262
return nil, err
6363
}
@@ -305,7 +305,7 @@ type cinderDiskDetacher struct {
305305
var _ volume.Detacher = &cinderDiskDetacher{}
306306

307307
func (plugin *cinderPlugin) NewDetacher() (volume.Detacher, error) {
308-
cinder, err := getCloudProvider(plugin.host.GetCloudProvider())
308+
cinder, err := plugin.getCloudProvider()
309309
if err != nil {
310310
return nil, err
311311
}

pkg/volume/cinder/cinder.go

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ import (
3737
"k8s.io/kubernetes/pkg/volume/util/volumehelper"
3838
)
3939

40+
const (
41+
DefaultCloudConfigPath = "/etc/kubernetes/cloud-config"
42+
)
43+
4044
// This is the primary entrypoint for volume plugins.
4145
func ProbeVolumePlugins() []volume.VolumePlugin {
4246
return []volume.VolumePlugin{&cinderPlugin{}}
@@ -188,25 +192,31 @@ func (plugin *cinderPlugin) newProvisionerInternal(options volume.VolumeOptions,
188192
}, nil
189193
}
190194

191-
func getCloudProvider(cloudProvider cloudprovider.Interface) (CinderProvider, error) {
192-
if cloud, ok := cloudProvider.(*openstack.OpenStack); ok && cloud != nil {
193-
return cloud, nil
194-
}
195-
return nil, fmt.Errorf("wrong cloud type")
196-
}
197-
198195
func (plugin *cinderPlugin) getCloudProvider() (CinderProvider, error) {
199196
cloud := plugin.host.GetCloudProvider()
200197
if cloud == nil {
201-
glog.Errorf("Cloud provider not initialized properly")
202-
return nil, errors.New("Cloud provider not initialized properly")
198+
if _, err := os.Stat(DefaultCloudConfigPath); err == nil {
199+
var config *os.File
200+
config, err = os.Open(DefaultCloudConfigPath)
201+
if err != nil {
202+
return nil, errors.New(fmt.Sprintf("unable to load OpenStack configuration from default path : %v", err))
203+
} else {
204+
defer config.Close()
205+
cloud, err = cloudprovider.GetCloudProvider(openstack.ProviderName, config)
206+
if err != nil {
207+
return nil, errors.New(fmt.Sprintf("unable to create OpenStack cloud provider from default path : %v", err))
208+
}
209+
}
210+
} else {
211+
return nil, errors.New(fmt.Sprintf("OpenStack cloud provider was not initialized properly : %v", err))
212+
}
203213
}
204214

205215
switch cloud := cloud.(type) {
206216
case *openstack.OpenStack:
207217
return cloud, nil
208218
default:
209-
return nil, errors.New("Invalid cloud provider: expected OpenStack.")
219+
return nil, errors.New("invalid cloud provider: expected OpenStack")
210220
}
211221
}
212222

0 commit comments

Comments
 (0)