Skip to content

Commit

Permalink
Merge pull request #388 from olliewalsh/node_selectors
Browse files Browse the repository at this point in the history
Ensure nodeSelector logic is consistent for all operators
  • Loading branch information
openshift-merge-bot[bot] authored Nov 19, 2024
2 parents 66396cc + f7b4465 commit c38568c
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 6 deletions.
2 changes: 1 addition & 1 deletion api/v1beta1/horizon_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type HorizonSpec struct {
type HorizonSpecCore struct {
// +kubebuilder:validation:Optional
// NodeSelector to target subset of worker nodes running this service
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
NodeSelector *map[string]string `json:"nodeSelector,omitempty"`

// +kubebuilder:validation:Optional
// ConfigOverwrite - interface to overwrite default config files like e.g. logging.conf or policy.json.
Expand Down
10 changes: 7 additions & 3 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pkg/horizon/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ func Deployment(
},
corev1.LabelHostname,
)
if instance.Spec.NodeSelector != nil && len(instance.Spec.NodeSelector) > 0 {
deployment.Spec.Template.Spec.NodeSelector = instance.Spec.NodeSelector
if instance.Spec.NodeSelector != nil {
deployment.Spec.Template.Spec.NodeSelector = *instance.Spec.NodeSelector
}

return deployment, nil
Expand Down
82 changes: 82 additions & 0 deletions tests/functional/horizon_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,88 @@ var _ = Describe("Horizon controller", func() {
})
})

When("nodeSelector is set", func() {
BeforeEach(func() {
spec := GetDefaultHorizonSpec()
spec["nodeSelector"] = map[string]interface{}{
"foo": "bar",
}
DeferCleanup(th.DeleteInstance, CreateHorizon(horizonName, spec))
DeferCleanup(
k8sClient.Delete, ctx, CreateHorizonSecret(namespace, SecretName))
DeferCleanup(infra.DeleteMemcached, infra.CreateMemcached(namespace, "memcached", memcachedSpec))
infra.SimulateMemcachedReady(types.NamespacedName{
Name: "memcached",
Namespace: namespace,
})
keystoneAPI := keystone.CreateKeystoneAPI(namespace)
DeferCleanup(keystone.DeleteKeystoneAPI, keystoneAPI)
th.SimulateDeploymentReplicaReady(deploymentName)
})

It("sets nodeSelector in resource specs", func() {
Eventually(func(g Gomega) {
g.Expect(th.GetDeployment(deploymentName).Spec.Template.Spec.NodeSelector).To(Equal(map[string]string{"foo": "bar"}))
}, timeout, interval).Should(Succeed())
})

It("updates nodeSelector in resource specs when changed", func() {
Eventually(func(g Gomega) {
g.Expect(th.GetDeployment(deploymentName).Spec.Template.Spec.NodeSelector).To(Equal(map[string]string{"foo": "bar"}))
}, timeout, interval).Should(Succeed())

Eventually(func(g Gomega) {
horizon := GetHorizon(horizonName)
newNodeSelector := map[string]string{
"foo2": "bar2",
}
horizon.Spec.NodeSelector = &newNodeSelector
g.Expect(k8sClient.Update(ctx, horizon)).Should(Succeed())
}, timeout, interval).Should(Succeed())

Eventually(func(g Gomega) {
th.SimulateDeploymentReplicaReady(deploymentName)
g.Expect(th.GetDeployment(deploymentName).Spec.Template.Spec.NodeSelector).To(Equal(map[string]string{"foo2": "bar2"}))
}, timeout, interval).Should(Succeed())
})

It("removes nodeSelector from resource specs when cleared", func() {
Eventually(func(g Gomega) {
g.Expect(th.GetDeployment(deploymentName).Spec.Template.Spec.NodeSelector).To(Equal(map[string]string{"foo": "bar"}))
}, timeout, interval).Should(Succeed())

Eventually(func(g Gomega) {
horizon := GetHorizon(horizonName)
emptyNodeSelector := map[string]string{}
horizon.Spec.NodeSelector = &emptyNodeSelector
g.Expect(k8sClient.Update(ctx, horizon)).Should(Succeed())
}, timeout, interval).Should(Succeed())

Eventually(func(g Gomega) {
th.SimulateDeploymentReplicaReady(deploymentName)
g.Expect(th.GetDeployment(deploymentName).Spec.Template.Spec.NodeSelector).To(BeNil())
}, timeout, interval).Should(Succeed())
})

It("removes nodeSelector from resource specs when nilled", func() {
Eventually(func(g Gomega) {
g.Expect(th.GetDeployment(deploymentName).Spec.Template.Spec.NodeSelector).To(Equal(map[string]string{"foo": "bar"}))
}, timeout, interval).Should(Succeed())

Eventually(func(g Gomega) {
horizon := GetHorizon(horizonName)
horizon.Spec.NodeSelector = nil
g.Expect(k8sClient.Update(ctx, horizon)).Should(Succeed())
}, timeout, interval).Should(Succeed())

Eventually(func(g Gomega) {
th.SimulateDeploymentReplicaReady(deploymentName)
g.Expect(th.GetDeployment(deploymentName).Spec.Template.Spec.NodeSelector).To(BeNil())
}, timeout, interval).Should(Succeed())
})

})

When("TLS is enabled", func() {
BeforeEach(func() {
DeferCleanup(th.DeleteInstance, CreateHorizon(horizonName, GetTLSHorizonSpec()))
Expand Down

0 comments on commit c38568c

Please sign in to comment.