Skip to content

Commit

Permalink
feat: support unclear stale pvc (#167)
Browse files Browse the repository at this point in the history
* feat: support unclear stale pvc
Signed-off-by: Kasakaze <[email protected]>

* make test

Signed-off-by: Kasakaze <[email protected]>

* update: change CLEANUP_STALE_PVC_ENABLE to GARBAGE_COLLECTION_ENABLED

Signed-off-by: Kasakaze <[email protected]>

* update: add env comments to kubectl deploy

Signed-off-by: Kasakaze <[email protected]>

---------

Signed-off-by: Kasakaze <[email protected]>
  • Loading branch information
njuptlzf authored Nov 29, 2023
1 parent b35af76 commit ec6a0f9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
4 changes: 4 additions & 0 deletions deploy/kubectl/openebs-nfs-provisioner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions provisioner/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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, "")
}
14 changes: 12 additions & 2 deletions provisioner/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit ec6a0f9

Please sign in to comment.