Skip to content

Commit

Permalink
spec.service.container.storage immutable. Fixes #2168
Browse files Browse the repository at this point in the history
  • Loading branch information
rigazilla authored and ryanemerson committed Oct 10, 2024
1 parent 65c6129 commit 8ff8418
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
4 changes: 4 additions & 0 deletions api/v1/infinispan_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ func (i *Infinispan) ValidateUpdate(oldRuntimeObj runtime.Object) error {
allErrs = append(allErrs, err)
}

if i.Spec.Service.Container != nil && i.Spec.Service.Container.Storage != nil && *old.Spec.Service.Container.Storage != *i.Spec.Service.Container.Storage {
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec").Child("service").Child("container").Child("storage"), "Storage configuration is immutable and cannot be updated after initial Infinispan creation"))
}

return errorListToError(i, allErrs)
}

Expand Down
20 changes: 19 additions & 1 deletion api/v1/infinispan_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ var _ = Describe("Infinispan Webhooks", func() {
})
})

It("Should prevent immutable fields being updated", func() {
It("Should prevent JMX immutable field being updated", func() {
ispn := &Infinispan{
ObjectMeta: metav1.ObjectMeta{
Name: key.Name,
Expand All @@ -627,6 +627,24 @@ var _ = Describe("Infinispan Webhooks", func() {
)
})

It("Should prevent spec.service.container.storage immutable field being updated", func() {
ispn := &Infinispan{
ObjectMeta: metav1.ObjectMeta{
Name: key.Name,
Namespace: key.Namespace,
},
Spec: InfinispanSpec{
Replicas: 1,
},
}
Expect(k8sClient.Create(ctx, ispn)).Should(Succeed())
Expect(k8sClient.Get(ctx, key, ispn)).Should(Succeed())
*ispn.Spec.Service.Container.Storage = "2Gi" // Default is "1Gi"
expectInvalidErrStatus(k8sClient.Update(ctx, ispn),
statusDetailCause{"FieldValueForbidden", "spec.service.container.storage", "Storage configuration is immutable and cannot be updated after initial Infinispan creation"},
)
})

It("Should prevent incompatible TLS configuration", func() {
ispn := &Infinispan{
ObjectMeta: metav1.ObjectMeta{
Expand Down

0 comments on commit 8ff8418

Please sign in to comment.