Skip to content

Commit

Permalink
Add a new webhook rule for sandboxes (#770)
Browse files Browse the repository at this point in the history
This PR adds a new webhook rule for sandboxes in CRD: cannot have a
primary subcluster defined in a sandbox.
  • Loading branch information
cchen-vertica committed Jul 24, 2024
1 parent 5cc0b80 commit 4d27daa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion api/v1/verticadb_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -1160,11 +1160,16 @@ func (v *VerticaDB) validateSubclustersInSandboxes(allErrs field.ErrorList) fiel
// check if a non-existing subcluster is defined in a sandbox
scMap := v.GenSubclusterMap()
for sc, i := range seenScWithSbIndex {
if _, ok := scMap[sc]; !ok {
if scInfo, ok := scMap[sc]; !ok {
err := field.Invalid(path.Index(i),
sandboxes[i],
fmt.Sprintf("subcluster %s does not exist", sc))
allErrs = append(allErrs, err)
} else if scInfo.IsPrimary() {
err := field.Invalid(path.Index(i),
sandboxes[i],
fmt.Sprintf("subcluster %s is a primary subcluster that is not allowed to be in a sandbox", sc))
allErrs = append(allErrs, err)
}
}

Expand Down
9 changes: 9 additions & 0 deletions api/v1/verticadb_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,15 @@ var _ = Describe("verticadb_webhook", func() {
{Name: "sandbox2", Image: mainClusterImageVer, Subclusters: []SubclusterName{{Name: "sc2"}, {Name: "sc3"}}},
}
Ω(vdb.validateVerticaDBSpec()).Should(HaveLen(1))

// cannot have a primary subcluster defined in a sandbox
// change sc1 from a secondary subcluster to a primary subcluster
vdb.Spec.Subclusters[1].Type = PrimarySubcluster
vdb.Spec.Sandboxes = []Sandbox{
{Name: "sandbox1", Image: mainClusterImageVer, Subclusters: []SubclusterName{{Name: "sc1"}}},
{Name: "sandbox2", Image: mainClusterImageVer, Subclusters: []SubclusterName{{Name: "sc2"}, {Name: "sc3"}}},
}
Ω(vdb.validateVerticaDBSpec()).Should(HaveLen(1))
})

It("should validate the number of subclusters in each sandbox", func() {
Expand Down

0 comments on commit 4d27daa

Please sign in to comment.