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

Commit 7c5429f

Browse files
author
Kubernetes Submit Queue
authored
Merge pull request #53523 from zetaab/ignore_volume_label
Automatic merge from submit-queue. 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>. add possibility to ignore volume label in dynamic provisioning **What this PR does / why we need it**: this is needed if openstack cinder zone name does not match to compute zone names. For instance if there is only one cinder zone and many compute zones. **Which issue this PR fixes**: fixes #53488 **Special notes for your reviewer**: ```release-note NONE ```
2 parents c8860a4 + a93fd48 commit 7c5429f

6 files changed

Lines changed: 19 additions & 12 deletions

File tree

pkg/cloudprovider/providers/openstack/openstack.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ type LoadBalancerOpts struct {
9393
type BlockStorageOpts struct {
9494
BSVersion string `gcfg:"bs-version"` // overrides autodetection. v1 or v2. Defaults to auto
9595
TrustDevicePath bool `gcfg:"trust-device-path"` // See Issue #33128
96+
IgnoreVolumeAZ bool `gcfg:"ignore-volume-az"`
9697
}
9798

9899
type RouterOpts struct {
@@ -187,6 +188,7 @@ func readConfig(config io.Reader) (Config, error) {
187188
// Set default values for config params
188189
cfg.BlockStorage.BSVersion = "auto"
189190
cfg.BlockStorage.TrustDevicePath = false
191+
cfg.BlockStorage.IgnoreVolumeAZ = false
190192
cfg.Metadata.SearchOrder = fmt.Sprintf("%s,%s", configDriveID, metadataID)
191193

192194
err := gcfg.ReadInto(&cfg, config)

pkg/cloudprovider/providers/openstack/openstack_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ func TestReadConfig(t *testing.T) {
100100
[BlockStorage]
101101
bs-version = auto
102102
trust-device-path = yes
103+
ignore-volume-az = yes
103104
[Metadata]
104105
search-order = configDrive, metadataService
105106
`))
@@ -128,6 +129,9 @@ func TestReadConfig(t *testing.T) {
128129
if cfg.BlockStorage.BSVersion != "auto" {
129130
t.Errorf("incorrect bs.bs-version: %v", cfg.BlockStorage.BSVersion)
130131
}
132+
if cfg.BlockStorage.IgnoreVolumeAZ != true {
133+
t.Errorf("incorrect bs.IgnoreVolumeAZ: %v", cfg.BlockStorage.IgnoreVolumeAZ)
134+
}
131135
if cfg.Metadata.SearchOrder != "configDrive, metadataService" {
132136
t.Errorf("incorrect md.search-order: %v", cfg.Metadata.SearchOrder)
133137
}
@@ -531,7 +535,7 @@ func TestVolumes(t *testing.T) {
531535
tags := map[string]string{
532536
"test": "value",
533537
}
534-
vol, _, err := os.CreateVolume("kubernetes-test-volume-"+rand.String(10), 1, "", "", &tags)
538+
vol, _, _, err := os.CreateVolume("kubernetes-test-volume-"+rand.String(10), 1, "", "", &tags)
535539
if err != nil {
536540
t.Fatalf("Cannot create a new Cinder volume: %v", err)
537541
}

pkg/cloudprovider/providers/openstack/openstack_volumes.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -299,11 +299,11 @@ func (os *OpenStack) getVolume(volumeID string) (Volume, error) {
299299
}
300300

301301
// CreateVolume creates a volume of given size (in GiB)
302-
func (os *OpenStack) CreateVolume(name string, size int, vtype, availability string, tags *map[string]string) (string, string, error) {
302+
func (os *OpenStack) CreateVolume(name string, size int, vtype, availability string, tags *map[string]string) (string, string, bool, error) {
303303
volumes, err := os.volumeService("")
304304
if err != nil || volumes == nil {
305305
glog.Errorf("Unable to initialize cinder client for region: %s", os.region)
306-
return "", "", err
306+
return "", "", os.bsOpts.IgnoreVolumeAZ, err
307307
}
308308

309309
opts := VolumeCreateOpts{
@@ -320,11 +320,11 @@ func (os *OpenStack) CreateVolume(name string, size int, vtype, availability str
320320

321321
if err != nil {
322322
glog.Errorf("Failed to create a %d GB volume: %v", size, err)
323-
return "", "", err
323+
return "", "", os.bsOpts.IgnoreVolumeAZ, err
324324
}
325325

326-
glog.Infof("Created volume %v in Availability Zone: %v", volumeID, volumeAZ)
327-
return volumeID, volumeAZ, nil
326+
glog.Infof("Created volume %v in Availability Zone: %v Ignore volume AZ: %v", volumeID, volumeAZ, os.bsOpts.IgnoreVolumeAZ)
327+
return volumeID, volumeAZ, os.bsOpts.IgnoreVolumeAZ, nil
328328
}
329329

330330
// GetDevicePath returns the path of an attached block storage volume, specified by its id.

pkg/volume/cinder/attacher_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,8 +571,8 @@ func (testcase *testcase) ShouldTrustDevicePath() bool {
571571
return true
572572
}
573573

574-
func (testcase *testcase) CreateVolume(name string, size int, vtype, availability string, tags *map[string]string) (string, string, error) {
575-
return "", "", errors.New("Not implemented")
574+
func (testcase *testcase) CreateVolume(name string, size int, vtype, availability string, tags *map[string]string) (string, string, bool, error) {
575+
return "", "", false, errors.New("Not implemented")
576576
}
577577

578578
func (testcase *testcase) GetDevicePath(volumeID string) string {

pkg/volume/cinder/cinder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ type CinderProvider interface {
4646
AttachDisk(instanceID, volumeID string) (string, error)
4747
DetachDisk(instanceID, volumeID string) error
4848
DeleteVolume(volumeID string) error
49-
CreateVolume(name string, size int, vtype, availability string, tags *map[string]string) (string, string, error)
49+
CreateVolume(name string, size int, vtype, availability string, tags *map[string]string) (string, string, bool, error)
5050
GetDevicePath(volumeID string) string
5151
InstanceID() (string, error)
5252
GetAttachmentDiskPath(instanceID, volumeID string) (string, error)

pkg/volume/cinder/cinder_util.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ func (util *CinderDiskUtil) CreateVolume(c *cinderVolumeProvisioner) (volumeID s
204204
}
205205
}
206206

207-
volumeID, volumeAZ, errr := cloud.CreateVolume(name, volSizeGB, vtype, availability, c.options.CloudTags)
207+
volumeID, volumeAZ, IgnoreVolumeAZ, errr := cloud.CreateVolume(name, volSizeGB, vtype, availability, c.options.CloudTags)
208208
if errr != nil {
209209
glog.V(2).Infof("Error creating cinder volume: %v", errr)
210210
return "", 0, nil, "", errr
@@ -213,8 +213,9 @@ func (util *CinderDiskUtil) CreateVolume(c *cinderVolumeProvisioner) (volumeID s
213213

214214
// these are needed that pod is spawning to same AZ
215215
volumeLabels = make(map[string]string)
216-
volumeLabels[kubeletapis.LabelZoneFailureDomain] = volumeAZ
217-
216+
if IgnoreVolumeAZ == false {
217+
volumeLabels[kubeletapis.LabelZoneFailureDomain] = volumeAZ
218+
}
218219
return volumeID, volSizeGB, volumeLabels, fstype, nil
219220
}
220221

0 commit comments

Comments
 (0)