Skip to content

Commit ff9e801

Browse files
authored
Merge branch 'main' into fix-loadbalancer-ip
2 parents b5493c9 + 04bf536 commit ff9e801

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

cloudstack.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ type CSConfig struct {
5454
SSLNoVerify bool `gcfg:"ssl-no-verify"`
5555
ProjectID string `gcfg:"project-id"`
5656
Zone string `gcfg:"zone"`
57+
Region string `gcfg:"region"`
5758
}
5859
}
5960

@@ -62,6 +63,7 @@ type CSCloud struct {
6263
client *cloudstack.CloudStackClient
6364
projectID string // If non-"", all resources will be created within this project
6465
zone string
66+
region string
6567
version semver.Version
6668
clientBuilder cloudprovider.ControllerClientBuilder
6769
}
@@ -96,6 +98,7 @@ func newCSCloud(cfg *CSConfig) (*CSCloud, error) {
9698
cs := &CSCloud{
9799
projectID: cfg.Global.ProjectID,
98100
zone: cfg.Global.Zone,
101+
region: cfg.Global.Region,
99102
version: semver.Version{},
100103
}
101104

@@ -231,7 +234,8 @@ func (cs *CSCloud) GetZone(ctx context.Context) (cloudprovider.Zone, error) {
231234

232235
klog.V(2).Infof("Current zone is %v", cs.zone)
233236
zone.FailureDomain = cs.zone
234-
zone.Region = cs.zone
237+
238+
zone.Region = cs.getRegionFromZone(cs.zone)
235239

236240
return zone, nil
237241
}
@@ -253,7 +257,7 @@ func (cs *CSCloud) GetZoneByProviderID(ctx context.Context, providerID string) (
253257

254258
klog.V(2).Infof("Current zone is %v", cs.zone)
255259
zone.FailureDomain = instance.Zonename
256-
zone.Region = instance.Zonename
260+
zone.Region = cs.getRegionFromZone(instance.Zonename)
257261

258262
return zone, nil
259263
}
@@ -275,7 +279,7 @@ func (cs *CSCloud) GetZoneByNodeName(ctx context.Context, nodeName types.NodeNam
275279

276280
klog.V(2).Infof("Current zone is %v", cs.zone)
277281
zone.FailureDomain = instance.Zonename
278-
zone.Region = instance.Zonename
282+
zone.Region = cs.getRegionFromZone(instance.Zonename)
279283

280284
return zone, nil
281285
}
@@ -425,3 +429,10 @@ func (cs *CSCloud) patchServiceAnnotation(ctx context.Context, client kubernetes
425429

426430
return fmt.Errorf("failed to update service annotation after %d attempts", maxRetries)
427431
}
432+
433+
func (cs *CSCloud) getRegionFromZone(zone string) string {
434+
if cs.region != "" {
435+
return cs.region
436+
}
437+
return zone
438+
}

0 commit comments

Comments
 (0)