Skip to content

Commit

Permalink
Set nodeSelector on jobs/cronjobs
Browse files Browse the repository at this point in the history
  • Loading branch information
olliewalsh committed Nov 13, 2024
1 parent 3217501 commit 1d55c7c
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 4 deletions.
4 changes: 4 additions & 0 deletions pkg/nova/celldelete.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,9 @@ func CellDeleteJob(
},
}

if cell.Spec.NodeSelector != nil && len(*cell.Spec.NodeSelector) > 0 {
job.Spec.Template.Spec.NodeSelector = *cell.Spec.NodeSelector
}

return job
}
4 changes: 4 additions & 0 deletions pkg/nova/cellmapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,9 @@ func CellMappingJob(
},
}

if cell.Spec.NodeSelector != nil && len(*cell.Spec.NodeSelector) > 0 {
job.Spec.Template.Spec.NodeSelector = *cell.Spec.NodeSelector
}

return job
}
4 changes: 4 additions & 0 deletions pkg/nova/host_discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,9 @@ func HostDiscoveryJob(
},
}

if instance.Spec.NodeSelector != nil && len(*instance.Spec.NodeSelector) > 0 {
job.Spec.Template.Spec.NodeSelector = *instance.Spec.NodeSelector
}

return job
}
4 changes: 4 additions & 0 deletions pkg/novaconductor/dbpurge.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,9 @@ func DBPurgeCronJob(
},
}

if instance.Spec.NodeSelector != nil && len(*instance.Spec.NodeSelector) > 0 {
cron.Spec.JobTemplate.Spec.Template.Spec.NodeSelector = *instance.Spec.NodeSelector
}

return cron
}
5 changes: 5 additions & 0 deletions pkg/novaconductor/dbsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,10 @@ func CellDBSyncJob(
},
},
}

if instance.Spec.NodeSelector != nil && len(*instance.Spec.NodeSelector) > 0 {
job.Spec.Template.Spec.NodeSelector = *instance.Spec.NodeSelector
}

return job
}
29 changes: 25 additions & 4 deletions test/functional/nova_reconfiguration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,14 +333,17 @@ var _ = Describe("Nova reconfiguration", func() {
nova.Spec.NodeSelector = &newSelector

g.Expect(k8sClient.Update(ctx, nova)).To(Succeed())
novaDeploymentName := serviceNameFunc()
th.SimulateStatefulSetReplicaReady(cell0.ConductorStatefulSetName)
th.SimulateStatefulSetReplicaReady(novaDeploymentName)
SimulateReadyOfNovaTopServices()
th.SimulateJobSuccess(cell1.DBSyncJobName)
th.SimulateJobSuccess(cell2.DBSyncJobName)

serviceDeployment := th.GetStatefulSet(novaDeploymentName)
serviceDeployment := th.GetStatefulSet(serviceNameFunc())
g.Expect(serviceDeployment.Spec.Template.Spec.NodeSelector).To(Equal(newSelector))

g.Expect(th.GetJob(cell0.DBSyncJobName).Spec.Template.Spec.NodeSelector).To(Equal(newSelector))
g.Expect(th.GetJob(cell1.DBSyncJobName).Spec.Template.Spec.NodeSelector).To(Equal(newSelector))
g.Expect(th.GetJob(cell2.DBSyncJobName).Spec.Template.Spec.NodeSelector).To(Equal(newSelector))

}, timeout, interval).Should(Succeed())

// Now reset it back to empty and see that it is propagates too
Expand All @@ -353,10 +356,17 @@ var _ = Describe("Nova reconfiguration", func() {
g.Expect(k8sClient.Update(ctx, nova)).To(Succeed())

serviceDeploymentName := serviceNameFunc()
th.SimulateJobSuccess(cell0.DBSyncJobName)
th.SimulateJobSuccess(cell1.DBSyncJobName)
th.SimulateJobSuccess(cell2.DBSyncJobName)
th.SimulateStatefulSetReplicaReady(cell0.ConductorStatefulSetName)
th.SimulateStatefulSetReplicaReady(serviceDeploymentName)
serviceDeployment := th.GetStatefulSet(serviceDeploymentName)
g.Expect(serviceDeployment.Spec.Template.Spec.NodeSelector).To(BeNil())

g.Expect(th.GetJob(cell0.DBSyncJobName).Spec.Template.Spec.NodeSelector).To(BeNil())
g.Expect(th.GetJob(cell1.DBSyncJobName).Spec.Template.Spec.NodeSelector).To(BeNil())
g.Expect(th.GetJob(cell2.DBSyncJobName).Spec.Template.Spec.NodeSelector).To(BeNil())
}, timeout, interval).Should(Succeed())
},
Entry("the nova api pods",
Expand Down Expand Up @@ -403,8 +413,11 @@ var _ = Describe("Nova reconfiguration", func() {

}
g.Expect(k8sClient.Update(ctx, nova)).To(Succeed())
th.SimulateJobSuccess(cell0.DBSyncJobName)
th.SimulateStatefulSetReplicaReady(cell0.ConductorStatefulSetName)
th.SimulateJobSuccess(cell1.DBSyncJobName)
th.SimulateStatefulSetReplicaReady(cell1.ConductorStatefulSetName)
th.SimulateJobSuccess(cell2.DBSyncJobName)
th.SimulateStatefulSetReplicaReady(cell2.ConductorStatefulSetName)

apiDeployment := th.GetStatefulSet(novaNames.APIStatefulSetName)
Expand All @@ -420,6 +433,10 @@ var _ = Describe("Nova reconfiguration", func() {
g.Expect(conductorDeployment.Spec.Template.Spec.NodeSelector).To(Equal(conductorSelector))
conductorDeployment = th.GetStatefulSet(cell2.ConductorStatefulSetName)
g.Expect(conductorDeployment.Spec.Template.Spec.NodeSelector).To(BeNil())

g.Expect(th.GetJob(cell0.DBSyncJobName).Spec.Template.Spec.NodeSelector).To(Equal(conductorSelector))
g.Expect(th.GetJob(cell1.DBSyncJobName).Spec.Template.Spec.NodeSelector).To(Equal(conductorSelector))
g.Expect(th.GetJob(cell2.DBSyncJobName).Spec.Template.Spec.NodeSelector).To(BeNil())
}, timeout, interval).Should(Succeed())
SimulateReadyOfNovaTopServices()

Expand All @@ -446,6 +463,10 @@ var _ = Describe("Nova reconfiguration", func() {
g.Expect(conductorDeployment.Spec.Template.Spec.NodeSelector).To(Equal(conductorSelector))
conductorDeployment = th.GetStatefulSet(cell2.ConductorStatefulSetName)
g.Expect(conductorDeployment.Spec.Template.Spec.NodeSelector).To(BeNil())

g.Expect(th.GetJob(cell0.DBSyncJobName).Spec.Template.Spec.NodeSelector).To(Equal(conductorSelector))
g.Expect(th.GetJob(cell1.DBSyncJobName).Spec.Template.Spec.NodeSelector).To(Equal(conductorSelector))
g.Expect(th.GetJob(cell2.DBSyncJobName).Spec.Template.Spec.NodeSelector).To(BeNil())
}, timeout, interval).Should(Succeed())
})
})
Expand Down

0 comments on commit 1d55c7c

Please sign in to comment.