@@ -2,6 +2,7 @@ package controllers
22
33import (
44 "context"
5+ "fmt"
56 "testing"
67 "time"
78
@@ -31,6 +32,7 @@ import (
3132 "sigs.k8s.io/cluster-api-provider-aws/v2/test/mocks"
3233 clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
3334 expclusterv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1"
35+ "sigs.k8s.io/cluster-api/util/patch"
3436)
3537
3638func TestNodePoolToRosaMachinePoolSpec (t * testing.T ) {
@@ -104,6 +106,7 @@ func TestRosaMachinePoolReconcile(t *testing.T) {
104106 recorder = record .NewFakeRecorder (10 )
105107 ctx = context .TODO ()
106108 scheme = runtime .NewScheme ()
109+ // scheme = testEnv.Scheme()
107110 ns , err = testEnv .CreateNamespace (ctx , "test-namespace" )
108111 g .Expect (err ).To (BeNil ())
109112
@@ -174,12 +177,18 @@ func TestRosaMachinePoolReconcile(t *testing.T) {
174177 ObjectMeta : metav1.ObjectMeta {
175178 Name : "rosa-machinepool" ,
176179 Namespace : ns .Name ,
180+ UID : "rosa-machinepool-1" ,
177181 },
178182 TypeMeta : metav1.TypeMeta {
179183 Kind : "ROSAMachinePool" ,
180184 APIVersion : expinfrav1 .GroupVersion .String (),
181185 },
182- Spec : expinfrav1.RosaMachinePoolSpec {},
186+ Spec : expinfrav1.RosaMachinePoolSpec {
187+ NodePoolName : "test-nodepool" ,
188+ Version : "4.14.5" ,
189+ Subnet : "subnet-id" ,
190+ InstanceType : "m5.large" ,
191+ },
183192 }
184193
185194 ownerMachinePool = & expclusterv1.MachinePool {
@@ -220,7 +229,7 @@ func TestRosaMachinePoolReconcile(t *testing.T) {
220229 },
221230 }
222231
223- objects = []client.Object {secret , ownerCluster , ownerMachinePool }
232+ objects = []client.Object {secret , ownerCluster , ownerMachinePool , rosaMachinePool }
224233
225234 for _ , obj := range objects {
226235 createObject (g , obj , ns .Name )
@@ -235,6 +244,7 @@ func TestRosaMachinePoolReconcile(t *testing.T) {
235244 }
236245
237246 t .Run ("Reconcile create node pool" , func (t * testing.T ) {
247+ fmt .Println ("START test" )
238248 setup (t )
239249 defer teardown ()
240250 ocmMock = mocks .NewMockOCMClient (mockCtrl )
@@ -243,12 +253,40 @@ func TestRosaMachinePoolReconcile(t *testing.T) {
243253 return nil , false , nil
244254 }).Times (1 )
245255 m .CreateNodePool (gomock .Any (), gomock .Any ()).DoAndReturn (func (clusterId string , nodePool * cmv1.NodePool ) (* cmv1.NodePool , error ) {
256+ fmt .Println ("NODE POOL" , nodePool .ID ())
246257 return nodePool , nil
247258 }).Times (1 )
248259 }
249260 expect (ocmMock .EXPECT ())
250261
262+ fmt .Println ("REC" , scheme .Recognizes (rosaMachinePool .GroupVersionKind ()))
263+ fmt .Println ("REC" , scheme .Recognizes (ownerCluster .GroupVersionKind ()))
264+
251265 c := fake .NewClientBuilder ().WithScheme (scheme ).WithObjects (rosaMachinePool , ownerCluster , ownerMachinePool , rosaControlPlane , secret ).Build ()
266+
267+ // failureMessage := "fail blabla"
268+ // rosaMachinePool.Status.FailureMessage = &failureMessage
269+
270+ // err = c.Status().Patch(ctx, rosaMachinePool, client.MergeFrom(rosaMachinePool))
271+ // err = c.Status().Patch(ctx, ownerMachinePool, client.MergeFrom(ownerMachinePool))
272+ g .Expect (err ).NotTo (HaveOccurred ())
273+ mpPh , err := patch .NewHelper (rosaMachinePool , testEnv )
274+
275+ rosaMachinePool .Status .Ready = true
276+ l := map [string ]string {"key" : "value" }
277+ rosaMachinePool .SetLabels (l )
278+
279+ err = mpPh .Patch (ctx , rosaMachinePool , patch.WithOwnedConditions {Conditions : []clusterv1.ConditionType {
280+ expinfrav1 .RosaMachinePoolReadyCondition ,
281+ }})
282+
283+ m := & expinfrav1.ROSAMachinePool {}
284+ key := client.ObjectKey {Name : rosaMachinePool .Name , Namespace : ns .Name }
285+ c .Get (ctx , key , m )
286+ fmt .Println ("ROSAMACHINEPOOL:" , m .Name , m .Status , m .Namespace , m .Labels )
287+
288+ g .Expect (err ).NotTo (HaveOccurred ())
289+
252290 stsMock := mock_stsiface .NewMockSTSAPI (mockCtrl )
253291 stsMock .EXPECT ().GetCallerIdentity (gomock .Any ()).Times (1 )
254292
@@ -266,10 +304,15 @@ func TestRosaMachinePoolReconcile(t *testing.T) {
266304 req := ctrl.Request {}
267305 req .NamespacedName = types.NamespacedName {Name : "rosa-machinepool" , Namespace : ns .Name }
268306
269- result , err := r .Reconcile (ctx , req )
307+ g .Expect (r .Endpoints ).To (Equal ("a" ))
308+ // result, err := r.Reconcile(ctx, req)
309+ // key := client.ObjectKey{Name: ownerMachinePool.Name, Namespace: ns.Name}
310+
311+ g .Expect (m .Status ).To (Equal (map [string ]string {"cluster.x-k8s.io/replicas-managed-by" : "rosa" }))
270312
271313 g .Expect (err ).ToNot (HaveOccurred ())
272- g .Expect (result ).To (Equal (ctrl.Result {}))
314+
315+ // g.Expect(result).To(Equal(ctrl.Result{}))
273316 })
274317
275318 // t.Run("Reconcile delete", func(t *testing.T) {
0 commit comments