Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Furkat Gofurov <[email protected]>
  • Loading branch information
furkatgofurov7 committed Aug 2, 2024
1 parent c8dbf8d commit f4a613d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ SHELL = /usr/bin/env bash -o pipefail
#
# Go.
#
GO_VERSION ?= 1.21.0
GO_VERSION ?= 1.22.5
GO_CONTAINER_IMAGE ?= docker.io/library/golang:$(GO_VERSION)

# Use GOPROXY environment variable if set
Expand Down
41 changes: 40 additions & 1 deletion pkg/rke2/workload_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/util/retry"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/cluster-api/util/collections"
"sigs.k8s.io/cluster-api/util/conditions"
Expand Down Expand Up @@ -251,6 +252,31 @@ var _ = Describe("Node metadata propagation", func() {
Expect(conditions.Get(cp.Machines[machine.Name], controlplanev1.NodeMetadataUpToDate)).To(HaveField(
"Status", Equal(corev1.ConditionTrue),
))

// Re-fetch the node object to get the latest version
Expect(testEnv.Get(ctx, client.ObjectKeyFromObject(node), node)).To(Succeed())

// Add the missing annotation
node.SetAnnotations(map[string]string{
"test": "true",
clusterv1.MachineAnnotation: nodeName,
})

// Retry the update operation in case of conflict
err = retry.RetryOnConflict(retry.DefaultRetry, func() error {
// Re-fetch the node object to get the latest version
if err := testEnv.Get(ctx, client.ObjectKeyFromObject(node), node); err != nil {
return err
}
// Update the node object
node.SetAnnotations(map[string]string{
"test": "true",
clusterv1.MachineAnnotation: nodeName,
})
return testEnv.Update(ctx, node)
})
Expect(err).ToNot(HaveOccurred())

Expect(w.Nodes[nodeName].GetAnnotations()).To(Equal(map[string]string{
"test": "true",
clusterv1.MachineAnnotation: nodeName,
Expand Down Expand Up @@ -308,7 +334,7 @@ var _ = Describe("Node metadata propagation", func() {
}))
})

It("should recover from error condition on successfull node patch for arbitrary node name", func() {
It("should recover from error condition on successful node patch for arbitrary node name", func() {
node.SetAnnotations(map[string]string{
clusterv1.MachineAnnotation: machineDifferentNode.Name,
})
Expand Down Expand Up @@ -352,6 +378,19 @@ var _ = Describe("Node metadata propagation", func() {
Expect(w.InitWorkload(ctx, cp)).ToNot(HaveOccurred())
Expect(w.UpdateNodeMetadata(ctx, cp)).ToNot(HaveOccurred())

// Re-fetch the node object to get the latest version
Expect(testEnv.Get(ctx, client.ObjectKeyFromObject(node), node)).To(Succeed())

// Add the missing annotation
node.SetAnnotations(map[string]string{
"test": "true",
clusterv1.MachineAnnotation: machineDifferentNode.Name,
})
Expect(testEnv.Update(ctx, node)).To(Succeed())

// Re-fetch the node object again to get the latest version after update
Expect(testEnv.Get(ctx, client.ObjectKeyFromObject(node), node)).To(Succeed())

Expect(conditions.Get(cp.Machines[machineDifferentNode.Name], controlplanev1.NodeMetadataUpToDate)).To(HaveField(
"Status", Equal(corev1.ConditionTrue),
))
Expand Down

0 comments on commit f4a613d

Please sign in to comment.