From c9ba7e31ee87e92a8e68b5f0ecb71d1eca3996aa Mon Sep 17 00:00:00 2001 From: vishesh92 Date: Tue, 25 Nov 2025 14:27:45 +0100 Subject: [PATCH] Allow custom region from config --- cloudstack.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/cloudstack.go b/cloudstack.go index 5ea15071..6f1b145f 100644 --- a/cloudstack.go +++ b/cloudstack.go @@ -46,6 +46,7 @@ type CSConfig struct { SSLNoVerify bool `gcfg:"ssl-no-verify"` ProjectID string `gcfg:"project-id"` Zone string `gcfg:"zone"` + Region string `gcfg:"region"` } } @@ -54,6 +55,7 @@ type CSCloud struct { client *cloudstack.CloudStackClient projectID string // If non-"", all resources will be created within this project zone string + region string clientBuilder cloudprovider.ControllerClientBuilder } @@ -87,6 +89,7 @@ func newCSCloud(cfg *CSConfig) (*CSCloud, error) { cs := &CSCloud{ projectID: cfg.Global.ProjectID, zone: cfg.Global.Zone, + region: cfg.Global.Region, } if cfg.Global.APIURL != "" && cfg.Global.APIKey != "" && cfg.Global.SecretKey != "" { @@ -198,7 +201,8 @@ func (cs *CSCloud) GetZone(ctx context.Context) (cloudprovider.Zone, error) { klog.V(2).Infof("Current zone is %v", cs.zone) zone.FailureDomain = cs.zone - zone.Region = cs.zone + + zone.Region = cs.getRegionFromZone(cs.zone) return zone, nil } @@ -220,7 +224,7 @@ func (cs *CSCloud) GetZoneByProviderID(ctx context.Context, providerID string) ( klog.V(2).Infof("Current zone is %v", cs.zone) zone.FailureDomain = instance.Zonename - zone.Region = instance.Zonename + zone.Region = cs.getRegionFromZone(instance.Zonename) return zone, nil } @@ -242,7 +246,7 @@ func (cs *CSCloud) GetZoneByNodeName(ctx context.Context, nodeName types.NodeNam klog.V(2).Infof("Current zone is %v", cs.zone) zone.FailureDomain = instance.Zonename - zone.Region = instance.Zonename + zone.Region = cs.getRegionFromZone(instance.Zonename) return zone, nil } @@ -297,3 +301,10 @@ func (cs *CSCloud) getNodeNameFromPod(ctx context.Context) (string, error) { klog.V(4).Infof("found node name %s for pod %s/%s", pod.Spec.NodeName, namespace, podName) return pod.Spec.NodeName, nil } + +func (cs *CSCloud) getRegionFromZone(zone string) string { + if cs.region != "" { + return cs.region + } + return zone +}