Skip to content

Commit

Permalink
First-seed-in-the-DC logic should respect additionalSeeds (#180)
Browse files Browse the repository at this point in the history
* The first seed logic needs to respect additionalSeeds

* gofmt fixes

* Fix the int test for the logic change

* typo

* Fix the assertions used
  • Loading branch information
jimdickinson authored Jul 31, 2020
1 parent b2cf2ec commit 77750d1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
13 changes: 7 additions & 6 deletions operator/pkg/reconciliation/reconcile_racks.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func (rc *ReconciliationContext) CheckRackPodTemplate() result.ReconcileResult {
statefulSet := rc.statefulSets[idx]

desiredSts, err := rc.desiredStatefulSetForExistingStatefulSet(statefulSet, rackName)

if err != nil {
logger.Error(err, "error calling desiredStatefulSetForExistingStatefulSet")
return result.Error(err)
Expand Down Expand Up @@ -729,7 +729,7 @@ func (rc *ReconciliationContext) GetUsers() []api.CassandraUser {
// add the standard superuser to our list of users
users := dc.Spec.Users
users = append(users, api.CassandraUser{
Superuser: true,
Superuser: true,
SecretName: dc.GetSuperuserSecretNamespacedName().Name,
})

Expand All @@ -744,7 +744,7 @@ func (rc *ReconciliationContext) UpdateSecretWatches() error {
name := types.NamespacedName{Name: user.SecretName, Namespace: dc.Namespace}
names = append(names, name)
}
dcNamespacedName := types.NamespacedName{Name: dc.Name, Namespace: dc.Namespace,}
dcNamespacedName := types.NamespacedName{Name: dc.Name, Namespace: dc.Namespace}
err := rc.SecretWatches.UpdateWatch(dcNamespacedName, names)

return err
Expand Down Expand Up @@ -787,10 +787,10 @@ func (rc *ReconciliationContext) CreateUsers() result.ReconcileResult {

patch := client.MergeFrom(rc.Datacenter.DeepCopy())
rc.Datacenter.Status.UsersUpserted = metav1.Now()

// For backwards compatibility
rc.Datacenter.Status.SuperUserUpserted = metav1.Now()

if err = rc.Client.Status().Patch(rc.Ctx, rc.Datacenter, patch); err != nil {
rc.ReqLogger.Error(err, "error updating the users upsert timestamp")
return result.Error(err)
Expand Down Expand Up @@ -1583,7 +1583,8 @@ func (rc *ReconciliationContext) startOneNodePerRack(endpointData httphelper.Cas
}

// if the DC has no ready seeds, label a pod as a seed before we start Cassandra on it
labelSeedBeforeStart := readySeeds == 0
// and also consider additional seeds
labelSeedBeforeStart := readySeeds == 0 && len(rc.Datacenter.Spec.AdditionalSeeds) == 0

rackThatNeedsNode := ""
for rackName, readyCount := range rackReadyCount {
Expand Down
20 changes: 19 additions & 1 deletion tests/additional_seeds/additional_seeds_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,15 +268,33 @@ var _ = Describe(testName, func() {

ns.WaitForOperatorReady()

step = "creating a datacenter resource with 2 racks/4 nodes and 2 additional seeds"
step = "creating a datacenter resource with 2 racks/4 nodes"
k = kubectl.ApplyFiles(dcYaml)
ns.ExecAndLog(step, k)

ns.WaitForDatacenterReady(dcName)

checkSeedConstraints()

step = "add additionalSeeds"
json := `
{
"spec": {
"additionalSeeds": ["192.168.1.1"]
}
}`
k = kubectl.PatchMerge(dcResource, json)
ns.ExecAndLog(step, k)

ns.WaitForDatacenterOperatorProgress(dcName, "Updating", 30)
ns.WaitForDatacenterOperatorProgress(dcName, "Ready", 1800)

checkSeedConstraints()

checkAdditionalSeedService()

// TODO provision a DC in another namespace and connect it to the first one
// with additional seeds, and test that's working
})
})
})
1 change: 0 additions & 1 deletion tests/testdata/additional-seeds-two-rack-four-node-dc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ spec:
managementApiAuth:
insecure: {}
size: 4
additionalSeeds: ["192.168.1.1"]
storageConfig:
cassandraDataVolumeClaimSpec:
storageClassName: server-storage
Expand Down

0 comments on commit 77750d1

Please sign in to comment.