From b7b950eb28cfeae34b39db592d5880334049f0a7 Mon Sep 17 00:00:00 2001 From: Oleksii Kliukin Date: Mon, 16 Jul 2018 11:49:58 +0200 Subject: [PATCH] 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 --- pkg/cluster/k8sres.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/cluster/k8sres.go b/pkg/cluster/k8sres.go index 49bd9fe84..162f2ef45 100644 --- a/pkg/cluster/k8sres.go +++ b/pkg/cluster/k8sres.go @@ -835,14 +835,19 @@ func (c *Cluster) getNumberOfInstances(spec *spec.PostgresSpec) (newcur int32) { } func generatePersistentVolumeClaimTemplate(volumeSize, volumeStorageClass string) (*v1.PersistentVolumeClaim, error) { + + var storageClassName *string + metadata := metav1.ObjectMeta{ Name: constants.DataVolumeName, } 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} + storageClassName = &volumeStorageClass } else { metadata.Annotations = map[string]string{"volume.alpha.kubernetes.io/storage-class": "default"} + storageClassName = nil } quantity, err := resource.ParseQuantity(volumeSize) @@ -859,6 +864,7 @@ func generatePersistentVolumeClaimTemplate(volumeSize, volumeStorageClass string v1.ResourceStorage: quantity, }, }, + StorageClassName: storageClassName, }, }