@@ -19,6 +19,7 @@ package controller
1919
2020import (
2121 "context"
22+ "fmt"
2223
2324 . "github.com/onsi/ginkgo/v2"
2425 . "github.com/onsi/gomega"
@@ -29,13 +30,17 @@ import (
2930 "sigs.k8s.io/controller-runtime/pkg/client"
3031
3132 kvmv1 "github.com/cobaltcore-dev/openstack-hypervisor-operator/api/v1"
33+ "github.com/jarcoal/httpmock"
3234)
3335
3436var _ = Describe ("Node Eviction Label Controller" , func () {
3537 var nodeReconciler * NodeEvictionLabelReconciler
3638
3739 Context ("When reconciling a node" , func () {
38- const nodeName = "node-test"
40+ const nodeName = "test-node"
41+ const hostName = "test-hostname"
42+ const region = "region"
43+ const zone = "zone"
3944 req := ctrl.Request {
4045 NamespacedName : types.NamespacedName {Name : nodeName },
4146 }
@@ -53,6 +58,7 @@ var _ = Describe("Node Eviction Label Controller", func() {
5358 }
5459
5560 BeforeEach (func () {
61+ httpmock .Activate ()
5662 nodeReconciler = & NodeEvictionLabelReconciler {
5763 Client : k8sClient ,
5864 Scheme : k8sClient .Scheme (),
@@ -67,9 +73,11 @@ var _ = Describe("Node Eviction Label Controller", func() {
6773 ObjectMeta : metav1.ObjectMeta {
6874 Name : nodeName ,
6975 Labels : map [string ]string {
70- corev1 .LabelHostname : "test" ,
71- labelEvictionRequired : "true" ,
72- labelOnboardingState : "completed" },
76+ corev1 .LabelHostname : hostName ,
77+ corev1 .LabelTopologyRegion : region ,
78+ corev1 .LabelTopologyZone : zone ,
79+ labelEvictionRequired : "true" ,
80+ labelOnboardingState : "completed" },
7381 },
7482 }
7583 Expect (k8sClient .Create (ctx , resource )).To (Succeed ())
@@ -79,16 +87,20 @@ var _ = Describe("Node Eviction Label Controller", func() {
7987 node := & corev1.Node {ObjectMeta : metav1.ObjectMeta {Name : nodeName }}
8088 By ("Cleanup the specific node" )
8189 Expect (client .IgnoreNotFound (k8sClient .Delete (ctx , node ))).To (Succeed ())
90+ httpmock .DeactivateAndReset ()
8291 })
8392
8493 It ("should successfully reconcile the resource" , func () {
94+ url := InstanceHaUrl (region , zone , hostName )
95+ httpmock .RegisterResponder ("POST" , url , httpmock .NewStringResponder (200 , `` ))
96+
8597 By ("Reconciling the created resource" )
8698 _ , err := reconcileNodeLoop (5 )
8799 Expect (err ).NotTo (HaveOccurred ())
88100
89101 // expect node controller to create an eviction for the node
90102 err = k8sClient .Get (ctx , types.NamespacedName {
91- Name : "maintenance-required-test" ,
103+ Name : fmt . Sprintf ( "maintenance-required-%v" , hostName ) ,
92104 Namespace : "monsoon3" ,
93105 }, & kvmv1.Eviction {})
94106 Expect (err ).NotTo (HaveOccurred ())
0 commit comments