@@ -189,10 +189,15 @@ func boolToConditionStatus(b bool) corev1.ConditionStatus {
189
189
return corev1 .ConditionFalse
190
190
}
191
191
192
- func newAgentWithProperties (name , namespace string , approved , bound , validated bool , labels map [string ]string ) * aiv1beta1.Agent {
192
+ func newValidAgent (name , namespace string , labels map [string ]string ) * aiv1beta1.Agent {
193
+ return newAgentWithProperties (name , namespace , true , false , true , true , labels )
194
+ }
195
+
196
+ func newAgentWithProperties (name , namespace string , approved , bound , validated , connected bool , labels map [string ]string ) * aiv1beta1.Agent {
193
197
agent := newAgent (name , namespace , aiv1beta1.AgentSpec {Approved : approved })
194
198
agent .Status .Conditions = append (agent .Status .Conditions , v1.Condition {Type : aiv1beta1 .BoundCondition , Status : boolToConditionStatus (bound )})
195
199
agent .Status .Conditions = append (agent .Status .Conditions , v1.Condition {Type : aiv1beta1 .ValidatedCondition , Status : boolToConditionStatus (validated )})
200
+ agent .Status .Conditions = append (agent .Status .Conditions , v1.Condition {Type : aiv1beta1 .ConnectedCondition , Status : boolToConditionStatus (connected )})
196
201
agent .Status .Conditions = append (agent .Status .Conditions , v1.Condition {Type : aiv1beta1 .SpecSyncedCondition , Status : boolToConditionStatus (true )})
197
202
agent .Status .Conditions = append (agent .Status .Conditions , v1.Condition {Type : aiv1beta1 .RequirementsMetCondition , Status : boolToConditionStatus (validated )})
198
203
agent .Status .Conditions = append (agent .Status .Conditions , v1.Condition {Type : aiv1beta1 .InstalledCondition , Status : boolToConditionStatus (false ), Reason : aiv1beta1 .InstallationNotStartedMsg , Message : "" })
@@ -313,16 +318,17 @@ var _ = Describe("agentmachine reconcile", func() {
313
318
badLabels4 := map [string ]string {"location" : "datacenter2" }
314
319
badLabels5 := map [string ]string {"hasGpu" : "true" }
315
320
316
- Expect (c .Create (ctx , newAgentWithProperties ("agent-0" , testNamespace , false , false , true , goodLabels ))).To (BeNil ()) // Agent0: not approved
317
- Expect (c .Create (ctx , newAgentWithProperties ("agent-1" , testNamespace , true , true , true , goodLabels ))).To (BeNil ()) // Agent1: already bound
318
- Expect (c .Create (ctx , newAgentWithProperties ("agent-2" , testNamespace , true , true , true , badLabels1 ))).To (BeNil ()) // Agent2: bad labels
319
- Expect (c .Create (ctx , newAgentWithProperties ("agent-3" , testNamespace , true , true , false , goodLabels ))).To (BeNil ()) // Agent3: validations are failing
320
- Expect (c .Create (ctx , newAgentWithProperties ("agent-4" , testNamespace , true , false , true , badLabels2 ))).To (BeNil ()) // Agent4: bad labels
321
- Expect (c .Create (ctx , newAgentWithProperties ("agent-5" , testNamespace , true , false , true , badLabels3 ))).To (BeNil ()) // Agent5: bad labels
322
- Expect (c .Create (ctx , newAgentWithProperties ("agent-6" , testNamespace , true , false , true , badLabels4 ))).To (BeNil ()) // Agent6: bad labels
323
- Expect (c .Create (ctx , newAgentWithProperties ("agent-7" , testNamespace , true , false , true , badLabels5 ))).To (BeNil ()) // Agent7: bad labels
324
- Expect (c .Create (ctx , newAgentWithProperties ("agent-8" , testNamespace , true , false , true , otherAgentMachineLabel ))).To (BeNil ()) // Agent8: should be skipped
325
- Expect (c .Create (ctx , newAgentWithProperties ("agent-9" , testNamespace , true , false , true , goodLabels ))).To (BeNil ()) // Agent9: the chosen one
321
+ Expect (c .Create (ctx , newAgentWithProperties ("agent-0" , testNamespace , false , false , true , true , goodLabels ))).To (BeNil ()) // Agent0: not approved
322
+ Expect (c .Create (ctx , newAgentWithProperties ("agent-1" , testNamespace , true , true , true , true , goodLabels ))).To (BeNil ()) // Agent1: already bound
323
+ Expect (c .Create (ctx , newAgentWithProperties ("agent-2" , testNamespace , true , true , true , true , badLabels1 ))).To (BeNil ()) // Agent2: bad labels
324
+ Expect (c .Create (ctx , newAgentWithProperties ("agent-3" , testNamespace , true , true , false , true , goodLabels ))).To (BeNil ()) // Agent3: validations are failing
325
+ Expect (c .Create (ctx , newAgentWithProperties ("agent-4" , testNamespace , true , false , true , true , badLabels2 ))).To (BeNil ()) // Agent4: bad labels
326
+ Expect (c .Create (ctx , newAgentWithProperties ("agent-5" , testNamespace , true , false , true , true , badLabels3 ))).To (BeNil ()) // Agent5: bad labels
327
+ Expect (c .Create (ctx , newAgentWithProperties ("agent-6" , testNamespace , true , false , true , true , badLabels4 ))).To (BeNil ()) // Agent6: bad labels
328
+ Expect (c .Create (ctx , newAgentWithProperties ("agent-7" , testNamespace , true , false , true , true , badLabels5 ))).To (BeNil ()) // Agent7: bad labels
329
+ Expect (c .Create (ctx , newAgentWithProperties ("agent-8" , testNamespace , true , false , true , true , otherAgentMachineLabel ))).To (BeNil ()) // Agent8: should be skipped
330
+ Expect (c .Create (ctx , newAgentWithProperties ("agent-9" , testNamespace , true , false , true , false , goodLabels ))).To (BeNil ()) // Agent9: disconnected
331
+ Expect (c .Create (ctx , newValidAgent ("agent-10" , testNamespace , goodLabels ))).To (BeNil ()) // Agent10: the chosen one
326
332
327
333
// find agent
328
334
result , err := amr .Reconcile (ctx , agentMachineRequest )
@@ -338,7 +344,7 @@ var _ = Describe("agentmachine reconcile", func() {
338
344
Expect (conditions .Get (agentMachine , capiproviderv1 .InstalledCondition ).Severity ).To (BeEquivalentTo (clusterv1 .ConditionSeverityInfo ))
339
345
Expect (conditions .Get (agentMachine , clusterv1 .ReadyCondition ).Status ).To (BeEquivalentTo ("False" ))
340
346
341
- Expect (agentMachine .Status .AgentRef .Name ).To (BeEquivalentTo ("agent-9 " ))
347
+ Expect (agentMachine .Status .AgentRef .Name ).To (BeEquivalentTo ("agent-10 " ))
342
348
Expect (len (agentMachine .Status .Addresses )).To (BeEquivalentTo (4 ))
343
349
expectedAddresses := []string {"1.2.3.4" , "2.3.4.5" , "3.4.5.6" , "agent-hostname" }
344
350
expectedTypes := []string {string (clusterv1 .MachineExternalIP ), string (clusterv1 .MachineInternalDNS )}
@@ -348,7 +354,7 @@ var _ = Describe("agentmachine reconcile", func() {
348
354
}
349
355
350
356
agent := & aiv1beta1.Agent {}
351
- Expect (c .Get (ctx , types.NamespacedName {Namespace : testNamespace , Name : "agent-9 " }, agent )).To (BeNil ())
357
+ Expect (c .Get (ctx , types.NamespacedName {Namespace : testNamespace , Name : "agent-10 " }, agent )).To (BeNil ())
352
358
Expect (agent .Spec .ClusterDeploymentName .Name ).To (BeEquivalentTo ("cluster-deployment-agentMachine" ))
353
359
Expect (agent .Spec .IgnitionEndpointTokenReference .Name ).To (BeEquivalentTo ("agent-userdata-secret-agentMachine" ))
354
360
Expect (agent .Spec .IgnitionEndpointTokenReference .Namespace ).To (BeEquivalentTo (testNamespace ))
@@ -364,7 +370,7 @@ var _ = Describe("agentmachine reconcile", func() {
364
370
Expect (c .Create (ctx , agentMachine )).To (BeNil ())
365
371
agentMachineRequest := newAgentMachineRequest (agentMachine )
366
372
367
- Expect (c .Create (ctx , newAgentWithProperties ("agent" , testNamespace , true , false , true , map [string ]string {}))).To (BeNil ())
373
+ Expect (c .Create (ctx , newAgentWithProperties ("agent" , testNamespace , true , false , true , true , map [string ]string {}))).To (BeNil ())
368
374
369
375
originalAgent := & aiv1beta1.Agent {}
370
376
Expect (c .Get (ctx , types.NamespacedName {Namespace : testNamespace , Name : "agent" }, originalAgent )).To (BeNil ())
@@ -405,7 +411,7 @@ var _ = Describe("agentmachine reconcile", func() {
405
411
Expect (c .Create (ctx , agentMachine )).To (BeNil ())
406
412
agentMachineRequest := newAgentMachineRequest (agentMachine )
407
413
408
- agent := newAgentWithProperties ("agent-1" , testNamespace , false , false , true , map [string ]string {})
414
+ agent := newAgentWithProperties ("agent-1" , testNamespace , false , false , true , true , map [string ]string {})
409
415
Expect (c .Create (ctx , agent )).To (BeNil ())
410
416
411
417
clusterDepRef := capiproviderv1.ClusterDeploymentReference {Namespace : testNamespace , Name : "my-cd" }
@@ -856,9 +862,7 @@ var _ = Describe("mapAgentToAgentMachine", func() {
856
862
})
857
863
858
864
It ("returns nothing if the agent isn't valid" , func () {
859
- agent := newAgent ("agent" , testNamespace , aiv1beta1.AgentSpec {Approved : true })
860
- agent .Status .Conditions = append (agent .Status .Conditions , v1.Condition {Type : aiv1beta1 .BoundCondition , Status : boolToConditionStatus (false )})
861
- agent .Status .Conditions = append (agent .Status .Conditions , v1.Condition {Type : aiv1beta1 .ValidatedCondition , Status : boolToConditionStatus (false )})
865
+ agent := newAgentWithProperties ("agent" , testNamespace , true , false , false , true , map [string ]string {})
862
866
Expect (c .Create (ctx , agent )).To (BeNil ())
863
867
agentMachine1 , _ := newAgentMachine ("agentMachine-1" , testNamespace , capiproviderv1.AgentMachineSpec {}, ctx , c )
864
868
Expect (c .Create (ctx , agentMachine1 )).To (Succeed ())
@@ -870,9 +874,7 @@ var _ = Describe("mapAgentToAgentMachine", func() {
870
874
})
871
875
872
876
It ("returns unmatched agent machines if no match is found" , func () {
873
- agent := newAgent ("agent" , testNamespace , aiv1beta1.AgentSpec {Approved : true })
874
- agent .Status .Conditions = append (agent .Status .Conditions , v1.Condition {Type : aiv1beta1 .BoundCondition , Status : boolToConditionStatus (false )})
875
- agent .Status .Conditions = append (agent .Status .Conditions , v1.Condition {Type : aiv1beta1 .ValidatedCondition , Status : boolToConditionStatus (true )})
877
+ agent := newValidAgent ("agent" , testNamespace , map [string ]string {})
876
878
Expect (c .Create (ctx , agent )).To (BeNil ())
877
879
agentMachine1 , _ := newAgentMachine ("agentMachine-1" , testNamespace , capiproviderv1.AgentMachineSpec {}, ctx , c )
878
880
Expect (c .Create (ctx , agentMachine1 )).To (Succeed ())
0 commit comments