Skip to content

Commit

Permalink
Remove underscore from new statefulset name during second online upgr…
Browse files Browse the repository at this point in the history
…ade (#854)

When you do back to back online upgrade, the 2nd time, the new sts names
contain the subcluster to mimic names. If any of the names contains an
underscore, the sts name will be invalid. This PR converts underscore to
hyphen to prevent that.
  • Loading branch information
roypaulin committed Jul 11, 2024
1 parent 2560667 commit a9c6174
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
14 changes: 8 additions & 6 deletions pkg/controllers/vdb/onlineupgrade_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -894,23 +894,25 @@ func (r *OnlineUpgradeReconciler) genNewSubclusterStsName(newSCName string, scTo
}

// Preference is to match the name of the new subcluster.
nm := fmt.Sprintf("%s-%s", r.VDB.Name, newSCName)
preferredStsName := fmt.Sprintf("%s-%s", r.VDB.Name, newSCName)
// replace underscore to hypen for the statefulset name
nm = v1beta1.GenCompatibleFQDNHelper(nm)
if _, found := stsNameMap[nm]; !found {
return nm, nil
preferredStsName = v1beta1.GenCompatibleFQDNHelper(preferredStsName)
if _, found := stsNameMap[preferredStsName]; !found {
return preferredStsName, nil
}

// Then try using the original name of the subcluster. This may be available
// if this the 2nd, 4th, etc. online upgrade. The sandbox will oscilate
// between the name of the subcluster in the sandbox and its original name.
nm = fmt.Sprintf("%s-%s", r.VDB.Name, scToMimic.Name)
nm := fmt.Sprintf("%s-%s", r.VDB.Name, scToMimic.Name)
// replace underscore to hypen for the statefulset name
nm = v1beta1.GenCompatibleFQDNHelper(nm)
if _, found := stsNameMap[nm]; !found {
return nm, nil
}

// Otherwise, generate a name using a uuid suffix
return r.genNameWithUUID(fmt.Sprintf("%s-%s", r.VDB.Name, newSCName),
return r.genNameWithUUID(preferredStsName,
func(nm string) bool { _, found := stsNameMap[nm]; return found })
}

Expand Down
19 changes: 19 additions & 0 deletions pkg/controllers/vdb/onlineupgrade_reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,25 @@ var _ = Describe("onlineupgrade_reconciler", func() {
Ω(vdb.Spec.Sandboxes[0].Image).Should(Equal(NewImageName))
})

It("should replace underscore with hyphen in sts name", func() {
vdb := vapi.MakeVDBForVclusterOps()
vdb.Spec.Subclusters = []vapi.Subcluster{
{Name: "sc_1"},
}
r := &OnlineUpgradeReconciler{
VDB: vdb,
}
sc := &r.VDB.Spec.Subclusters[0]
newSCName := "sc_1-sb"
stsName, _ := r.genNewSubclusterStsName(newSCName, sc)
Ω(stsName).Should(Equal(fmt.Sprintf("%s-sc-1-sb", r.VDB.Name)))
sc.Annotations = map[string]string{
vmeta.StsNameOverrideAnnotation: stsName,
}
stsName, _ = r.genNewSubclusterStsName(newSCName, sc)
Ω(stsName).Should(Equal(fmt.Sprintf("%s-sc-1", r.VDB.Name)))
})

It("should use VerticaReplicator CR to handle replication", func() {
vdb := vapi.MakeVDBForVclusterOps()
test.CreateVDB(ctx, k8sClient, vdb)
Expand Down

0 comments on commit a9c6174

Please sign in to comment.