diff --git a/api/v1alpha1/etcdcluster_webhook.go b/api/v1alpha1/etcdcluster_webhook.go index 1ad0976f..14e0bdbb 100644 --- a/api/v1alpha1/etcdcluster_webhook.go +++ b/api/v1alpha1/etcdcluster_webhook.go @@ -79,7 +79,8 @@ func (r *EtcdCluster) ValidateUpdate(old runtime.Object) (admission.Warnings, er } var allErrors field.ErrorList - if oldCluster.Spec.Storage.EmptyDir.String() != r.Spec.Storage.EmptyDir.String() { + if oldCluster.Spec.Storage.EmptyDir == nil && r.Spec.Storage.EmptyDir != nil || + oldCluster.Spec.Storage.EmptyDir != nil && r.Spec.Storage.EmptyDir == nil { allErrors = append(allErrors, field.Invalid( field.NewPath("spec", "storage", "emptyDir"), r.Spec.Storage.EmptyDir, diff --git a/api/v1alpha1/etcdcluster_webhook_test.go b/api/v1alpha1/etcdcluster_webhook_test.go index b4b191a6..1932a580 100644 --- a/api/v1alpha1/etcdcluster_webhook_test.go +++ b/api/v1alpha1/etcdcluster_webhook_test.go @@ -95,12 +95,28 @@ var _ = Describe("EtcdCluster Webhook", func() { Storage: StorageSpec{EmptyDir: nil}, }, } - w, err := etcdCluster.ValidateUpdate(oldCluster) - gomega.Expect(w).To(gomega.BeEmpty()) + _, err := etcdCluster.ValidateUpdate(oldCluster) if gomega.Expect(err).To(gomega.HaveOccurred()) { statusErr := err.(*errors.StatusError) gomega.Expect(statusErr.ErrStatus.Message).To(gomega.ContainSubstring("field is immutable")) } }) + + It("Should allow changing emptydir size", func() { + etcdCluster := &EtcdCluster{ + Spec: EtcdClusterSpec{ + Replicas: ptr.To(int32(1)), + Storage: StorageSpec{EmptyDir: &corev1.EmptyDirVolumeSource{SizeLimit: ptr.To(resource.MustParse("4Gi"))}}, + }, + } + oldCluster := &EtcdCluster{ + Spec: EtcdClusterSpec{ + Replicas: ptr.To(int32(1)), + Storage: StorageSpec{EmptyDir: &corev1.EmptyDirVolumeSource{SizeLimit: ptr.To(resource.MustParse("10Gi"))}}, + }, + } + _, err := etcdCluster.ValidateUpdate(oldCluster) + gomega.Expect(err).To(gomega.Succeed()) + }) }) })