diff --git a/operators/pkg/controller/elasticsearch/pvc/pvc.go b/operators/pkg/controller/elasticsearch/pvc/pvc.go index eb99fc45db..a05eda97cf 100644 --- a/operators/pkg/controller/elasticsearch/pvc/pvc.go +++ b/operators/pkg/controller/elasticsearch/pvc/pvc.go @@ -18,7 +18,6 @@ import ( var ( log = logf.Log.WithName("pvc") - standardStorageClassname = "standard" ErrNotNodeNameLabelNotFound = errors.New("node name not found as a label on the PVC") ) @@ -107,11 +106,13 @@ func compareResources(claim, candidate *corev1.PersistentVolumeClaim) bool { } func compareStorageClass(claim, candidate *corev1.PersistentVolumeClaim) bool { - if claim.Spec.StorageClassName != nil { - return reflect.DeepEqual(claim.Spec.StorageClassName, candidate.Spec.StorageClassName) + if claim.Spec.StorageClassName == nil { + // volumeClaimTemplate has no storageClass set: it should use the k8s cluster default + // since we don't know that default, we fallback to reusing any available volume + // from the same cluster (whatever the storage class actually is) + return true } - // No storage class name in the claim, only match if the claim is a standard storage class - return standardStorageClassname == *candidate.Spec.StorageClassName + return reflect.DeepEqual(claim.Spec.StorageClassName, candidate.Spec.StorageClassName) } // compare two maps but ignore the label.PodNameLabelName key diff --git a/operators/pkg/controller/elasticsearch/pvc/pvc_test.go b/operators/pkg/controller/elasticsearch/pvc/pvc_test.go index 4200ecd000..119f99a95d 100644 --- a/operators/pkg/controller/elasticsearch/pvc/pvc_test.go +++ b/operators/pkg/controller/elasticsearch/pvc/pvc_test.go @@ -203,14 +203,14 @@ func TestOrphanedPersistentVolumeClaims_FindOrphanedVolumeClaim(t *testing.T) { "elasticsearch-sample-es-6bw9qkw77k-"+volume.ElasticsearchDataVolumeName, sampleLabels1, "1Gi", - &standardStorageClassname, + nil, ), *newPVC( "elasticsearch-sample-es-6qg4hmd9dj", "elasticsearch-sample-es-6qg4hmd9dj-"+volume.ElasticsearchDataVolumeName, sampleLabels1, "1Gi", - &standardStorageClassname, + nil, ), }}, args: args{ @@ -230,7 +230,7 @@ func TestOrphanedPersistentVolumeClaims_FindOrphanedVolumeClaim(t *testing.T) { "elasticsearch-sample-es-6bw9qkw77k-"+volume.ElasticsearchDataVolumeName, sampleLabels1, "1Gi", - &standardStorageClassname, + nil, ), }, { name: "Labels mismatch", @@ -241,14 +241,14 @@ func TestOrphanedPersistentVolumeClaims_FindOrphanedVolumeClaim(t *testing.T) { "elasticsearch-sample-es-6bw9qkw77k-"+volume.ElasticsearchDataVolumeName, sampleLabels2, "1Gi", - &standardStorageClassname, + nil, ), *newPVC( "elasticsearch-sample-es-6qg4hmd9dj", "elasticsearch-sample-es-6qg4hmd9dj-"+volume.ElasticsearchDataVolumeName, sampleLabels2, "1Gi", - &standardStorageClassname, + nil, ), }}, args: args{ @@ -313,14 +313,14 @@ func TestOrphanedPersistentVolumeClaims_FindOrphanedVolumeClaim(t *testing.T) { "elasticsearch-sample-es-6bw9qkw77k-"+volume.ElasticsearchDataVolumeName, sampleLabels1, "1Gi", - &standardStorageClassname, + nil, ), *newPVC( "elasticsearch-sample-es-6qg4hmd9dj", "elasticsearch-sample-es-6qg4hmd9dj-"+volume.ElasticsearchDataVolumeName, sampleLabels1, "1Gi", - &standardStorageClassname, + nil, ), }}, args: args{