Skip to content

Commit

Permalink
add storageClass.withPathSuffix
Browse files Browse the repository at this point in the history
  • Loading branch information
jwangatabsolute committed Jul 15, 2021
1 parent e289a21 commit e747edb
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
3 changes: 2 additions & 1 deletion charts/nfs-subdir-external-provisioner/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ The following tables lists the configurable parameters of this chart and their d
| `storageClass.provisionerName` | Name of the provisionerName | null |
| `storageClass.archiveOnDelete` | Archive PVC when deleting | `true` |
| `storageClass.onDelete` | Strategy on PVC deletion. Overrides archiveOnDelete when set to lowercase values 'delete' or 'retain' | null |
| `storageClass.pathPattern` | Specifies a template for the directory name | null |
| `storageClass.pathPattern` | Specifies a template for the directory name. Ignored if `storageClass.pathPattern` is set to false | null |
| `storageClass.withPathSuffix` | Specifies if a suffix is added to the path. | `true` |
| `storageClass.accessModes` | Set access mode for PV | `ReadWriteOnce` |
| `storageClass.annotations` | Set additional annotations for the StorageClass | `{}` |
| `leaderElection.enabled` | Enables or disables leader election | `true` |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ allowVolumeExpansion: {{ .Values.storageClass.allowVolumeExpansion }}
reclaimPolicy: {{ .Values.storageClass.reclaimPolicy }}
parameters:
archiveOnDelete: "{{ .Values.storageClass.archiveOnDelete }}"
withPathSuffix: "{{ .Values.storageClass.withPathSuffix }}"
{{- if .Values.storageClass.pathPattern }}
pathPattern: "{{ .Values.storageClass.pathPattern }}"
{{- end }}
Expand Down
6 changes: 6 additions & 0 deletions charts/nfs-subdir-external-provisioner/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,14 @@ storageClass:
# Ignored if value not set.
onDelete:

# If the directory path should have a suffix to nfs.path
# If true, it will use either storageClass.pathPattern or ${namespace}-${pvcName}-${pvName}
# If false, it will not add any suffix to nfs.path regardless of storageClass.pathPattern
withPathSuffix: true

# Specifies a template for creating a directory path via PVC metadata's such as labels, annotations, name or namespace.
# Ignored if value not set.
# If storageClass.withPathSuffix is false, pathPattern will be ignored even if it is set
pathPattern:

# Set access mode - ReadWriteOnce, ReadOnlyMany or ReadWriteMany
Expand Down
16 changes: 15 additions & 1 deletion cmd/nfs-subdir-external-provisioner/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,21 @@ func (p *nfsProvisioner) Provision(ctx context.Context, options controller.Provi
path := filepath.Join(p.path, pvName)

pathPattern, exists := options.StorageClass.Parameters["pathPattern"]
if exists {
withPathSuffix, existsWithPathSuffix := options.StorageClass.Parameters["withPathSuffix"]
// default is true
withPathSuffixBool := true
if existsWithPathSuffix {
var err error
withPathSuffixBool, err = strconv.ParseBool(withPathSuffix)
if err != nil {
return nil, controller.ProvisioningFinished, fmt.Errorf("storageClass.withPathSuffix is not a boolean value")
}
}
if !withPathSuffixBool {
path = p.path
fullPath = mountPath
}
else if exists {
customPath := metadata.stringParser(pathPattern)
if customPath != "" {
path = filepath.Join(p.path, customPath)
Expand Down

0 comments on commit e747edb

Please sign in to comment.