From 77750d11c62f2c3043f1088e377b743859c3be96 Mon Sep 17 00:00:00 2001 From: Jim Dickinson Date: Fri, 31 Jul 2020 10:56:03 -0400 Subject: [PATCH] First-seed-in-the-DC logic should respect additionalSeeds (#180) * The first seed logic needs to respect additionalSeeds * gofmt fixes * Fix the int test for the logic change * typo * Fix the assertions used --- .../pkg/reconciliation/reconcile_racks.go | 13 ++++++------ .../additional_seeds_suite_test.go | 20 ++++++++++++++++++- ...dditional-seeds-two-rack-four-node-dc.yaml | 1 - 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/operator/pkg/reconciliation/reconcile_racks.go b/operator/pkg/reconciliation/reconcile_racks.go index 719cbf720..86faf2a49 100644 --- a/operator/pkg/reconciliation/reconcile_racks.go +++ b/operator/pkg/reconciliation/reconcile_racks.go @@ -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) @@ -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, }) @@ -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 @@ -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) @@ -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 { diff --git a/tests/additional_seeds/additional_seeds_suite_test.go b/tests/additional_seeds/additional_seeds_suite_test.go index 08218041f..92f8d47e7 100644 --- a/tests/additional_seeds/additional_seeds_suite_test.go +++ b/tests/additional_seeds/additional_seeds_suite_test.go @@ -268,7 +268,7 @@ 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) @@ -276,7 +276,25 @@ var _ = Describe(testName, func() { 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 }) }) }) diff --git a/tests/testdata/additional-seeds-two-rack-four-node-dc.yaml b/tests/testdata/additional-seeds-two-rack-four-node-dc.yaml index 8ef4f9f37..2bcd21e4b 100644 --- a/tests/testdata/additional-seeds-two-rack-four-node-dc.yaml +++ b/tests/testdata/additional-seeds-two-rack-four-node-dc.yaml @@ -9,7 +9,6 @@ spec: managementApiAuth: insecure: {} size: 4 - additionalSeeds: ["192.168.1.1"] storageConfig: cassandraDataVolumeClaimSpec: storageClassName: server-storage