Skip to content

Commit

Permalink
add support hybrid cluster (#25)
Browse files Browse the repository at this point in the history
Signed-off-by: Alexey Sulimenko <alexey.sulimenko@flant.com>
  • Loading branch information
aleksey-su authored Oct 11, 2024
1 parent 112eaff commit 22fafab
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
23 changes: 10 additions & 13 deletions driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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]
Expand All @@ -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")
Expand Down Expand Up @@ -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,
},
},
Expand Down Expand Up @@ -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,
},
},
Expand Down
15 changes: 10 additions & 5 deletions driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down

0 comments on commit 22fafab

Please # to comment.