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

Support Zone-Aware Topologies in the KubeVirt CSI Driver #124

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
11 changes: 9 additions & 2 deletions cmd/kubevirt-csi-driver/kubevirt-csi-driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,20 @@ func handle() {
klog.Fatal(err)
}

var nodeID string
var (
nodeID string
allowedTopologies = map[string]string{}
)

if *nodeName != "" {
node, err := tenantClientSet.CoreV1().Nodes().Get(context.TODO(), *nodeName, v1.GetOptions{})
if err != nil {
klog.Fatal(fmt.Errorf("failed to find node by name %v: %v", nodeName, err))
}
// systemUUID is the VM ID
nodeID = node.Status.NodeInfo.SystemUUID
allowedTopologies[service.WellKnownZoneTopologyKey] = node.Labels[service.WellKnownZoneTopologyKey]
allowedTopologies[service.WellKnownRegionTopologyKey] = node.Labels[service.WellKnownRegionTopologyKey]
klog.Infof("Node name: %v, Node ID: %s", nodeName, nodeID)
}

Expand All @@ -131,7 +137,8 @@ func handle() {
storageClassEnforcement,
nodeID,
*runNodeService,
*runControllerService)
*runControllerService,
allowedTopologies)

driver.Run(*endpoint)
}
Expand Down
1 change: 1 addition & 0 deletions deploy/controller-infra/base/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ spec:
- "--v=5"
- "--timeout=3m"
- "--retry-interval-max=1m"
- "--feature-gates=Topology=true"
env:
- name: ADDRESS
value: /var/lib/csi/sockets/pluginproxy/csi.sock
Expand Down
1 change: 1 addition & 0 deletions deploy/controller-tenant/base/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ spec:
- "--v=5"
- "--timeout=3m"
- "--retry-interval-max=1m"
- "--feature-gates=Topology=true"
env:
- name: ADDRESS
value: /var/lib/csi/sockets/pluginproxy/csi.sock
Expand Down
65 changes: 62 additions & 3 deletions pkg/service/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,12 @@ func (c *ControllerService) CreateVolume(ctx context.Context, req *csi.CreateVol
// Prepare serial for disk
serial := string(dv.GetUID())

// Return response
return &csi.CreateVolumeResponse{
zone, region, err := c.getAllowedZoneAndRegion(ctx, req.AccessibilityRequirements)
if err != nil {
return nil, err
}

cvr := &csi.CreateVolumeResponse{
Volume: &csi.Volume{
CapacityBytes: storageSize,
VolumeId: dvName,
Expand All @@ -229,7 +233,27 @@ func (c *ControllerService) CreateVolume(ctx context.Context, req *csi.CreateVol
},
ContentSource: req.GetVolumeContentSource(),
},
}, nil
}

var allowedTopologies = map[string]string{}
if zone != "" {
allowedTopologies[WellKnownZoneTopologyKey] = zone
}

if region != "" {
allowedTopologies[WellKnownRegionTopologyKey] = region
}

if len(allowedTopologies) > 0 {
cvr.Volume.AccessibleTopology = []*csi.Topology{
{
Segments: allowedTopologies,
},
}
}

// Return response
return cvr, nil
}

func (c *ControllerService) determineDvSource(ctx context.Context, req *csi.CreateVolumeRequest) (*cdiv1.DataVolumeSource, error) {
Expand Down Expand Up @@ -768,3 +792,38 @@ func (c *ControllerService) getVMNameByCSINodeID(ctx context.Context, nodeID str

return "", status.Error(codes.NotFound, fmt.Sprintf("failed to find VM with domain.firmware.uuid %v", nodeID))
}

func (c *ControllerService) getAllowedZoneAndRegion(_ context.Context, requirement *csi.TopologyRequirement) (string, string, error) {
var zone, region string

if requirement == nil {
return "", "", nil
}

for _, topology := range requirement.GetPreferred() {
preferredZone, exists := topology.GetSegments()[WellKnownZoneTopologyKey]
if exists {
zone = preferredZone
}

preferredRegion, exists := topology.GetSegments()[WellKnownRegionTopologyKey]
if exists {
region = preferredRegion
}
}

for _, topology := range requirement.GetRequisite() {
requisiteZone, exists := topology.GetSegments()[WellKnownZoneTopologyKey]
if exists {
zone = requisiteZone
}

requisiteRegion, exists := topology.GetSegments()[WellKnownRegionTopologyKey]
if exists {
region = requisiteRegion
}
}

return zone, region, nil

}
10 changes: 8 additions & 2 deletions pkg/service/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import (
"kubevirt.io/csi-driver/pkg/util"
)

const (
WellKnownRegionTopologyKey = "topology.kubernetes.io/region"
WellKnownZoneTopologyKey = "topology.kubernetes.io/zone"
)

var (
// VendorVersion is the vendor version set by ldflags at build time
VendorVersion = "0.2.0"
Expand All @@ -30,7 +35,8 @@ func NewKubevirtCSIDriver(virtClient kubevirt.Client,
storageClassEnforcement util.StorageClassEnforcement,
nodeID string,
runNodeService bool,
runControllerService bool) *KubevirtCSIDriver {
runControllerService bool,
allowedTopologies map[string]string) *KubevirtCSIDriver {
d := KubevirtCSIDriver{
IdentityService: NewIdentityService(identityClientset),
}
Expand All @@ -45,7 +51,7 @@ func NewKubevirtCSIDriver(virtClient kubevirt.Client,
}

if runNodeService {
d.NodeService = NewNodeService(nodeID)
d.NodeService = NewNodeService(nodeID, allowedTopologies)
}

return &d
Expand Down
7 changes: 7 additions & 0 deletions pkg/service/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ func (i *IdentityService) GetPluginCapabilities(context.Context, *csi.GetPluginC
},
},
},
{
Type: &csi.PluginCapability_Service_{
Service: &csi.PluginCapability_Service{
Type: csi.PluginCapability_Service_VOLUME_ACCESSIBILITY_CONSTRAINTS,
},
},
},
},
}, nil
}
Expand Down
27 changes: 16 additions & 11 deletions pkg/service/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ var nodeCaps = []csi.NodeServiceCapability_RPC_Type{
// NodeService implements the CSI Driver node service
type NodeService struct {
csi.UnimplementedNodeServer
nodeID string
deviceLister DeviceLister
fsMaker FsMaker
mounter mount.Interface
dirMaker dirMaker
nodeID string
deviceLister DeviceLister
fsMaker FsMaker
mounter mount.Interface
dirMaker dirMaker
allowedTopologies map[string]string
}

type DeviceLister interface{ List() ([]byte, error) }
Expand Down Expand Up @@ -59,12 +60,13 @@ var NewFsMaker = func() FsMaker {
})
}

func NewNodeService(nodeId string) *NodeService {
func NewNodeService(nodeId string, allowedTopologies map[string]string) *NodeService {
return &NodeService{
nodeID: nodeId,
deviceLister: NewDeviceLister(),
fsMaker: NewFsMaker(),
mounter: NewMounter(),
nodeID: nodeId,
deviceLister: NewDeviceLister(),
fsMaker: NewFsMaker(),
mounter: NewMounter(),
allowedTopologies: allowedTopologies,
dirMaker: dirMakerFunc(func(path string, perm os.FileMode) error {
// MkdirAll returns nil if path already exists
return os.MkdirAll(path, perm)
Expand Down Expand Up @@ -334,7 +336,10 @@ func (n *NodeService) NodeExpandVolume(context.Context, *csi.NodeExpandVolumeReq
// NodeGetInfo returns the node ID
func (n *NodeService) NodeGetInfo(context.Context, *csi.NodeGetInfoRequest) (*csi.NodeGetInfoResponse, error) {
// the nodeID is the VM's ID in kubevirt or VMI.spec.domain.firmware.uuid
return &csi.NodeGetInfoResponse{NodeId: n.nodeID}, nil

return &csi.NodeGetInfoResponse{
NodeId: n.nodeID,
AccessibleTopology: &csi.Topology{Segments: n.allowedTopologies}}, nil
}

// NodeGetCapabilities returns the supported capabilities of the node service
Expand Down