Skip to content

Commit

Permalink
Merge pull request #483 from wizhaoredhat/fix_node_selector
Browse files Browse the repository at this point in the history
Fix Config Daemon node selector
  • Loading branch information
Eoghan Russell authored Oct 12, 2023
2 parents 314f246 + 5c1b0af commit d73d7ad
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
24 changes: 23 additions & 1 deletion controllers/sriovoperatorconfig_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ var _ = Describe("Operator", func() {
Expect(err).NotTo(HaveOccurred())
})

PIt("should be able to update the node selector of sriov-network-config-daemon", func() {
It("should be able to update the node selector of sriov-network-config-daemon", func() {
By("specify the configDaemonNodeSelector")
config := &sriovnetworkv1.SriovOperatorConfig{}
err := util.WaitForNamespacedObject(config, k8sClient, testNamespace, "default", interval, timeout)
Expand All @@ -171,5 +171,27 @@ var _ = Describe("Operator", func() {
}, timeout*10, interval).Should(Equal(config.Spec.ConfigDaemonNodeSelector))
})

It("should be able to do multiple updates to the node selector of sriov-network-config-daemon", func() {
By("changing the configDaemonNodeSelector")
config := &sriovnetworkv1.SriovOperatorConfig{}
err := util.WaitForNamespacedObject(config, k8sClient, testNamespace, "default", interval, timeout)
Expect(err).NotTo(HaveOccurred())
config.Spec.ConfigDaemonNodeSelector = map[string]string{"labelA": "", "labelB": "", "labelC": ""}
err = k8sClient.Update(goctx.TODO(), config)
Expect(err).NotTo(HaveOccurred())
config.Spec.ConfigDaemonNodeSelector = map[string]string{"labelA": "", "labelB": ""}
err = k8sClient.Update(goctx.TODO(), config)
Expect(err).NotTo(HaveOccurred())

daemonSet := &appsv1.DaemonSet{}
Eventually(func() map[string]string {
err := k8sClient.Get(goctx.TODO(), types.NamespacedName{Name: "sriov-network-config-daemon", Namespace: testNamespace}, daemonSet)
if err != nil {
return nil
}
return daemonSet.Spec.Template.Spec.NodeSelector
}, timeout*10, interval).Should(Equal(config.Spec.ConfigDaemonNodeSelector))
})

})
})
4 changes: 2 additions & 2 deletions pkg/apply/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ func ApplyObject(ctx context.Context, client k8sclient.Client, obj *uns.Unstruct
if err := MergeObjectForUpdate(existing, obj); err != nil {
return errors.Wrapf(err, "could not merge object %s with existing", objDesc)
}
if !equality.Semantic.DeepDerivative(obj, existing) {
if !equality.Semantic.DeepEqual(existing, obj) {
if err := client.Update(ctx, obj); err != nil {
return errors.Wrapf(err, "could not update object %s", objDesc)
} else {
log.Printf("update was successful")
log.Printf("update was successful %s", objDesc)
}
}

Expand Down

0 comments on commit d73d7ad

Please sign in to comment.