diff --git a/pkg/cloudprovider/providers/openstack/openstack.go b/pkg/cloudprovider/providers/openstack/openstack.go index f09d200e0c9..7b3259c790e 100644 --- a/pkg/cloudprovider/providers/openstack/openstack.go +++ b/pkg/cloudprovider/providers/openstack/openstack.go @@ -93,6 +93,7 @@ type LoadBalancerOpts struct { type BlockStorageOpts struct { BSVersion string `gcfg:"bs-version"` // overrides autodetection. v1 or v2. Defaults to auto TrustDevicePath bool `gcfg:"trust-device-path"` // See Issue #33128 + IgnoreVolumeAZ bool `gcfg:"ignore-volume-az"` } type RouterOpts struct { @@ -187,6 +188,7 @@ func readConfig(config io.Reader) (Config, error) { // Set default values for config params cfg.BlockStorage.BSVersion = "auto" cfg.BlockStorage.TrustDevicePath = false + cfg.BlockStorage.IgnoreVolumeAZ = false cfg.Metadata.SearchOrder = fmt.Sprintf("%s,%s", configDriveID, metadataID) err := gcfg.ReadInto(&cfg, config) diff --git a/pkg/cloudprovider/providers/openstack/openstack_test.go b/pkg/cloudprovider/providers/openstack/openstack_test.go index 5c6a861b84c..85e23718152 100644 --- a/pkg/cloudprovider/providers/openstack/openstack_test.go +++ b/pkg/cloudprovider/providers/openstack/openstack_test.go @@ -100,6 +100,7 @@ func TestReadConfig(t *testing.T) { [BlockStorage] bs-version = auto trust-device-path = yes + ignore-volume-az = yes [Metadata] search-order = configDrive, metadataService `)) @@ -128,6 +129,9 @@ func TestReadConfig(t *testing.T) { if cfg.BlockStorage.BSVersion != "auto" { t.Errorf("incorrect bs.bs-version: %v", cfg.BlockStorage.BSVersion) } + if cfg.BlockStorage.IgnoreVolumeAZ != true { + t.Errorf("incorrect bs.IgnoreVolumeAZ: %v", cfg.BlockStorage.IgnoreVolumeAZ) + } if cfg.Metadata.SearchOrder != "configDrive, metadataService" { t.Errorf("incorrect md.search-order: %v", cfg.Metadata.SearchOrder) } @@ -531,7 +535,7 @@ func TestVolumes(t *testing.T) { tags := map[string]string{ "test": "value", } - vol, _, err := os.CreateVolume("kubernetes-test-volume-"+rand.String(10), 1, "", "", &tags) + vol, _, _, err := os.CreateVolume("kubernetes-test-volume-"+rand.String(10), 1, "", "", &tags) if err != nil { t.Fatalf("Cannot create a new Cinder volume: %v", err) } diff --git a/pkg/cloudprovider/providers/openstack/openstack_volumes.go b/pkg/cloudprovider/providers/openstack/openstack_volumes.go index d8fb05bca7e..a8b99774499 100644 --- a/pkg/cloudprovider/providers/openstack/openstack_volumes.go +++ b/pkg/cloudprovider/providers/openstack/openstack_volumes.go @@ -299,11 +299,11 @@ func (os *OpenStack) getVolume(volumeID string) (Volume, error) { } // CreateVolume creates a volume of given size (in GiB) -func (os *OpenStack) CreateVolume(name string, size int, vtype, availability string, tags *map[string]string) (string, string, error) { +func (os *OpenStack) CreateVolume(name string, size int, vtype, availability string, tags *map[string]string) (string, string, bool, error) { volumes, err := os.volumeService("") if err != nil || volumes == nil { glog.Errorf("Unable to initialize cinder client for region: %s", os.region) - return "", "", err + return "", "", os.bsOpts.IgnoreVolumeAZ, err } opts := VolumeCreateOpts{ @@ -320,11 +320,11 @@ func (os *OpenStack) CreateVolume(name string, size int, vtype, availability str if err != nil { glog.Errorf("Failed to create a %d GB volume: %v", size, err) - return "", "", err + return "", "", os.bsOpts.IgnoreVolumeAZ, err } - glog.Infof("Created volume %v in Availability Zone: %v", volumeID, volumeAZ) - return volumeID, volumeAZ, nil + glog.Infof("Created volume %v in Availability Zone: %v Ignore volume AZ: %v", volumeID, volumeAZ, os.bsOpts.IgnoreVolumeAZ) + return volumeID, volumeAZ, os.bsOpts.IgnoreVolumeAZ, nil } // GetDevicePath returns the path of an attached block storage volume, specified by its id. diff --git a/pkg/volume/cinder/attacher_test.go b/pkg/volume/cinder/attacher_test.go index d6a4b5b06e6..19a156f4202 100644 --- a/pkg/volume/cinder/attacher_test.go +++ b/pkg/volume/cinder/attacher_test.go @@ -571,8 +571,8 @@ func (testcase *testcase) ShouldTrustDevicePath() bool { return true } -func (testcase *testcase) CreateVolume(name string, size int, vtype, availability string, tags *map[string]string) (string, string, error) { - return "", "", errors.New("Not implemented") +func (testcase *testcase) CreateVolume(name string, size int, vtype, availability string, tags *map[string]string) (string, string, bool, error) { + return "", "", false, errors.New("Not implemented") } func (testcase *testcase) GetDevicePath(volumeID string) string { diff --git a/pkg/volume/cinder/cinder.go b/pkg/volume/cinder/cinder.go index c5cca5c4b13..cef425b2499 100644 --- a/pkg/volume/cinder/cinder.go +++ b/pkg/volume/cinder/cinder.go @@ -46,7 +46,7 @@ type CinderProvider interface { AttachDisk(instanceID, volumeID string) (string, error) DetachDisk(instanceID, volumeID string) error DeleteVolume(volumeID string) error - CreateVolume(name string, size int, vtype, availability string, tags *map[string]string) (string, string, error) + CreateVolume(name string, size int, vtype, availability string, tags *map[string]string) (string, string, bool, error) GetDevicePath(volumeID string) string InstanceID() (string, error) GetAttachmentDiskPath(instanceID, volumeID string) (string, error) diff --git a/pkg/volume/cinder/cinder_util.go b/pkg/volume/cinder/cinder_util.go index 9a4b824fabc..1e0d51d6cb1 100644 --- a/pkg/volume/cinder/cinder_util.go +++ b/pkg/volume/cinder/cinder_util.go @@ -204,7 +204,7 @@ func (util *CinderDiskUtil) CreateVolume(c *cinderVolumeProvisioner) (volumeID s } } - volumeID, volumeAZ, errr := cloud.CreateVolume(name, volSizeGB, vtype, availability, c.options.CloudTags) + volumeID, volumeAZ, IgnoreVolumeAZ, errr := cloud.CreateVolume(name, volSizeGB, vtype, availability, c.options.CloudTags) if errr != nil { glog.V(2).Infof("Error creating cinder volume: %v", errr) return "", 0, nil, "", errr @@ -213,8 +213,9 @@ func (util *CinderDiskUtil) CreateVolume(c *cinderVolumeProvisioner) (volumeID s // these are needed that pod is spawning to same AZ volumeLabels = make(map[string]string) - volumeLabels[kubeletapis.LabelZoneFailureDomain] = volumeAZ - + if IgnoreVolumeAZ == false { + volumeLabels[kubeletapis.LabelZoneFailureDomain] = volumeAZ + } return volumeID, volSizeGB, volumeLabels, fstype, nil }