Skip to content

Commit

Permalink
fix topology
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugome committed May 27, 2023
1 parent 04fa377 commit 87cada3
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ metadata:
name: storage-libvirt-xfs-retain
provisioner: lu.lxc.csi.libvirt
parameters:
fstype: xfs
csi.storage.k8s.io/fstype: xfs
pool: pool
bus: virtio # virtio/usb/sata/ide
reclaimPolicy: Retain
Expand Down
1 change: 1 addition & 0 deletions charts/libvirt-csi/templates/controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ spec:
image: registry.k8s.io/sig-storage/csi-provisioner:v3.4.0
args:
- "--csi-address=$(ADDRESS)"
- "--feature-gates=Topology=true"
- "--default-fstype=ext4"
- "--v=5"
env:
Expand Down
2 changes: 1 addition & 1 deletion charts/libvirt-csi/templates/node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ rules:
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: csi-libvirt-node-driver-read-node-labels
name: csi-libvirt-node-driver-read-node-labels-role
namespace: kube-system
rules:
- apiGroups: [""]
Expand Down
3 changes: 3 additions & 0 deletions internal/provider/csi/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ func (c *Controller) ControllerGetVolume(ctx context.Context, request *csi.Contr
if err != nil {
return nil, status.Error(codes.NotFound, fmt.Sprintf("unable to get libvirt instance: %s, %s", zone, err.Error()))
}
if zone != "" {
response.Volume.AccessibleTopology = []*csi.Topology{{Segments: map[string]string{c.Driver.Name + "/zone": zone}}}
}
pool, err := lv.StoragePoolLookupByName(poolName)
if err != nil {
response.Status.VolumeCondition = &csi.VolumeCondition{Abnormal: true, Message: fmt.Sprintf("Pool %s not found or with error (%s)", poolName, err.Error())}
Expand Down
7 changes: 5 additions & 2 deletions internal/provider/csi/controller/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,19 @@ func (c *Controller) CreateVolume(ctx context.Context, request *csi.CreateVolume
if violations := validateCapabilities(request.VolumeCapabilities); len(violations) > 0 {
return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("volume capabilities cannot be satisified: %s", strings.Join(violations, "; ")))
}
toppology := []*csi.Topology{}
zone := ""
if request.AccessibilityRequirements.Preferred != nil {
if request.AccessibilityRequirements != nil && request.AccessibilityRequirements.Preferred != nil {
for _, topology := range request.AccessibilityRequirements.Preferred {
if zoneSegment, ok := topology.Segments[c.Driver.Name+"/zone"]; ok && zoneSegment != "" {
zone = zoneSegment
toppology = request.AccessibilityRequirements.Preferred
}
}
}
poolName := request.Parameters["pool"]
bus := request.Parameters["bus"]
fstype := request.Parameters["fstype"]
fstype := request.Parameters["csi.storage.k8s.io/fstype"]
unlock := c.Driver.DiskLock(poolName, request.Name)
defer unlock()

Expand Down Expand Up @@ -92,6 +94,7 @@ func (c *Controller) CreateVolume(ctx context.Context, request *csi.CreateVolume
c.Driver.Name + "/fstype": fstype,
c.Driver.Name + "/zone": zone,
},
AccessibleTopology: toppology,
},
}, nil
}
Expand Down

0 comments on commit 87cada3

Please sign in to comment.