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

delete nfs config for stale subvolume #302

Merged
merged 1 commit into from
Jun 24, 2024
Merged
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
67 changes: 67 additions & 0 deletions pkg/filesystem/subvolume.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,21 @@ func deleteOmapForSubvolume(ctx context.Context, clientsets *k8sutil.Clientsets,
if err != nil || poolName == "" {
logging.Fatal(fmt.Errorf("pool name not found: %q", err))
}
nfsClusterName := getNfsClusterName(ctx, clientsets, OperatorNamespace, CephClusterNamespace, subVol, fs)
if nfsClusterName != "" {
exportPath := getNfsExportPath(ctx, clientsets, OperatorNamespace, CephClusterNamespace, nfsClusterName)
if exportPath == "" {
logging.Info("export path not found for subvol %q: %q", subVol, nfsClusterName)
} else {
cmd := "ceph"
args := []string{"nfs", "export", "delete", nfsClusterName, exportPath}
_, err := runCommand(ctx, clientsets, OperatorNamespace, CephClusterNamespace, cmd, args)
if err != nil {
logging.Fatal(err, "failed to delete export for subvol %q: %q %q", subVol, nfsClusterName, exportPath)
}
logging.Info("nfs export: %q %q deleted", nfsClusterName, exportPath)
}
}
if omapval != "" {
cmd := "rados"
args := []string{"rm", omapval, "-p", poolName, "--namespace", "csi"}
Expand Down Expand Up @@ -392,6 +407,58 @@ func getOmapKey(ctx context.Context, clientsets *k8sutil.Clientsets, OperatorNam
return omapkey
}

// getNfsClusterName returns the cluster name from the omap.
// csi.nfs.cluster
// value (26 bytes) :
// 00000000 6f 63 73 2d 73 74 6f 72 61 67 65 63 6c 75 73 74 |my-cluster-cephn|
// 00000010 65 72 2d 63 65 70 68 6e 66 73 |fs|
// 0000001a
func getNfsClusterName(ctx context.Context, clientsets *k8sutil.Clientsets, OperatorNamespace, CephClusterNamespace, subVol, fs string) string {

poolName, err := getMetadataPoolName(ctx, clientsets, OperatorNamespace, CephClusterNamespace, fs)
if err != nil || poolName == "" {
logging.Fatal(fmt.Errorf("pool name not found %q: %q", poolName, err))
}
omapval := getOmapVal(subVol)

args := []string{"getomapval", omapval, "csi.nfs.cluster", "-p", poolName, "--namespace", "csi", "/dev/stdout"}
cmd := "rados"
nfscluster, err := runCommand(ctx, clientsets, OperatorNamespace, CephClusterNamespace, cmd, args)
if err != nil || nfscluster == "" {
logging.Info("nfs cluster not found for subvolume %s: %s %s", subVol, poolName, err)
return ""
}

return nfscluster
}

func getNfsExportPath(ctx context.Context, clientsets *k8sutil.Clientsets, OperatorNamespace, CephClusterNamespace, clusterName string) string {

args := []string{"nfs", "export", "ls", clusterName}
cmd := "ceph"
exportList, err := runCommand(ctx, clientsets, OperatorNamespace, CephClusterNamespace, cmd, args)
if err != nil || exportList == "" {
logging.Info("No export path found for cluster %s: %s", clusterName, err)
return ""
}

var unmarshalexportpath []string
var exportPath string

err = json.Unmarshal([]byte(exportList), &unmarshalexportpath)
if err != nil {
logging.Info("failed to unmarshal export list: %q", err)
return ""
}

// Extract the value from the unmarshalexportpath
if len(unmarshalexportpath) > 0 {
exportPath = unmarshalexportpath[0]
}

return exportPath
}

// func getOmapVal is used to get the omapval from the given subvolume
// omapval is of format csi.volume.427774b4-340b-11ed-8d66-0242ac110005
// which is similar to volume name csi-vol-427774b4-340b-11ed-8d66-0242ac110005
Expand Down
Loading