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

Commit a93fd48

Browse files
committed
add possibility to ignore volume label in dynamic provisioning
ignorelabel -> addlabel FIX tests small fix to test fixes according what was asked fix test fix test
1 parent 2ec6023 commit a93fd48

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
@@ -94,6 +94,7 @@ type LoadBalancerOpts struct {
9494
type BlockStorageOpts struct {
9595
BSVersion string `gcfg:"bs-version"` // overrides autodetection. v1 or v2. Defaults to auto
9696
TrustDevicePath bool `gcfg:"trust-device-path"` // See Issue #33128
97+
IgnoreVolumeAZ bool `gcfg:"ignore-volume-az"`
9798
}
9899

99100
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
@@ -101,6 +101,7 @@ func TestReadConfig(t *testing.T) {
101101
[BlockStorage]
102102
bs-version = auto
103103
trust-device-path = yes
104+
ignore-volume-az = yes
104105
[Metadata]
105106
search-order = configDrive, metadataService
106107
`))
@@ -129,6 +130,9 @@ func TestReadConfig(t *testing.T) {
129130
if cfg.BlockStorage.BSVersion != "auto" {
130131
t.Errorf("incorrect bs.bs-version: %v", cfg.BlockStorage.BSVersion)
131132
}
133+
if cfg.BlockStorage.IgnoreVolumeAZ != true {
134+
t.Errorf("incorrect bs.IgnoreVolumeAZ: %v", cfg.BlockStorage.IgnoreVolumeAZ)
135+
}
132136
if cfg.Metadata.SearchOrder != "configDrive, metadataService" {
133137
t.Errorf("incorrect md.search-order: %v", cfg.Metadata.SearchOrder)
134138
}
@@ -514,7 +518,7 @@ func TestVolumes(t *testing.T) {
514518
tags := map[string]string{
515519
"test": "value",
516520
}
517-
vol, _, err := os.CreateVolume("kubernetes-test-volume-"+rand.String(10), 1, "", "", &tags)
521+
vol, _, _, err := os.CreateVolume("kubernetes-test-volume-"+rand.String(10), 1, "", "", &tags)
518522
if err != nil {
519523
t.Fatalf("Cannot create a new Cinder volume: %v", err)
520524
}

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)