diff --git a/controllers/cluster_controller_test.go b/controllers/cluster_controller_test.go index 7c93420d..7e487fcb 100644 --- a/controllers/cluster_controller_test.go +++ b/controllers/cluster_controller_test.go @@ -587,36 +587,38 @@ var _ = Describe("cluster_controller", func() { Expect(k8sClient.Update(context.TODO(), cluster)).NotTo(HaveOccurred()) }) - It("should replace the targeted Pod and update the cluster status", func() { - pods := &corev1.PodList{} - Expect(k8sClient.List(context.TODO(), pods, getListOptions(cluster)...)).NotTo(HaveOccurred()) - Expect(pods.Items).To(HaveLen(17)) + When("the pod is in a healthy state", func() { + It("should replace the targeted Pod and update the cluster status", func() { + pods := &corev1.PodList{} + Expect(k8sClient.List(context.TODO(), pods, getListOptions(cluster)...)).NotTo(HaveOccurred()) + Expect(pods.Items).To(HaveLen(17)) - Expect(getProcessClassMap(cluster, pods.Items)).To(Equal(map[fdbv1beta2.ProcessClass]int{ - fdbv1beta2.ProcessClassStorage: 4, - fdbv1beta2.ProcessClassLog: 4, - fdbv1beta2.ProcessClassStateless: 8, - fdbv1beta2.ProcessClassClusterController: 1, - })) + Expect(getProcessClassMap(cluster, pods.Items)).To(Equal(map[fdbv1beta2.ProcessClass]int{ + fdbv1beta2.ProcessClassStorage: 4, + fdbv1beta2.ProcessClassLog: 4, + fdbv1beta2.ProcessClassStateless: 8, + fdbv1beta2.ProcessClassClusterController: 1, + })) - processGroupIDs := make([]string, 17) - for idx, pod := range pods.Items { - processGroupIDs[idx] = pod.Labels[fdbv1beta2.FDBProcessGroupIDLabel] - } - Expect(processGroupIDs).NotTo(ContainElements(string(replacedProcessGroup.ProcessGroupID))) + processGroupIDs := make([]string, 17) + for idx, pod := range pods.Items { + processGroupIDs[idx] = pod.Labels[fdbv1beta2.FDBProcessGroupIDLabel] + } + Expect(processGroupIDs).NotTo(ContainElements(string(replacedProcessGroup.ProcessGroupID))) - // Should change the connection string - Expect(cluster.Status.ConnectionString).NotTo(Equal(originalConnectionString)) + // Should change the connection string + Expect(cluster.Status.ConnectionString).NotTo(Equal(originalConnectionString)) - // Should remove the process group - Expect(fdbv1beta2.ContainsProcessGroupID(cluster.Status.ProcessGroups, replacedProcessGroup.ProcessGroupID)).To(BeFalse()) + // Should remove the process group + Expect(fdbv1beta2.ContainsProcessGroupID(cluster.Status.ProcessGroups, replacedProcessGroup.ProcessGroupID)).To(BeFalse()) - // Should exclude and re-include the process - adminClient, err := mock.NewMockAdminClientUncast(cluster, k8sClient) - Expect(err).NotTo(HaveOccurred()) - Expect(adminClient).NotTo(BeNil()) - Expect(adminClient.ExcludedAddresses).To(BeEmpty()) - Expect(adminClient.ReincludedAddresses).To(HaveKeyWithValue(replacedProcessGroup.Addresses[0], true)) + // Should exclude and re-include the process + adminClient, err := mock.NewMockAdminClientUncast(cluster, k8sClient) + Expect(err).NotTo(HaveOccurred()) + Expect(adminClient).NotTo(BeNil()) + Expect(adminClient.ExcludedAddresses).To(BeEmpty()) + Expect(adminClient.ReincludedAddresses).To(HaveKeyWithValue(replacedProcessGroup.Addresses[0], true)) + }) }) When("a pod is stuck in terminating", func() { @@ -738,7 +740,7 @@ var _ = Describe("cluster_controller", func() { }) }) - Context("with a removal with no exclusion", func() { + When("the pod should be removed without an exclusion", func() { BeforeEach(func() { pod := &corev1.Pod{} Expect(k8sClient.Get(context.Background(), client.ObjectKey{Name: replacedProcessGroup.GetPodName(cluster), Namespace: cluster.Namespace}, pod)) diff --git a/controllers/suite_test.go b/controllers/suite_test.go index aaa1f0f0..2b3dbd92 100644 --- a/controllers/suite_test.go +++ b/controllers/suite_test.go @@ -106,6 +106,7 @@ var _ = AfterEach(func() { k8sClient.Clear() mock.ClearMockAdminClients() mock.ClearMockLockClients() + clusterReconciler.InSimulation = true }) func createDefaultRestore(cluster *fdbv1beta2.FoundationDBCluster) *fdbv1beta2.FoundationDBRestore { diff --git a/pkg/fdbadminclient/mock/admin_client_mock.go b/pkg/fdbadminclient/mock/admin_client_mock.go index 402d4b15..696e2b23 100644 --- a/pkg/fdbadminclient/mock/admin_client_mock.go +++ b/pkg/fdbadminclient/mock/admin_client_mock.go @@ -579,6 +579,7 @@ func (client *AdminClient) ExcludeProcesses(addresses []fdbv1beta2.ProcessAddres address := pAddr.String() client.ExcludedAddresses[address] = fdbv1beta2.None{} } + return nil } @@ -589,13 +590,14 @@ func (client *AdminClient) IncludeProcesses(addresses []fdbv1beta2.ProcessAddres defer adminClientMutex.Unlock() for _, address := range addresses { - address := address.String() - _, ok := client.ExcludedAddresses[address] + addr := address.String() + _, ok := client.ExcludedAddresses[addr] if ok { - client.ReincludedAddresses[address] = true - delete(client.ExcludedAddresses, address) + client.ReincludedAddresses[addr] = true + delete(client.ExcludedAddresses, addr) } } + return nil }