Skip to content

Commit

Permalink
added spport for lvol-id annotation (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
geoffrey1330 authored Jan 15, 2025
1 parent 10036b7 commit 1aa871a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
33 changes: 33 additions & 0 deletions pkg/spdk/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,11 @@ func prepareCreateVolumeReq(ctx context.Context, req *csi.CreateVolumeRequest, s
return nil, err
}

lvolID, err := getLvolIDAnnotation(ctx, pvcName, pvcNamespace)
if err != nil {
return nil, err
}

createVolReq := util.CreateLVolData{
LvolName: req.GetName(),
Size: fmt.Sprintf("%dM", sizeMiB),
Expand All @@ -282,6 +287,7 @@ func prepareCreateVolumeReq(ctx context.Context, req *csi.CreateVolumeRequest, s
CryptoKey1: cryptoKey1,
CryptoKey2: cryptoKey2,
HostID: hostID,
LvolID: lvolID,
PvcName: pvcName,
PvcNamespace: pvcNamespace,
}
Expand Down Expand Up @@ -731,3 +737,30 @@ func getHostIDAnnotation(ctx context.Context, pvcName, pvcNamespace string) (str

return hostID, nil
}

func getLvolIDAnnotation(ctx context.Context, pvcName, pvcNamespace string) (string, error) {
config, err := rest.InClusterConfig()
if err != nil {
klog.Errorf("failed to get in-cluster config: %v", err)
return "", fmt.Errorf("could not get in-cluster config: %w", err)
}

clientset, err := kubernetes.NewForConfig(config)
if err != nil {
klog.Errorf("failed to create clientset: %v", err)
return "", fmt.Errorf("could not create clientset: %w", err)
}

pvc, err := clientset.CoreV1().PersistentVolumeClaims(pvcNamespace).Get(ctx, pvcName, metav1.GetOptions{})
if err != nil {
klog.Errorf("failed to get PVC %s in namespace %s: %v", pvcName, pvcNamespace, err)
return "", fmt.Errorf("could not get PVC %s in namespace %s: %w", pvcName, pvcNamespace, err)
}

lvolID, ok := pvc.ObjectMeta.Annotations["simplybk/lvol-id"]
if !ok {
return "", nil
}

return lvolID, nil
}
1 change: 1 addition & 0 deletions pkg/util/nvmf.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ type CreateLVolData struct {
CryptoKey1 string `json:"crypto_key1"`
CryptoKey2 string `json:"crypto_key2"`
HostID string `json:"host_id"`
LvolID string `json:"uid"`
PvcName string `json:"pvc_name"`
PvcNamespace string `json:"namespace"`
}
Expand Down

0 comments on commit 1aa871a

Please sign in to comment.