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

Do not reject PVC update when a different unit is used #2857

Merged
merged 1 commit into from
Apr 10, 2020
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
10 changes: 6 additions & 4 deletions pkg/apis/elasticsearch/v1/validations.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ package v1
import (
"fmt"
"net"
"reflect"

apiequality "k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/util/validation/field"

commonv1 "github.com/elastic/cloud-on-k8s/pkg/apis/common/v1"
"github.com/elastic/cloud-on-k8s/pkg/controller/common/version"
esversion "github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/version"
netutil "github.com/elastic/cloud-on-k8s/pkg/utils/net"
"k8s.io/apimachinery/pkg/util/validation/field"
)

const (
Expand Down Expand Up @@ -153,8 +154,9 @@ func pvcModification(current, proposed *Elasticsearch) field.ErrorList {
}

// ssets do not allow modifications to fields other than 'replicas', 'template', and 'updateStrategy'
// reflection isn't ideal, but okay here since the ES object does not have the status of the claims
if !reflect.DeepEqual(node.VolumeClaimTemplates, currNode.VolumeClaimTemplates) {
// reflection isn't ideal, but okay here since the ES object does not have the status of the claims.
// Checking semantic equality here allows providing PVC storage size with different units (eg. 1Ti vs. 1024Gi).
if !apiequality.Semantic.DeepEqual(node.VolumeClaimTemplates, currNode.VolumeClaimTemplates) {
errs = append(errs, field.Invalid(field.NewPath("spec").Child("nodeSet").Index(i).Child("volumeClaimTemplates"), node.VolumeClaimTemplates, pvcImmutableMsg))
}
}
Expand Down
30 changes: 29 additions & 1 deletion pkg/apis/elasticsearch/v1/validations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,35 @@ func Test_pvcModified(t *testing.T) {
},
expectErrors: true,
},

{
name: "same size with different unit accepted",
current: current,
proposed: &Elasticsearch{
Spec: ElasticsearchSpec{
Version: "7.2.0",
NodeSets: []NodeSet{
{
Name: "master",
VolumeClaimTemplates: []corev1.PersistentVolumeClaim{
{
ObjectMeta: metav1.ObjectMeta{
Name: "elasticsearch-data",
},
Spec: corev1.PersistentVolumeClaimSpec{
Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceStorage: resource.MustParse("5120Mi"),
},
},
},
},
},
},
},
},
},
expectErrors: false,
},
{
name: "same size accepted",
current: current,
Expand Down