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

KO-371: Added a validation check to ensure that MRT fields are allowed only in SC namespaces #339

Merged
merged 3 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
22 changes: 22 additions & 0 deletions api/v1/aerospikecluster_validating_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,10 @@ func validateNamespaceConfig(
return nErr
}

if mErr := validateMRTFields(nsConf); mErr != nil {
return mErr
}

if nsStorage, ok := nsConf["storage-engine"]; ok {
if nsStorage == nil {
return fmt.Errorf(
Expand Down Expand Up @@ -1235,6 +1239,24 @@ func validateNamespaceConfig(
return nil
}

func validateMRTFields(nsConf map[string]interface{}) error {
mrtField := isMRTFieldSet(nsConf)
scEnabled := IsNSSCEnabled(nsConf)

if !scEnabled && mrtField {
return fmt.Errorf("MRT fields are not allowed in non-SC namespace %v", nsConf)
}

return nil
}

func isMRTFieldSet(nsConf map[string]interface{}) bool {
_, isMRTDurationSet := nsConf["mrt-duration"]
_, isDisableMRTWritesSet := nsConf["disable-mrt-writes"]

return isDisableMRTWritesSet || isMRTDurationSet
}

abhishekdwivedi3060 marked this conversation as resolved.
Show resolved Hide resolved
func validateNamespaceReplicationFactor(
nsConf map[string]interface{}, clSize int,
) error {
Expand Down
45 changes: 45 additions & 0 deletions test/cluster/strong_consistency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,28 @@ var _ = Describe("SCMode", func() {

validateRoster(k8sClient, ctx, clusterNamespacedName, scNamespace)
})

It("Should allow MRT fields in SC namespace", func() {
aeroCluster := createDummyAerospikeCluster(clusterNamespacedName, 3)
racks := getDummyRackConf(1)

sc1Path := "/test/dev/" + sc1Name
aeroCluster.Spec.Storage.Volumes = append(
aeroCluster.Spec.Storage.Volumes, getStorageVolumeForAerospike(sc1Name, sc1Path))

conf := getSCNamespaceConfig(sc1Name, sc1Path)
conf["mrt-duration"] = 15

racks[0].InputAerospikeConfig = &asdbv1.AerospikeConfigSpec{
Value: map[string]interface{}{
"namespaces": []interface{}{conf},
},
}
aeroCluster.Spec.RackConfig.Racks = racks

err := deployCluster(k8sClient, ctx, aeroCluster)
Expect(err).ToNot(HaveOccurred())
})
})

Context("When doing invalid operation", func() {
Expand Down Expand Up @@ -322,6 +344,29 @@ var _ = Describe("SCMode", func() {
Expect(err).To(HaveOccurred())
})

It("Should not allow MRT fields in non-SC namespace", func() {
aeroCluster := createDummyAerospikeCluster(clusterNamespacedName, 3)
racks := getDummyRackConf(1)

sc1Path := "/test/dev/" + sc1Name
aeroCluster.Spec.Storage.Volumes = append(
aeroCluster.Spec.Storage.Volumes, getStorageVolumeForAerospike(sc1Name, sc1Path))

conf := getSCNamespaceConfig(sc1Name, sc1Path)
conf["strong-consistency"] = false
conf["mrt-duration"] = 10

racks[0].InputAerospikeConfig = &asdbv1.AerospikeConfigSpec{
Value: map[string]interface{}{
"namespaces": []interface{}{conf},
},
}
aeroCluster.Spec.RackConfig.Racks = racks

err := deployCluster(k8sClient, ctx, aeroCluster)
Expect(err).To(HaveOccurred())
})

})
})

Expand Down
Loading