Skip to content

Commit

Permalink
tests, infra: Use patch instead of update
Browse files Browse the repository at this point in the history
Signed-off-by: Edward Haas <[email protected]>
  • Loading branch information
EdDev committed Jul 31, 2022
1 parent 362bd79 commit 06af383
Showing 1 changed file with 23 additions and 30 deletions.
53 changes: 23 additions & 30 deletions tests/infra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import (
"kubevirt.io/client-go/kubecli"

clusterutil "kubevirt.io/kubevirt/pkg/util/cluster"
k6ttypes "kubevirt.io/kubevirt/pkg/util/types"
"kubevirt.io/kubevirt/pkg/virt-controller/leaderelectionconfig"
nodelabellerutil "kubevirt.io/kubevirt/pkg/virt-handler/node-labeller/util"
"kubevirt.io/kubevirt/pkg/virt-operator/resource/generate/components"
Expand Down Expand Up @@ -394,24 +395,19 @@ var _ = Describe("[Serial][sig-compute]Infrastructure", func() {
AfterEach(func() {
if selectedNodeName != "" {
By("removing the taint from the tainted node")
err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
selectedNode, err := virtClient.CoreV1().Nodes().Get(context.Background(), selectedNodeName, metav1.GetOptions{})
if err != nil {
return err
}
selectedNode, err := virtClient.CoreV1().Nodes().Get(context.Background(), selectedNodeName, metav1.GetOptions{})
Expect(err).NotTo(HaveOccurred())

var taints []k8sv1.Taint
for _, taint := range selectedNode.Spec.Taints {
if taint.Key != "CriticalAddonsOnly" {
taints = append(taints, taint)
}
var taints []k8sv1.Taint
for _, taint := range selectedNode.Spec.Taints {
if taint.Key != "CriticalAddonsOnly" {
taints = append(taints, taint)
}
selectedNode.Spec.Taints = taints

_, err = virtClient.CoreV1().Nodes().Update(context.Background(), selectedNode, metav1.UpdateOptions{})
return err
})
Expect(err).ShouldNot(HaveOccurred())
}
patchData, err := k6ttypes.GenerateTestReplacePatch("/spec/taints", selectedNode.Spec.Taints, taints)
Expect(err).NotTo(HaveOccurred())
selectedNode, err = virtClient.CoreV1().Nodes().Patch(context.Background(), selectedNode.Name, types.JSONPatchType, patchData, metav1.PatchOptions{})
Expect(err).NotTo(HaveOccurred())
}
})

Expand Down Expand Up @@ -487,22 +483,19 @@ var _ = Describe("[Serial][sig-compute]Infrastructure", func() {
go signalTerminatedPods(stopCn, lw.ResultChan(), terminatedPodsCn)

By("tainting the selected node")
err = retry.RetryOnConflict(retry.DefaultRetry, func() error {
selectedNode, err := virtClient.CoreV1().Nodes().Get(context.Background(), selectedNodeName, metav1.GetOptions{})
if err != nil {
return err
}

selectedNode.Spec.Taints = append(selectedNode.Spec.Taints, k8sv1.Taint{
Key: "CriticalAddonsOnly",
Value: "",
Effect: k8sv1.TaintEffectNoExecute,
})
selectedNode, err := virtClient.CoreV1().Nodes().Get(context.Background(), selectedNodeName, metav1.GetOptions{})
Expect(err).NotTo(HaveOccurred())

_, err = virtClient.CoreV1().Nodes().Update(context.Background(), selectedNode, metav1.UpdateOptions{})
return err
taints := append(selectedNode.Spec.Taints, k8sv1.Taint{
Key: "CriticalAddonsOnly",
Value: "",
Effect: k8sv1.TaintEffectNoExecute,
})
Expect(err).ShouldNot(HaveOccurred())

patchData, err := k6ttypes.GenerateTestReplacePatch("/spec/taints", selectedNode.Spec.Taints, taints)
Expect(err).ToNot(HaveOccurred())
selectedNode, err = virtClient.CoreV1().Nodes().Patch(context.Background(), selectedNode.Name, types.JSONPatchType, patchData, metav1.PatchOptions{})
Expect(err).ToNot(HaveOccurred())

Consistently(terminatedPodsCn, 5*time.Second).ShouldNot(Receive(), "pods should not terminate")
stopCn <- true
Expand Down

0 comments on commit 06af383

Please sign in to comment.