From ec6a0f9a45e4e3a304820236b0cc0be3416cc6a6 Mon Sep 17 00:00:00 2001
From: Kasakaze
Date: Wed, 29 Nov 2023 12:56:17 +0800
Subject: [PATCH] feat: support unclear stale pvc (#167)
* feat: support unclear stale pvc
Signed-off-by: Kasakaze
* make test
Signed-off-by: Kasakaze
* update: change CLEANUP_STALE_PVC_ENABLE to GARBAGE_COLLECTION_ENABLED
Signed-off-by: Kasakaze
* update: add env comments to kubectl deploy
Signed-off-by: Kasakaze
---------
Signed-off-by: Kasakaze
---
deploy/kubectl/openebs-nfs-provisioner.yaml | 4 ++++
provisioner/env.go | 6 ++++++
provisioner/provisioner.go | 14 ++++++++++++--
3 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/deploy/kubectl/openebs-nfs-provisioner.yaml b/deploy/kubectl/openebs-nfs-provisioner.yaml
index 485c232c..6f88a522 100644
--- a/deploy/kubectl/openebs-nfs-provisioner.yaml
+++ b/deploy/kubectl/openebs-nfs-provisioner.yaml
@@ -112,6 +112,10 @@ spec:
# value: "kubernetes.io/storage-node,kubernetes.io/nfs-node"
# - name: OPENEBS_IO_NFS_SERVER_NODE_AFFINITY
# value: "kubernetes.io/storage-node,kubernetes.io/nfs-node"
+ # Provide a switch to turn off the function of clearing stale pvc to avoid
+ #. garbage collecting an NFS backend PVC if the NFS PVC is deleted.
+ # - name: OPENEBS_IO_NFS_SERVER_GARBAGE_COLLECTION_ENABLED
+ #. value: false
- name: NODE_NAME
valueFrom:
fieldRef:
diff --git a/provisioner/env.go b/provisioner/env.go
index 9fcf767d..8ca932ac 100644
--- a/provisioner/env.go
+++ b/provisioner/env.go
@@ -58,6 +58,9 @@ const (
// NFSBackendPvcTimeout defines env name to store BackendPvcBoundTimeout value
NFSBackendPvcTimeout menv.ENVKey = "OPENEBS_IO_NFS_SERVER_BACKEND_PVC_TIMEOUT"
+ // The NFSGarbageCollectionEnable environment variable is the switch for the garbage collector.(default true)
+ NFSGarbageCollectionEnable menv.ENVKey = "OPENEBS_IO_NFS_SERVER_GARBAGE_COLLECTION_ENABLED"
+
// NFSServerImagePullSecret defines the env name to store the name of the image pull secret
NFSServerImagePullSecret menv.ENVKey = "OPENEBS_IO_NFS_SERVER_IMAGE_PULL_SECRET"
)
@@ -105,6 +108,9 @@ func getBackendPvcTimeout() string {
return menv.Get(NFSBackendPvcTimeout)
}
+func getNfsGarbageCollectionEnable() string {
+ return menv.GetOrDefault(NFSGarbageCollectionEnable, "true")
+}
func getNfsServerImagePullSecret() string {
return menv.GetOrDefault(NFSServerImagePullSecret, "")
}
diff --git a/provisioner/provisioner.go b/provisioner/provisioner.go
index a93b9665..f3884be4 100644
--- a/provisioner/provisioner.go
+++ b/provisioner/provisioner.go
@@ -117,8 +117,18 @@ func NewProvisioner(ctx context.Context, kubeClient *clientset.Clientset) (*Prov
// and maintain it in cache
go k8sNodeInformer.Run(ctx.Done())
- // Running garbage collector to perform cleanup for stale NFS resources
- go RunGarbageCollector(ctx, kubeClient, pvTracker, nfsServerNs)
+ gcStr := getNfsGarbageCollectionEnable()
+ gcEnable, err := strconv.ParseBool(gcStr)
+ if err != nil {
+ klog.Warningf("Invalid %s value=%s, using default value=true", NFSGarbageCollectionEnable, gcStr)
+ gcEnable = true
+ }
+ if gcEnable {
+ // Running garbage collector to perform cleanup for stale NFS resources
+ go RunGarbageCollector(ctx, kubeClient, pvTracker, nfsServerNs)
+ } else {
+ klog.Warning("Garbage collector is disabled")
+ }
return p, nil
}