Skip to content

Commit

Permalink
[CN-983] Persistence of SQL metadata shouldn't be changed once it was…
Browse files Browse the repository at this point in the history
… enabled (#883)

* validation for sql catalogPersistenceEnabled

* update error path

* fix validation
  • Loading branch information
semihbkgr committed Sep 20, 2023
1 parent ddd94ce commit 1c948ce
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
7 changes: 7 additions & 0 deletions api/v1alpha1/hazelcast_validation.go
Expand Up @@ -360,6 +360,7 @@ func (v *hazelcastValidator) validateNotUpdatableHazelcastFields(current *Hazelc
}

v.validateNotUpdatableHzPersistenceFields(current.Persistence, last.Persistence)
v.validateNotUpdatableSQLFields(current.SQL, last.SQL)
}

func (v *hazelcastValidator) validateNotUpdatableHzPersistenceFields(current, last *HazelcastPersistenceConfiguration) {
Expand All @@ -386,6 +387,12 @@ func (v *hazelcastValidator) validateNotUpdatableHzPersistenceFields(current, la
}
}

func (v *hazelcastValidator) validateNotUpdatableSQLFields(current, last *SQL) {
if last != nil && last.CatalogPersistenceEnabled && (current == nil || !current.CatalogPersistenceEnabled) {
v.Forbidden(Path("spec", "sql", "catalogPersistenceEnabled"), "field cannot be disabled after it has been enabled")
}
}

func (v *hazelcastValidator) validateJetConfig(h *Hazelcast) {
j := h.Spec.JetEngineConfiguration
p := h.Spec.Persistence
Expand Down
30 changes: 30 additions & 0 deletions test/integration/hazelcast_test.go
Expand Up @@ -2185,6 +2185,36 @@ var _ = Describe("Hazelcast CR", func() {

Expect(hz.Spec.SQL.CatalogPersistenceEnabled).Should(BeTrue())
})

It("should fail to disable catalogPersistence", Label("fast"), func() {
spec := test.HazelcastSpec(defaultHazelcastSpecValues(), ee)
spec.Persistence = &hazelcastv1alpha1.HazelcastPersistenceConfiguration{
BaseDir: "/data/hot-restart/",
ClusterDataRecoveryPolicy: hazelcastv1alpha1.FullRecovery,
Pvc: &hazelcastv1alpha1.PersistencePvcConfiguration{
AccessModes: []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce},
RequestStorage: resource.NewQuantity(9*2^20, resource.BinarySI),
},
}
spec.SQL = &hazelcastv1alpha1.SQL{
CatalogPersistenceEnabled: true,
}

hzSpec, _ := json.Marshal(&spec)

hz := &hazelcastv1alpha1.Hazelcast{
ObjectMeta: randomObjectMeta(namespace, n.LastSuccessfulSpecAnnotation, string(hzSpec)),
Spec: spec,
}

Create(hz)
hz = ensureHzStatusIsPending(hz)
Expect(hz.Spec.SQL.CatalogPersistenceEnabled).Should(BeTrue())

hz.Spec.SQL.CatalogPersistenceEnabled = false
err := k8sClient.Update(context.Background(), hz)
Expect(err).Should(MatchError(ContainSubstring("field cannot be disabled after it has been enabled")))
})
})
})
})

0 comments on commit 1c948ce

Please sign in to comment.