local-path-provisioner: Custom teardown script doesn't work

I’ve tried to set a custom teardown script using Helm values:

teardown: |-
  #!/bin/sh
  path=$1
  archived_path="$(dirname ${path})/archived-$(basename ${path})"
  mv ${path} ${archived_path}

Although the config map gets updated to the new teardown script, when I delete a pvc local-path-provisioner still deletes the pv folder instead of running the script.

Any help would be appreciated 😃

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 33 (29 by maintainers)

Most upvoted comments

@SamDecrock Thanks for the confirmation. I will cut a release now.

@rxbn I think the master should work but I am planning cut a new release this week to include the customized setup/teardown script.

With v0.0.17 it works perfectly! I guess this issue can be closed now 👍

@rxbn I would recommend to revert back to use v0.0.14 in in the meantime for your case.

With the latest master it works!

@rxbn you need to clone the repo, run make and then use the generated image.

Hi, I also have the same issue. The folder just disappears instead of running the teardown script. When can you release a new version or how do I build the master?

@rxbn hi, i tried to reproduce your problem, but it works well.

my configMap:

kind: ConfigMap
apiVersion: v1
metadata:
  name: local-path-config
  namespace: local-path-storage
data:
  config.json: |-
        {
                "nodePathMap":[
                {
                        "node":"DEFAULT_PATH_FOR_NON_LISTED_NODES",
                        "paths":["/opt/local-path-provisioner"]
                },
                {
                        "node":"yasker-lp-dev1",
                        "paths":["/opt/local-path-provisioner", "/data1"]
                },
                {
                        "node":"yasker-lp-dev3",
                        "paths":[]
                }
                ]
        }
  setup: |-
        #!/bin/sh
        path=$1
        mkdir -m 0777 -p ${path}
  teardown: |-
        #!/bin/sh
        path=$1
        archived_path="$(dirname ${path})/archived-$(basename ${path})"
        mv ${path} ${archived_path}

and did as follows:

ADD

# kubectl apply -f examples/pvc.yaml 
persistentvolumeclaim/local-path-pvc created
# kubectl get pvc
NAME             STATUS    VOLUME             CAPACITY   ACCESS MODES   STORAGECLASS   AGE
local-path-pvc   Pending                                                local-path     7s
# kubectl apply -f examples/pod.yaml 
# kubectl get pvc
NAME             STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
local-path-pvc   Bound    pvc-bfe590db-02f7-4986-8455-789c769a2a20   2Gi        RWO            local-path     61s
# ls -la /opt/local-path-provisioner/
drwxr-xr-x  3 root root  77 Jul  28 11:08 .
drwxr-xr-x. 9 root root 133 Jul  16 16:20 ..
drwxrwxrwx  2 root root   6 Jul  28 11:08 pvc-bfe590db-02f7-4986-8455-789c769a2a20_default_local-path-pvc

DELETE

# kubectl delete -f examples/pod.yaml 
pod "volume-test" deleted
# kubectl delete -f examples/pvc.yaml 
persistentvolumeclaim "local-path-pvc" deleted
# ls -la /opt/local-path-provisioner/
drwxr-xr-x  3 root root  86 Jul  28 11:10 .
drwxr-xr-x. 9 root root 133 Jul  16 16:20 ..
drwxrwxrwx  2 root root   6 Jul  28 11:08 archived-pvc-bfe590db-02f7-4986-8455-789c769a2a20_default_local-path-pvc

so the pvc-bfe590db-02f7-4986-8455-789c769a2a20_default_local-path-pvc was renamed as archived-pvc-bfe590db-02f7-4986-8455-789c769a2a20_default_local-path-pvc , that was what the teardown script did.