This is an automated email from the ASF dual-hosted git repository.

vishesh pushed a commit to branch main
in repository 
https://gitbox.apache.org/repos/asf/cloudstack-kubernetes-provider.git


The following commit(s) were added to refs/heads/main by this push:
     new 04bf5364 Allow custom region from config (#83)
04bf5364 is described below

commit 04bf5364c6c9534ddd71c9975ee97716ce8d1062
Author: Vishesh <[email protected]>
AuthorDate: Fri Dec 12 12:51:18 2025 +0530

    Allow custom region from config (#83)
---
 cloudstack.go | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/cloudstack.go b/cloudstack.go
index 242ff7dc..92c31b96 100644
--- a/cloudstack.go
+++ b/cloudstack.go
@@ -48,6 +48,7 @@ type CSConfig struct {
                SSLNoVerify bool   `gcfg:"ssl-no-verify"`
                ProjectID   string `gcfg:"project-id"`
                Zone        string `gcfg:"zone"`
+               Region      string `gcfg:"region"`
        }
 }
 
@@ -56,6 +57,7 @@ type CSCloud struct {
        client        *cloudstack.CloudStackClient
        projectID     string // If non-"", all resources will be created within 
this project
        zone          string
+       region        string
        version       semver.Version
        clientBuilder cloudprovider.ControllerClientBuilder
 }
@@ -90,6 +92,7 @@ func newCSCloud(cfg *CSConfig) (*CSCloud, error) {
        cs := &CSCloud{
                projectID: cfg.Global.ProjectID,
                zone:      cfg.Global.Zone,
+               region:    cfg.Global.Region,
                version:   semver.Version{},
        }
 
@@ -225,7 +228,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
 }
@@ -247,7 +251,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
 }
@@ -269,7 +273,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
 }
@@ -324,3 +328,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
+}

Reply via email to