Skip to content

Commit

Permalink
Standard might not be the default storage class (#1061)
Browse files Browse the repository at this point in the history
* standard may not be the default class storage
  • Loading branch information
barkbay authored Jun 12, 2019
1 parent 41e9cdf commit e09bf2e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
11 changes: 6 additions & 5 deletions operators/pkg/controller/elasticsearch/pvc/pvc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)

Expand Down Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions operators/pkg/controller/elasticsearch/pvc/pvc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -230,7 +230,7 @@ func TestOrphanedPersistentVolumeClaims_FindOrphanedVolumeClaim(t *testing.T) {
"elasticsearch-sample-es-6bw9qkw77k-"+volume.ElasticsearchDataVolumeName,
sampleLabels1,
"1Gi",
&standardStorageClassname,
nil,
),
}, {
name: "Labels mismatch",
Expand All @@ -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{
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit e09bf2e

Please sign in to comment.