Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support hybrid cluster #25

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading