Skip to content

Commit

Permalink
Ensure the the cluster reconciler status is set to be in simulation a…
Browse files Browse the repository at this point in the history
…fter each test
  • Loading branch information
johscheuer committed Nov 4, 2024
1 parent cadf6ba commit 9d88547
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 30 deletions.
54 changes: 28 additions & 26 deletions controllers/cluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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))
Expand Down
1 change: 1 addition & 0 deletions controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ var _ = AfterEach(func() {
k8sClient.Clear()
mock.ClearMockAdminClients()
mock.ClearMockLockClients()
clusterReconciler.InSimulation = true
})

func createDefaultRestore(cluster *fdbv1beta2.FoundationDBCluster) *fdbv1beta2.FoundationDBRestore {
Expand Down
10 changes: 6 additions & 4 deletions pkg/fdbadminclient/mock/admin_client_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,7 @@ func (client *AdminClient) ExcludeProcesses(addresses []fdbv1beta2.ProcessAddres
address := pAddr.String()
client.ExcludedAddresses[address] = fdbv1beta2.None{}
}

return nil
}

Expand All @@ -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
}

Expand Down

0 comments on commit 9d88547

Please sign in to comment.