From 22fafab14cef0068ff6fa410fac6c6660c063352 Mon Sep 17 00:00:00 2001 From: Aleksey Sulimenko Date: Fri, 11 Oct 2024 11:43:11 +0300 Subject: [PATCH] add support hybrid cluster (#25) Signed-off-by: Alexey Sulimenko --- driver/controller.go | 23 ++++++++++------------- driver/driver.go | 15 ++++++++++----- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/driver/controller.go b/driver/controller.go index 495e797..b65c5bf 100644 --- a/driver/controller.go +++ b/driver/controller.go @@ -69,11 +69,9 @@ const ( zoneTopologyKey = "failure-domain.beta.kubernetes.io/zone" ) -var ( - supportedAccessMode = &csi.VolumeCapability_AccessMode{ - Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, - } -) +var supportedAccessMode = &csi.VolumeCapability_AccessMode{ + Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, +} // CreateVolume creates a new volume from the given request. The function is // idempotent. @@ -102,14 +100,13 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) return nil, status.Errorf(codes.OutOfRange, "invalid capacity range: %v", err) } - var zone = d.zone + zone := d.zone + region := d.region if req.AccessibilityRequirements != nil { for _, t := range req.AccessibilityRequirements.Requisite { - region, ok := t.Segments[regionTopologyKey] + regionStr, ok := t.Segments[regionTopologyKey] if ok { - if region != d.region { - return nil, status.Errorf(codes.ResourceExhausted, "volume can be only created in region: %q, got: %q", d.region, region) - } + region = regionStr } zoneStr, ok := t.Segments[zoneTopologyKey] @@ -126,7 +123,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) "storage_size_gibibytes": size / giB, "method": "create_volume", "volume_capabilities": req.VolumeCapabilities, - "region": d.region, + "region": region, "zone": zone, }) log.Info("create volume called") @@ -160,7 +157,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) AccessibleTopology: []*csi.Topology{ { Segments: map[string]string{ - regionTopologyKey: d.region, + regionTopologyKey: region, zoneTopologyKey: vol.ZoneId, }, }, @@ -197,7 +194,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) AccessibleTopology: []*csi.Topology{ { Segments: map[string]string{ - regionTopologyKey: d.region, + regionTopologyKey: region, zoneTopologyKey: zone, }, }, diff --git a/driver/driver.go b/driver/driver.go index 28b265a..464f110 100644 --- a/driver/driver.go +++ b/driver/driver.go @@ -135,15 +135,20 @@ func NewDriver(ep, authKeysStr, folderID, driverName, address, clusterUUID strin return nil, err } + region := "" + zone := "" + instanceID := "" + instanceIdentity, err := ychelpers.GetInstanceIdentity() if err != nil { - return nil, err + // ignore error if we can't get instance identity + logrus.Warningf("failed to get instance identity: %v", err) + } else { + region = instanceIdentity.Region + zone = instanceIdentity.AvailabilityZone + instanceID = instanceIdentity.InstanceID } - region := instanceIdentity.Region - zone := instanceIdentity.AvailabilityZone - instanceID := instanceIdentity.InstanceID - if version == "" { version = "dev" }