Skip to content

Commit

Permalink
Handle apiVersion for StorageClass to support k8s>=1.22 (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
plumdog authored Jul 1, 2022
1 parent e32cb88 commit e9d316b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion charts/efs-provisioner/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v1
name: efs-provisioner
description: A Helm chart for the AWS EFS external storage provisioner
version: 0.13.3
version: 0.14.0
appVersion: v2.4.0
home: https://github.com/kubernetes-incubator/external-storage/tree/master/aws/efs
sources:
Expand Down
23 changes: 23 additions & 0 deletions charts/efs-provisioner/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,26 @@ Create the name of the service account to use
{{ default "default" .Values.serviceAccount.name }}
{{- end -}}
{{- end -}}

{{/*
StorageClass apiVersion
*/}}
{{- define "efs-provisioner.storageClassApiVersion" -}}
{{- with .Values.efsProvisioner.storageClass }}
{{- /* use an explicit version if set */ -}}
{{- if .apiVersion -}}
{{- .apiVersion -}}
{{- else -}}
{{- /* otherwise, check the candidate versions, and pick the first match found, starting from the top or the bottom of the list, depending on apiVersionPolicy.newestAvailable */ -}}
{{- $matchingApiVersion := "" -}}
{{- range $candidateApiVersion := (.apiVersionPolicy.newestAvailable | ternary (reverse .apiVersionPolicy.candidateApiVersions) .apiVersionPolicy.candidateApiVersions) -}}
{{- if not $matchingApiVersion }}
{{- if $.Capabilities.APIVersions.Has (printf "%s/StorageClass" $candidateApiVersion) -}}
{{- $matchingApiVersion = $candidateApiVersion -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $matchingApiVersion -}}
{{- end -}}
{{- end -}}
{{- end -}}
2 changes: 1 addition & 1 deletion charts/efs-provisioner/templates/storageclass.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
kind: StorageClass
apiVersion: storage.k8s.io/v1beta1
apiVersion: {{ (include "efs-provisioner.storageClassApiVersion" .) | required "Unable to determine apiVersion for StorageClass and none explicitly set." }}
metadata:
name: {{ .Values.efsProvisioner.storageClass.name }}
labels:
Expand Down
11 changes: 11 additions & 0 deletions charts/efs-provisioner/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ efsProvisioner:
gidMax: 50000
reclaimPolicy: Delete
mountOptions: []
# Defaults based on k8s version (see apiVersionPolicy below), or can set explicitly.
apiVersion: null
apiVersionPolicy:
newestAvailable: false
# This is an ordered list of api versions that might serve
# StorageClass, ordered from oldest to newest. If
# newestAvailable is true, use the last one in the list that
# does serve StorageClass, otherwise, use the first that does.
candidateApiVersions:
- storage.k8s.io/v1beta1
- storage.k8s.io/v1

## Enable RBAC
##
Expand Down

0 comments on commit e9d316b

Please sign in to comment.