Updated README and saved archiveOnDelete
This commit is contained in:
		
							parent
							
								
									a5f4a8b72b
								
							
						
					
					
						commit
						30d9813bdf
					
				
							
								
								
									
										20
									
								
								README.md
								
								
								
								
							
							
						
						
									
										20
									
								
								README.md
								
								
								
								
							|  | @ -107,6 +107,17 @@ spec: | ||||||
| 
 | 
 | ||||||
| You may also want to change the PROVISIONER_NAME above from ``fuseim.pri/ifs`` to something more descriptive like ``nfs-storage``, but if you do remember to also change the PROVISIONER_NAME in the storage class definition below: | You may also want to change the PROVISIONER_NAME above from ``fuseim.pri/ifs`` to something more descriptive like ``nfs-storage``, but if you do remember to also change the PROVISIONER_NAME in the storage class definition below: | ||||||
| 
 | 
 | ||||||
|  | **Step 5: Deploying your storage class** | ||||||
|  | 
 | ||||||
|  | ***Paraments:*** | ||||||
|  | 
 | ||||||
|  | | Name | Description |  Default | | ||||||
|  | |------|-------------|:--------:| | ||||||
|  | | onDelete | If it exists and has a delete value, delete the directory, if it exists and has a retain value, save the directory. | will be archived with name on the share: `archived-+volume.Name` | | ||||||
|  | | archiveOnDelete | If it exists and has a false value, delete the directory. if `onDelete` exists will be ignored. | will be archived with name on the share: `archived-+volume.Name` | | ||||||
|  | | archiveOnDelete | If it exists and has a false value, delete the directory. if `onDelete` exists will be ignored. | will be archived with name on the share: `archived-+volume.Name` | | ||||||
|  | | pathPattern | Specifies a template for creating a directory path via PVC metadata's such as labels, annotations, name or namespace. To specify metadata use `${.PVC.}`: `${PVC.namespace}`|  n/a | | ||||||
|  | 
 | ||||||
| This is `deploy/class.yaml` which defines the NFS-Client's Kubernetes Storage Class: | This is `deploy/class.yaml` which defines the NFS-Client's Kubernetes Storage Class: | ||||||
| 
 | 
 | ||||||
| ```yaml | ```yaml | ||||||
|  | @ -116,11 +127,11 @@ 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: | parameters: | ||||||
|   archiveOnDelete: "false" # When set to "false" your PVs will not be archived |   pathPattern: "${.PVC.namespace}/${.PVC.annotations.nfs.io/storage-path}" # waits for nfs.io/storage-path annotation, if not specified will accept as empty string. | ||||||
|                            # by the provisioner upon deletion of the PVC. |   onDelete: delete    | ||||||
| ``` | ``` | ||||||
| 
 | 
 | ||||||
| **Step 5: Finally, test your environment!** | **Step 6: Finally, test your environment!** | ||||||
| 
 | 
 | ||||||
| Now we'll test your NFS provisioner. | Now we'll test your NFS provisioner. | ||||||
| 
 | 
 | ||||||
|  | @ -138,7 +149,7 @@ kubectl delete -f deploy/test-pod.yaml -f deploy/test-claim.yaml | ||||||
| 
 | 
 | ||||||
| Now check the folder has been deleted. | Now check the folder has been deleted. | ||||||
| 
 | 
 | ||||||
| **Step 6: Deploying your own PersistentVolumeClaims**. To deploy your own PVC, make sure that you have the correct `storage-class` as indicated by your `deploy/class.yaml` file. | **Step 7: Deploying your own PersistentVolumeClaims**. To deploy your own PVC, make sure that you have the correct `storage-class` as indicated by your `deploy/class.yaml` file. | ||||||
| 
 | 
 | ||||||
| For example: | For example: | ||||||
| 
 | 
 | ||||||
|  | @ -149,6 +160,7 @@ metadata: | ||||||
|   name: test-claim |   name: test-claim | ||||||
|   annotations: |   annotations: | ||||||
|     volume.beta.kubernetes.io/storage-class: "managed-nfs-storage" |     volume.beta.kubernetes.io/storage-class: "managed-nfs-storage" | ||||||
|  |     nfs.io/storage-path: "test-path" # not required, depending on whether this annotation was shown in the storage class description | ||||||
| spec: | spec: | ||||||
|   accessModes: |   accessModes: | ||||||
|     - ReadWriteMany |     - ReadWriteMany | ||||||
|  |  | ||||||
|  | @ -23,6 +23,7 @@ import ( | ||||||
| 	"os" | 	"os" | ||||||
| 	"path/filepath" | 	"path/filepath" | ||||||
| 	"regexp" | 	"regexp" | ||||||
|  | 	"strconv" | ||||||
| 	"strings" | 	"strings" | ||||||
| 
 | 
 | ||||||
| 	"github.com/golang/glog" | 	"github.com/golang/glog" | ||||||
|  | @ -52,7 +53,7 @@ type pvcMetadata struct { | ||||||
| 	annotations map[string]string | 	annotations map[string]string | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| var pattern = regexp.MustCompile(`{pvc\.((labels|annotations)\.(.*?)|.*?)}`) | var pattern = regexp.MustCompile(`\${\.PVC\.((labels|annotations)\.(.*?)|.*?)}`) | ||||||
| 
 | 
 | ||||||
| func (meta *pvcMetadata) stringParser(str string) string { | func (meta *pvcMetadata) stringParser(str string) string { | ||||||
| 	result := pattern.FindAllStringSubmatch(str, -1) | 	result := pattern.FindAllStringSubmatch(str, -1) | ||||||
|  | @ -148,9 +149,10 @@ func (p *nfsProvisioner) Delete(volume *v1.PersistentVolume) error { | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| 	// Determine if the "archiveOnDelete" parameter exists.
 | 
 | ||||||
| 	// If it exists and has a false value, delete the directory.
 | 	// Determine if the "onDelete" parameter exists.
 | ||||||
| 	// Otherwise, archive it.
 | 	// If it exists and has a delete value, delete the directory.
 | ||||||
|  | 	// If it exists and has a retain value, safe the directory.
 | ||||||
| 	onDelete := storageClass.Parameters["onDelete"] | 	onDelete := storageClass.Parameters["onDelete"] | ||||||
| 	switch onDelete { | 	switch onDelete { | ||||||
| 
 | 
 | ||||||
|  | @ -159,12 +161,27 @@ func (p *nfsProvisioner) Delete(volume *v1.PersistentVolume) error { | ||||||
| 
 | 
 | ||||||
| 	case "retain": | 	case "retain": | ||||||
| 		return nil | 		return nil | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	// Determine if the "archiveOnDelete" parameter exists.
 | ||||||
|  | 	// If it exists and has a false value, delete the directory.
 | ||||||
|  | 	// Otherwise, archive it.
 | ||||||
|  | 	archiveOnDelete, exists := storageClass.Parameters["archiveOnDelete"] | ||||||
|  | 	if exists { | ||||||
|  | 		if exists { | ||||||
|  | 			archiveBool, err := strconv.ParseBool(archiveOnDelete) | ||||||
|  | 			if err != nil { | ||||||
|  | 				return err | ||||||
|  | 			} | ||||||
|  | 			if !archiveBool { | ||||||
|  | 				return os.RemoveAll(oldPath) | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
| 
 | 
 | ||||||
| 	default: |  | ||||||
| 	archivePath := filepath.Join(mountPath, "archived-"+volume.Name) | 	archivePath := filepath.Join(mountPath, "archived-"+volume.Name) | ||||||
| 	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
 | // getClassForVolume returns StorageClass
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue