Skip to content

Commit

Permalink
moved new functions to validateImmutableFields. fixed 3 broken test c…
Browse files Browse the repository at this point in the history
…ases
  • Loading branch information
LiboYu2 committed Oct 31, 2024
1 parent c573373 commit 3b1ed31
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
11 changes: 6 additions & 5 deletions api/v1/verticadb_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,7 @@ func (v *VerticaDB) ValidateUpdate(old runtime.Object) error {
verticadblog.Info("validate update", "name", v.Name, "GroupVersion", GroupVersion)

allErrs := append(v.validateImmutableFields(old), v.validateVerticaDBSpec()...)
allErrs = v.validateShutdownSandboxImage(old, allErrs)
allErrs = v.validateTerminatingSandboxes(old, allErrs)
allErrs = v.validateUnsandboxShutdownConditions(old, allErrs)
allErrs = v.validateAnnotatedSubclustersInShutdownSandbox(old, allErrs)
allErrs = v.validateNewSBoxOrSClusterShutdownUnset(allErrs)

if len(allErrs) == 0 {
return nil
}
Expand Down Expand Up @@ -154,6 +150,11 @@ func (v *VerticaDB) validateImmutableFields(old runtime.Object) field.ErrorList
allErrs = v.checkImmutableStsName(oldObj, allErrs)
allErrs = v.checkValidSubclusterTypeTransition(oldObj, allErrs)
allErrs = v.checkSandboxesDuringUpgrade(oldObj, allErrs)
allErrs = v.validateShutdownSandboxImage(old, allErrs)
allErrs = v.validateTerminatingSandboxes(old, allErrs)
allErrs = v.validateUnsandboxShutdownConditions(old, allErrs)
allErrs = v.validateAnnotatedSubclustersInShutdownSandbox(old, allErrs)
allErrs = v.validateNewSBoxOrSClusterShutdownUnset(allErrs)
return allErrs
}

Expand Down
17 changes: 17 additions & 0 deletions api/v1/verticadb_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,13 @@ var _ = Describe("verticadb_webhook", func() {
{Name: "sandbox1", Image: mainClusterImageVer, Subclusters: []SubclusterName{{Name: "sc1"}}},
{Name: "sandbox2", Image: mainClusterImageVer, Subclusters: []SubclusterName{{Name: "sc2"}, {Name: "sc3"}}},
}
newVdb.Status.Subclusters = []SubclusterStatus{
{Name: "main"},
{Name: "sc1"},
{Name: "sc2"},
{Name: "sc3"},
{Name: "sc4"},
}
newVdb.ObjectMeta.Annotations[vmeta.VersionAnnotation] = SandboxSupportedMinVersion
newVdb.ObjectMeta.Annotations[vmeta.VClusterOpsAnnotation] = vmeta.VClusterOpsAnnotationTrue
resetStatusConditionsForDBInitialized(newVdb)
Expand Down Expand Up @@ -1215,6 +1222,11 @@ var _ = Describe("verticadb_webhook", func() {
{Name: "sand1", Subclusters: []SubclusterName{{Name: "sc2"}, {Name: "sc3"}}},
}
newVdb := oldVdb.DeepCopy()
newVdb.Status.Subclusters = []SubclusterStatus{
{Name: "sc1"},
{Name: "sc2"},
{Name: "sc3"},
}
newVdb.Spec.Sandboxes[0].Subclusters = []SubclusterName{{Name: "sc2"}}
Ω(newVdb.validateImmutableFields(oldVdb)).Should(HaveLen(1))
newVdb.Spec.Sandboxes[0].Subclusters = []SubclusterName{{Name: "sc3"}}
Expand Down Expand Up @@ -1286,6 +1298,11 @@ var _ = Describe("verticadb_webhook", func() {
{Name: "sc3", Type: SecondarySubcluster, Size: 1},
}
newVdb := oldVdb.DeepCopy()
newVdb.Status.Subclusters = []SubclusterStatus{
{Name: "sc1"},
{Name: "sc2"},
{Name: "sc3"},
}
Ω(newVdb.validateImmutableFields(oldVdb)).Should(HaveLen(0))
newVdb.Spec.Sandboxes = []Sandbox{
{Name: sbName, Subclusters: []SubclusterName{{Name: "sc3"}}},
Expand Down

0 comments on commit 3b1ed31

Please sign in to comment.