Skip to content

Commit ccec72b

Browse files
committed
feat(occm): support multi region cluster
Currently, it supports only single auth section. Set the regions in config as: [Global] region=REGION1 regions=REGION1 regions=REGION2 regions=REGION3
1 parent bbb82f4 commit ccec72b

File tree

6 files changed

+164
-59
lines changed

6 files changed

+164
-59
lines changed

docs/openstack-cloud-controller-manager/using-openstack-cloud-controller-manager.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ The options in `Global` section are used for openstack-cloud-controller-manager
114114
Keystone user password. If you are using [Keystone application credential](https://docs.openstack.org/keystone/latest/user/application_credentials.html), this option is not required.
115115
* `region`
116116
Required. Keystone region name.
117+
* `regions`
118+
Optional. Keystone region name, which is used to specify regions for the cloud provider where the instance is running. Region is default region name. Can be specified multiple times.
117119
* `domain-id`
118120
Keystone user domain ID. If you are using [Keystone application credential](https://docs.openstack.org/keystone/latest/user/application_credentials.html), this option is not required.
119121
* `domain-name`
@@ -317,7 +319,7 @@ Although the openstack-cloud-controller-manager was initially implemented with N
317319
call](https://docs.openstack.org/api-ref/load-balancer/v2/?expanded=create-a-load-balancer-detail#creating-a-fully-populated-load-balancer).
318320
Setting this option to true will create loadbalancers using serial API calls which first create an unpopulated
319321
loadbalancer, then populate its listeners, pools and members. This is a compatibility option at the expense of
320-
increased load on the OpenStack API. Default: false
322+
increased load on the OpenStack API. Default: false
321323
322324
NOTE:
323325

pkg/client/client.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ type AuthOpts struct {
5353
UserDomainID string `gcfg:"user-domain-id" mapstructure:"user-domain-id" name:"os-userDomainID" value:"optional"`
5454
UserDomainName string `gcfg:"user-domain-name" mapstructure:"user-domain-name" name:"os-userDomainName" value:"optional"`
5555
Region string `name:"os-region"`
56+
Regions []string `name:"os-regions" value:"optional"`
5657
EndpointType gophercloud.Availability `gcfg:"os-endpoint-type" mapstructure:"os-endpoint-type" name:"os-endpointType" value:"optional"`
5758
CAFile string `gcfg:"ca-file" mapstructure:"ca-file" name:"os-certAuthorityPath" value:"optional"`
5859
TLSInsecure string `gcfg:"tls-insecure" mapstructure:"tls-insecure" name:"os-TLSInsecure" value:"optional" matches:"^true|false$"`
@@ -87,6 +88,7 @@ func LogCfg(authOpts AuthOpts) {
8788
klog.V(5).Infof("UserDomainID: %s", authOpts.UserDomainID)
8889
klog.V(5).Infof("UserDomainName: %s", authOpts.UserDomainName)
8990
klog.V(5).Infof("Region: %s", authOpts.Region)
91+
klog.V(5).Infof("Regions: %s", authOpts.Regions)
9092
klog.V(5).Infof("EndpointType: %s", authOpts.EndpointType)
9193
klog.V(5).Infof("CAFile: %s", authOpts.CAFile)
9294
klog.V(5).Infof("CertFile: %s", authOpts.CertFile)
@@ -232,6 +234,20 @@ func ReadClouds(authOpts *AuthOpts) error {
232234
authOpts.ApplicationCredentialName = replaceEmpty(authOpts.ApplicationCredentialName, cloud.AuthInfo.ApplicationCredentialName)
233235
authOpts.ApplicationCredentialSecret = replaceEmpty(authOpts.ApplicationCredentialSecret, cloud.AuthInfo.ApplicationCredentialSecret)
234236

237+
regions := strings.Split(authOpts.Region, ",")
238+
if len(regions) > 1 {
239+
authOpts.Region = regions[0]
240+
}
241+
242+
for _, r := range cloud.Regions {
243+
// Support only single auth section in clouds.yaml
244+
if r.Values.AuthInfo == nil && r.Name != authOpts.Region {
245+
regions = append(regions, r.Name)
246+
}
247+
}
248+
249+
authOpts.Regions = regions
250+
235251
return nil
236252
}
237253

pkg/csi/cinder/openstack/openstack.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func GetConfigFromFiles(configFilePaths []string) (Config, error) {
126126
}
127127
}
128128

129-
for _, global := range cfg.Global {
129+
for idx, global := range cfg.Global {
130130
// Update the config with data from clouds.yaml if UseClouds is enabled
131131
if global.UseClouds {
132132
if global.CloudsFile != "" {
@@ -138,6 +138,10 @@ func GetConfigFromFiles(configFilePaths []string) (Config, error) {
138138
}
139139
klog.V(5).Infof("Credentials are loaded from %s:", global.CloudsFile)
140140
}
141+
142+
if len(global.Regions) == 0 {
143+
cfg.Global[idx].Regions = []string{global.Region}
144+
}
141145
}
142146

143147
return cfg, nil

pkg/csi/cinder/openstack/openstack_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ rescan-on-resize=true`
112112
CAFile: fakeCAfile,
113113
TenantID: fakeTenantID,
114114
Region: fakeRegion,
115+
Regions: []string{fakeRegion},
115116
}
116117
expectedOpts.Global["cloud2"] = &client.AuthOpts{
117118
Username: fakeUserName_cloud2,
@@ -121,6 +122,7 @@ rescan-on-resize=true`
121122
CAFile: fakeCAfile_cloud2,
122123
TenantID: fakeTenantID_cloud2,
123124
Region: fakeRegion_cloud2,
125+
Regions: []string{fakeRegion_cloud2},
124126
}
125127
expectedOpts.Global["cloud3"] = &client.AuthOpts{
126128
Username: fakeUserName_cloud3,
@@ -130,6 +132,7 @@ rescan-on-resize=true`
130132
CAFile: fakeCAfile_cloud3,
131133
TenantID: fakeTenantID_cloud3,
132134
Region: fakeRegion_cloud3,
135+
Regions: []string{fakeRegion_cloud3},
133136
}
134137

135138
expectedOpts.BlockStorage.RescanOnResize = true
@@ -224,6 +227,7 @@ rescan-on-resize=true`
224227
CAFile: fakeCAfile,
225228
TenantID: fakeTenantID,
226229
Region: fakeRegion,
230+
Regions: []string{fakeRegion},
227231
EndpointType: gophercloud.AvailabilityPublic,
228232
UseClouds: true,
229233
CloudsFile: wd + "/fixtures/clouds.yaml",
@@ -237,6 +241,7 @@ rescan-on-resize=true`
237241
CAFile: fakeCAfile_cloud2,
238242
TenantID: fakeTenantID_cloud2,
239243
Region: fakeRegion_cloud2,
244+
Regions: []string{fakeRegion_cloud2},
240245
EndpointType: gophercloud.AvailabilityPublic,
241246
UseClouds: true,
242247
CloudsFile: wd + "/fixtures/clouds.yaml",
@@ -250,6 +255,7 @@ rescan-on-resize=true`
250255
CAFile: fakeCAfile_cloud3,
251256
TenantID: fakeTenantID_cloud3,
252257
Region: fakeRegion_cloud3,
258+
Regions: []string{fakeRegion_cloud3},
253259
EndpointType: gophercloud.AvailabilityPublic,
254260
UseClouds: true,
255261
CloudsFile: wd + "/fixtures/clouds.yaml",

0 commit comments

Comments
 (0)