Use the StorageClassName field of the volumeClaimTemplate. (#338)

The old way of specifying it with the annotation is deprecated and not
available in recent Kubernetes versions. We will keep it there anyway
until upgrading to the new go-client that is incompatible with those
versions.

Per report from @schmitch
This commit is contained in:
Oleksii Kliukin 2018-07-16 11:49:58 +02:00 committed by GitHub
parent 25a306244f
commit b7b950eb28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 1 deletions

View File

@ -835,14 +835,19 @@ func (c *Cluster) getNumberOfInstances(spec *spec.PostgresSpec) (newcur int32) {
} }
func generatePersistentVolumeClaimTemplate(volumeSize, volumeStorageClass string) (*v1.PersistentVolumeClaim, error) { func generatePersistentVolumeClaimTemplate(volumeSize, volumeStorageClass string) (*v1.PersistentVolumeClaim, error) {
var storageClassName *string
metadata := metav1.ObjectMeta{ metadata := metav1.ObjectMeta{
Name: constants.DataVolumeName, Name: constants.DataVolumeName,
} }
if volumeStorageClass != "" { if volumeStorageClass != "" {
// TODO: check if storage class exists // TODO: remove the old annotation, switching completely to the StorageClassName field.
metadata.Annotations = map[string]string{"volume.beta.kubernetes.io/storage-class": volumeStorageClass} metadata.Annotations = map[string]string{"volume.beta.kubernetes.io/storage-class": volumeStorageClass}
storageClassName = &volumeStorageClass
} else { } else {
metadata.Annotations = map[string]string{"volume.alpha.kubernetes.io/storage-class": "default"} metadata.Annotations = map[string]string{"volume.alpha.kubernetes.io/storage-class": "default"}
storageClassName = nil
} }
quantity, err := resource.ParseQuantity(volumeSize) quantity, err := resource.ParseQuantity(volumeSize)
@ -859,6 +864,7 @@ func generatePersistentVolumeClaimTemplate(volumeSize, volumeStorageClass string
v1.ResourceStorage: quantity, v1.ResourceStorage: quantity,
}, },
}, },
StorageClassName: storageClassName,
}, },
} }