diff --git a/deploy/kubectl/openebs-nfs-provisioner.yaml b/deploy/kubectl/openebs-nfs-provisioner.yaml index 485c232..6f88a52 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 9fcf767..8ca932a 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 a93b966..f3884be 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 }