Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standard might not be the default storage class #1061

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure I understand why we return true here? I read it as "if there is no storage class requested, then the candidate PV is compatible" which sounds wrong?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I guess we have no way of knowing what is the "default" storage class on a given cluster, so we fallback to anything?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should get that comment a bit more explicit:

// 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)

}
// 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