Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nfs-subdir-external-provisioner
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Rancher商店
nfs-subdir-external-provisioner
Commits
125ed5e7
Commit
125ed5e7
authored
Aug 09, 2018
by
Gary Morse
Committed by
kmova
Sep 07, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds archiveOnDelete parameter to nfs-client provisioner
(cherry picked from commit 2b11b498c5497158bc02dd2ac273e2f97157c95e)
parent
b3eb332a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
2 deletions
+44
-2
README.md
README.md
+3
-2
provisioner.go
cmd/nfs-client-provisioner/provisioner.go
+39
-0
class.yaml
deploy/class.yaml
+2
-0
No files found.
README.md
View file @
125ed5e7
...
@@ -6,7 +6,6 @@
...
@@ -6,7 +6,6 @@
`nfs-client`
is an automatic provisioner that used your
*already configured*
NFS server, automatically creating Persistent Volumes.
`nfs-client`
is an automatic provisioner that used your
*already configured*
NFS server, automatically creating Persistent Volumes.
-
Persistent volumes are provisioned as ${namespace}-${pvcName}-${pvName}
-
Persistent volumes are provisioned as ${namespace}-${pvcName}-${pvName}
-
Persistent volumes which are recycled as archieved-${namespace}-${pvcName}-${pvName}
# How to deploy nfs-client to your cluster.
# How to deploy nfs-client to your cluster.
...
@@ -41,6 +40,8 @@ kind: StorageClass
...
@@ -41,6 +40,8 @@ kind: StorageClass
metadata
:
metadata
:
name
:
managed-nfs-storage
name
:
managed-nfs-storage
provisioner
:
fuseim.pri/ifs
# or choose another name, must match deployment's env PROVISIONER_NAME'
provisioner
:
fuseim.pri/ifs
# or choose another name, must match deployment's env PROVISIONER_NAME'
parameters
:
archiveOnDelete
:
"
false"
# When set to "false" your PVs will not be archived by the provisioner upon deletion of the PVC.
```
```
2.
Authorization
2.
Authorization
...
@@ -82,7 +83,7 @@ Now check your NFS Server for the file `SUCCESS`.
...
@@ -82,7 +83,7 @@ Now check your NFS Server for the file `SUCCESS`.
kubectl delete
-f
deploy/test-pod.yaml
-f
deploy/test-claim.yaml
kubectl delete
-f
deploy/test-pod.yaml
-f
deploy/test-claim.yaml
```
```
Now check the folder
renamed to
`archived-???`
.
Now check the folder
has been deleted
.
4.
Deploying your own PersistentVolumeClaim
4.
Deploying your own PersistentVolumeClaim
...
...
cmd/nfs-client-provisioner/provisioner.go
View file @
125ed5e7
...
@@ -22,11 +22,15 @@ import (
...
@@ -22,11 +22,15 @@ import (
"fmt"
"fmt"
"os"
"os"
"path/filepath"
"path/filepath"
"strconv"
"strings"
"strings"
"k8s.io/kubernetes/pkg/apis/core/v1/helper"
"github.com/golang/glog"
"github.com/golang/glog"
"github.com/kubernetes-incubator/external-storage/lib/controller"
"github.com/kubernetes-incubator/external-storage/lib/controller"
"k8s.io/api/core/v1"
"k8s.io/api/core/v1"
storage
"k8s.io/api/storage/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes"
...
@@ -100,9 +104,43 @@ func (p *nfsProvisioner) Delete(volume *v1.PersistentVolume) error {
...
@@ -100,9 +104,43 @@ func (p *nfsProvisioner) Delete(volume *v1.PersistentVolume) error {
glog
.
Warningf
(
"path %s does not exist, deletion skipped"
,
oldPath
)
glog
.
Warningf
(
"path %s does not exist, deletion skipped"
,
oldPath
)
return
nil
return
nil
}
}
// Get the storage class for this volume.
storageClass
,
err
:=
p
.
getClassForVolume
(
volume
)
if
err
!=
nil
{
return
err
}
// Determine if the "archiveOnDelete" parameter exists.
// If it exists and has a falsey value, delete the directory.
// Otherwise, archive it.
archiveOnDelete
,
exists
:=
storageClass
.
Parameters
[
"archiveOnDelete"
]
archiveBool
,
err
:=
strconv
.
ParseBool
(
archiveOnDelete
)
if
err
!=
nil
{
return
err
}
if
exists
&&
!
archiveBool
{
return
os
.
RemoveAll
(
oldPath
)
}
archivePath
:=
filepath
.
Join
(
mountPath
,
"archived-"
+
pvName
)
archivePath
:=
filepath
.
Join
(
mountPath
,
"archived-"
+
pvName
)
glog
.
V
(
4
)
.
Infof
(
"archiving path %s to %s"
,
oldPath
,
archivePath
)
glog
.
V
(
4
)
.
Infof
(
"archiving path %s to %s"
,
oldPath
,
archivePath
)
return
os
.
Rename
(
oldPath
,
archivePath
)
return
os
.
Rename
(
oldPath
,
archivePath
)
}
// getClassForVolume returns StorageClass
func
(
p
*
nfsProvisioner
)
getClassForVolume
(
pv
*
v1
.
PersistentVolume
)
(
*
storage
.
StorageClass
,
error
)
{
if
p
.
client
==
nil
{
return
nil
,
fmt
.
Errorf
(
"Cannot get kube client"
)
}
className
:=
helper
.
GetPersistentVolumeClass
(
pv
)
if
className
==
""
{
return
nil
,
fmt
.
Errorf
(
"Volume has no storage class"
)
}
class
,
err
:=
p
.
client
.
StorageV1
()
.
StorageClasses
()
.
Get
(
className
,
metav1
.
GetOptions
{})
if
err
!=
nil
{
return
nil
,
err
}
return
class
,
nil
}
}
func
main
()
{
func
main
()
{
...
@@ -141,6 +179,7 @@ func main() {
...
@@ -141,6 +179,7 @@ func main() {
}
}
clientNFSProvisioner
:=
&
nfsProvisioner
{
clientNFSProvisioner
:=
&
nfsProvisioner
{
client
:
clientset
,
server
:
server
,
server
:
server
,
path
:
path
,
path
:
path
,
}
}
...
...
deploy/class.yaml
View file @
125ed5e7
...
@@ -3,3 +3,5 @@ kind: StorageClass
...
@@ -3,3 +3,5 @@ kind: StorageClass
metadata
:
metadata
:
name
:
managed-nfs-storage
name
:
managed-nfs-storage
provisioner
:
fuseim.pri/ifs
# or choose another name, must match deployment's env PROVISIONER_NAME'
provisioner
:
fuseim.pri/ifs
# or choose another name, must match deployment's env PROVISIONER_NAME'
parameters
:
archiveOnDelete
:
"
false"
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment