-
Notifications
You must be signed in to change notification settings - Fork 217
/
statemachine.go
1289 lines (1211 loc) · 61.7 KB
/
statemachine.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package host
import (
"fmt"
"github.com/filanov/stateswitch"
"github.com/openshift/assisted-service/models"
)
// See documentTransitionTypes for documentation of each transition type
const (
TransitionTypeRegisterHost = "RegisterHost"
TransitionTypeHostInstallationFailed = "HostInstallationFailed"
TransitionTypeCancelInstallation = "CancelInstallation"
TransitionTypeInstallHost = "InstallHost"
TransitionTypeResettingPendingUserAction = "ResettingPendingUserAction"
TransitionTypeRefresh = "RefreshHost"
TransitionTypeHostProgress = "HostProgressChanged"
TransitionTypeMediaDisconnect = "MediaDisconnect"
TransitionTypeBindHost = "BindHost"
TransitionTypeUnbindHost = "UnbindHost"
TransitionTypeReclaimHost = "ReclaimHost"
TransitionTypeRebootingForReclaim = "RebootingForReclaim"
TransitionTypeReclaimFailed = "ReclaimHostFailed"
)
// func NewHostStateMachine(th *transitionHandler) stateswitch.StateMachine {
func NewHostStateMachine(sm stateswitch.StateMachine, th TransitionHandler) stateswitch.StateMachine {
documentStates(sm)
documentTransitionTypes(sm)
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeRegisterHost,
SourceStates: []stateswitch.State{
"",
},
Condition: stateswitch.Not(th.IsUnboundHost),
DestinationState: stateswitch.State(models.HostStatusDiscovering),
PostTransition: th.PostRegisterHost,
Documentation: stateswitch.TransitionRuleDoc{
Name: "Initial registration",
Description: "When new host is first registered. This transition is not executed on unbound hosts because <unknown, TODO>",
},
})
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeHostProgress,
Condition: stateswitch.And(th.IsHostInReboot, th.IsDay2Host),
SourceStates: []stateswitch.State{
stateswitch.State(models.HostStatusInstallingInProgress),
stateswitch.State(models.HostStatusInstalling),
},
DestinationState: stateswitch.State(models.HostStatusInstallingInProgress),
PostTransition: th.PostHostProgress,
Documentation: stateswitch.TransitionRuleDoc{
Name: "host progress installing-in-progress on rebooting in kube-api mode",
Description: "This state is called only from kube-api controllers. ",
},
})
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeHostProgress,
Condition: stateswitch.And(th.IsHostInDone, th.IsDay2Host),
SourceStates: []stateswitch.State{
stateswitch.State(models.HostStatusInstallingInProgress),
stateswitch.State(models.HostStatusInstalling),
stateswitch.State(models.HostStatusInstallingPendingUserAction),
},
DestinationState: stateswitch.State(models.HostStatusAddedToExistingCluster),
PostTransition: th.PostHostProgress,
Documentation: stateswitch.TransitionRuleDoc{
Name: "host progress changed to added-to-existing-cluster for day2 host",
Description: "Change day2 host state to HostStatusAddedToExistingCluster when it reached stage Done. (i.e. the end of SAAS flow for day2 installation)",
},
})
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeHostProgress,
Condition: th.IsHostInDone,
SourceStates: []stateswitch.State{
stateswitch.State(models.HostStatusInstallingInProgress),
stateswitch.State(models.HostStatusInstalling),
},
DestinationState: stateswitch.State(models.HostStatusInstalled),
PostTransition: th.PostHostProgress,
Documentation: stateswitch.TransitionRuleDoc{
Name: "host progress changed to installed",
Description: "Change host state to installed when it reached stage Done",
},
})
//Note: Keep this transition last in respect
//to other TransitionTypeHostProgress rules
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeHostProgress,
SourceStates: []stateswitch.State{
stateswitch.State(models.HostStatusInstallingInProgress),
stateswitch.State(models.HostStatusInstalling),
stateswitch.State(models.HostStatusInstallingPendingUserAction),
},
DestinationState: stateswitch.State(models.HostStatusInstallingInProgress),
PostTransition: th.PostHostProgress,
Documentation: stateswitch.TransitionRuleDoc{
Name: "default host progress changed",
Description: "Keep host state in installingInProgress during installation",
},
})
//this is a noop operation where all other conditions
//are not met.
for _, state := range []stateswitch.State{
stateswitch.State(models.HostStatusInstalled),
stateswitch.State(models.HostStatusInstallingPendingUserAction),
stateswitch.State(models.HostStatusResettingPendingUserAction),
} {
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeHostProgress,
SourceStates: []stateswitch.State{state},
DestinationState: state,
Documentation: stateswitch.TransitionRuleDoc{
Name: fmt.Sprintf("Host progress change during %s state when host is not in state Done (or Rebooting in day2) should stay in %s state", state, state),
Description: "Fallback transition for host progress change",
},
})
}
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeRegisterHost,
SourceStates: []stateswitch.State{
stateswitch.State(models.HostStatusDiscovering),
stateswitch.State(models.HostStatusKnown),
stateswitch.State(models.HostStatusDisconnected),
stateswitch.State(models.HostStatusInsufficient),
stateswitch.State(models.HostStatusResettingPendingUserAction),
stateswitch.State(models.HostStatusPreparingForInstallation),
stateswitch.State(models.HostStatusPreparingSuccessful),
stateswitch.State(models.HostStatusBinding),
stateswitch.State(models.HostStatusPendingForInput),
},
DestinationState: stateswitch.State(models.HostStatusDiscovering),
PostTransition: th.PostRegisterHost,
Documentation: stateswitch.TransitionRuleDoc{
Name: "Re-registration",
Description: "When the host attempts to register while it's in one of the non-installation states. We move the host back to the discovering state instead of keeping it in its current state because we consider it a new host with potentially different hardware. See PostRegisterHost function",
},
})
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeRegisterHost,
SourceStates: []stateswitch.State{
stateswitch.State(models.HostStatusResetting),
},
Condition: th.IsHostInReboot,
DestinationState: stateswitch.State(models.HostStatusResetting),
Documentation: stateswitch.TransitionRuleDoc{
Name: "Ignore register while rebooting host in resetting",
Description: "On such cases cluster monitor is responsible to set the host state to resetting-pending-user-action. There are some edge cases on installation where user tries to reset installation on the same time reboot is called. On some cases the agent will get to reset itself and register again just before the reboot and the cluster monitor will not get to set the status in resetting-pending-user-action on time. Created to prevent OCPBUGSM-13597",
},
})
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeRegisterHost,
SourceStates: []stateswitch.State{
stateswitch.State(models.HostStatusResetting),
},
Condition: stateswitch.Not(th.IsHostInReboot),
DestinationState: stateswitch.State(models.HostStatusDiscovering),
PostTransition: th.PostRegisterHost,
Documentation: stateswitch.TransitionRuleDoc{
Name: "Register non-rebooting host in resetting",
Description: "The opposite of the 'Ignore register while rebooting host in resetting' transition rule, move host to discovering",
},
})
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeRegisterHost,
Condition: stateswitch.Or(th.IsHostInReboot, stateswitch.And(th.IsDay2Host, th.IsHostInDone)),
SourceStates: []stateswitch.State{
stateswitch.State(models.HostStatusInstallingInProgress),
stateswitch.State(models.HostStatusInstallingPendingUserAction),
stateswitch.State(models.HostStatusAddedToExistingCluster),
},
DestinationState: stateswitch.State(models.HostStatusInstallingPendingUserAction),
PostTransition: th.PostRegisterDuringReboot,
Documentation: stateswitch.TransitionRuleDoc{
Name: "Wrong boot order detection",
Description: "A day-1 host trying to register while it's in the rebooting stage or a day-2 host trying to register while it's in the done stage indicate that the host, after installing the operating system to disk and then rebooting, booted from the discovery ISO again instead of booting the installed operating system as it should've done (the first thing the discovery ISO live OS tries to do is register). This indicates that the user has a wrong boot order that they should fix. This transition makes sure to let the user know about what happened and what they should do to fix that",
},
})
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeRegisterHost,
SourceStates: []stateswitch.State{
stateswitch.State(models.HostStatusInstalling),
stateswitch.State(models.HostStatusInstallingInProgress),
},
DestinationState: stateswitch.State(models.HostStatusError),
PostTransition: th.PostRegisterDuringInstallation,
Documentation: stateswitch.TransitionRuleDoc{
Name: "Register during installation",
Description: "Any host registering during installation but doesn't match the 'Wrong boot order detection' transition is performing an invalid operation and thus should move to the error state",
},
})
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeRegisterHost,
SourceStates: []stateswitch.State{
stateswitch.State(models.HostStatusError),
},
DestinationState: stateswitch.State(models.HostStatusError),
Documentation: stateswitch.TransitionRuleDoc{
Name: "Register during error",
Description: "Host in error should be able to register without changes. If the registration return conflict or error then we have infinite number of events. If the registration is blocked (403) it will break auto-reset feature. It can happen that user rebooted the host manually after installation failure without changes in the cluster. So the best option is just accept the registration without changes in the DB",
},
})
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeRegisterHost,
SourceStates: []stateswitch.State{
stateswitch.State(models.HostStatusInstalled),
},
DestinationState: stateswitch.State(models.HostStatusInstalled),
PostTransition: th.PostRegisterAfterInstallation,
Documentation: stateswitch.TransitionRuleDoc{
Name: "Register post-installation",
Description: "A host may boot from the installation ISO after the cluster has been installed. In that case we want to ask the host to go away, as otherwise it will flood the log and the events",
},
})
// Installation failure
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeHostInstallationFailed,
SourceStates: []stateswitch.State{
stateswitch.State(models.HostStatusInstalling),
stateswitch.State(models.HostStatusInstallingInProgress),
},
DestinationState: stateswitch.State(models.HostStatusError),
PostTransition: th.PostHostInstallationFailed,
Documentation: stateswitch.TransitionRuleDoc{
Name: "Installation failed while host is installing",
Description: "When the installation fails while a host is installing, the host should be moved to the error state because it is no longer actually installing",
},
})
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeCancelInstallation,
SourceStates: []stateswitch.State{
stateswitch.State(models.HostStatusInstallingPendingUserAction),
stateswitch.State(models.HostStatusInstalling),
stateswitch.State(models.HostStatusInstallingInProgress),
stateswitch.State(models.HostStatusInstalled),
stateswitch.State(models.HostStatusError),
},
DestinationState: stateswitch.State(models.HostStatusCancelled),
PostTransition: th.PostCancelInstallation,
Documentation: stateswitch.TransitionRuleDoc{
Name: "Installation canceled while host is installing",
Description: "When the installation is canceled while the host is installing or finished installing, the host needs to move to the cancelled state",
},
})
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeCancelInstallation,
SourceStates: []stateswitch.State{
stateswitch.State(models.HostStatusPreparingForInstallation),
stateswitch.State(models.HostStatusPreparingSuccessful),
},
DestinationState: stateswitch.State(models.HostStatusKnown),
PostTransition: th.PostCancelInstallation,
Documentation: stateswitch.TransitionRuleDoc{
Name: "Cancel while preparing",
Description: "TODO: Document this transition rule",
},
})
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeCancelInstallation,
SourceStates: []stateswitch.State{
stateswitch.State(models.HostStatusKnown),
},
DestinationState: stateswitch.State(models.HostStatusKnown),
Documentation: stateswitch.TransitionRuleDoc{
Name: "Cancel while known",
Description: "TODO: Document this transition rule",
},
})
// Install day2 host
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeInstallHost,
SourceStates: []stateswitch.State{
stateswitch.State(models.HostStatusKnown),
},
Condition: th.IsDay2Host,
DestinationState: stateswitch.State(models.HostStatusInstalling),
PostTransition: th.PostInstallHost,
Documentation: stateswitch.TransitionRuleDoc{
Name: "Install known host",
Description: "TODO: Document this transition rule",
},
})
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeResettingPendingUserAction,
SourceStates: []stateswitch.State{
stateswitch.State(models.HostStatusResetting),
stateswitch.State(models.HostStatusDiscovering),
stateswitch.State(models.HostStatusKnown),
stateswitch.State(models.HostStatusInstallingPendingUserAction),
stateswitch.State(models.HostStatusInstalling),
stateswitch.State(models.HostStatusPreparingForInstallation),
stateswitch.State(models.HostStatusPreparingSuccessful),
stateswitch.State(models.HostStatusPreparingFailed),
stateswitch.State(models.HostStatusPendingForInput),
stateswitch.State(models.HostStatusResettingPendingUserAction),
stateswitch.State(models.HostStatusInstallingInProgress),
stateswitch.State(models.HostStatusInstalled),
stateswitch.State(models.HostStatusError),
stateswitch.State(models.HostStatusCancelled),
stateswitch.State(models.HostStatusAddedToExistingCluster),
},
DestinationState: stateswitch.State(models.HostStatusResettingPendingUserAction),
PostTransition: th.PostResettingPendingUserAction,
Documentation: stateswitch.TransitionRuleDoc{
Name: "Reset pending user action all states",
Description: "TODO: Document this transition rule",
},
})
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeUnbindHost,
SourceStates: []stateswitch.State{
stateswitch.State(models.HostStatusKnown),
stateswitch.State(models.HostStatusDiscovering),
stateswitch.State(models.HostStatusDisconnected),
stateswitch.State(models.HostStatusInsufficient),
stateswitch.State(models.HostStatusPendingForInput),
},
DestinationState: stateswitch.State(models.HostStatusUnbinding),
PostTransition: th.PostUnbindHost,
Documentation: stateswitch.TransitionRuleDoc{
Name: "Unbind pre-installation",
Description: "TODO: Document this transition rule",
},
})
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeUnbindHost,
SourceStates: []stateswitch.State{
stateswitch.State(models.HostStatusInstalled),
stateswitch.State(models.HostStatusAddedToExistingCluster),
stateswitch.State(models.HostStatusError),
stateswitch.State(models.HostStatusCancelled),
},
DestinationState: stateswitch.State(models.HostStatusUnbindingPendingUserAction),
PostTransition: th.PostUnbindHost,
Documentation: stateswitch.TransitionRuleDoc{
Name: "Unbind during or after installation",
Description: "TODO: Document this transition rule",
},
})
// ReclaimHost when installed moves to Reclaiming
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeReclaimHost,
SourceStates: []stateswitch.State{
stateswitch.State(models.HostStatusInstalled),
stateswitch.State(models.HostStatusAddedToExistingCluster),
},
DestinationState: stateswitch.State(models.HostStatusReclaiming),
PostTransition: th.PostUnbindHost,
Documentation: stateswitch.TransitionRuleDoc{
Name: "Reclaim successful host",
Description: "TODO: Document this transition rule",
},
})
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeRebootingForReclaim,
SourceStates: []stateswitch.State{
stateswitch.State(models.HostStatusReclaiming),
},
DestinationState: stateswitch.State(models.HostStatusReclaimingRebooting),
PostTransition: th.PostReclaim,
Documentation: stateswitch.TransitionRuleDoc{
Name: "Rebooting for reclaim reclaiming host",
Description: "TODO: Document this transition rule",
},
})
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeReclaimFailed,
SourceStates: []stateswitch.State{
stateswitch.State(models.HostStatusReclaiming),
stateswitch.State(models.HostStatusReclaimingRebooting),
},
DestinationState: stateswitch.State(models.HostStatusUnbindingPendingUserAction),
PostTransition: th.PostUnbindHost,
Documentation: stateswitch.TransitionRuleDoc{
Name: "Reclaim failure for reclaiming host",
Description: "TODO: Document this transition rule",
},
})
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeRefresh,
SourceStates: []stateswitch.State{
stateswitch.State(models.HostStatusReclaiming),
stateswitch.State(models.HostStatusReclaimingRebooting),
},
Condition: th.HasStatusTimedOut(ReclaimTimeout),
DestinationState: stateswitch.State(models.HostStatusUnbindingPendingUserAction),
PostTransition: th.PostRefreshReclaimTimeout,
Documentation: stateswitch.TransitionRuleDoc{
Name: "Refresh reclaiming host",
Description: "TODO: Document this transition rule",
},
})
// ReclaimHost in other states acts like Unbind
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeReclaimHost,
SourceStates: []stateswitch.State{
stateswitch.State(models.HostStatusKnown),
stateswitch.State(models.HostStatusDiscovering),
stateswitch.State(models.HostStatusDisconnected),
stateswitch.State(models.HostStatusInsufficient),
stateswitch.State(models.HostStatusPendingForInput),
},
DestinationState: stateswitch.State(models.HostStatusUnbinding),
PostTransition: th.PostUnbindHost,
Documentation: stateswitch.TransitionRuleDoc{
Name: "Reclaim pre-installation",
Description: "TODO: Document this transition rule",
},
})
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeReclaimHost,
SourceStates: []stateswitch.State{
stateswitch.State(models.HostStatusError),
stateswitch.State(models.HostStatusCancelled),
},
DestinationState: stateswitch.State(models.HostStatusUnbindingPendingUserAction),
PostTransition: th.PostUnbindHost,
Documentation: stateswitch.TransitionRuleDoc{
Name: "Reclaim failed host",
Description: "TODO: Document this transition rule",
},
})
// Refresh host
// Prepare for installation
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeRefresh,
Condition: stateswitch.And(If(ValidRoleForInstallation), If(IsConnected), If(IsMediaConnected), If(ClusterPreparingForInstallation)),
SourceStates: []stateswitch.State{
stateswitch.State(models.HostStatusKnown),
},
DestinationState: stateswitch.State(models.HostStatusPreparingForInstallation),
PostTransition: th.PostPreparingForInstallationHost,
Documentation: stateswitch.TransitionRuleDoc{
Name: "Refresh known host in preparing cluster",
Description: "TODO: Document this transition rule",
},
})
// Unknown validations
installationDiskSpeedUnknown := stateswitch.And(stateswitch.Not(If(InstallationDiskSpeedCheckSuccessful)), If(SufficientOrUnknownInstallationDiskSpeed))
imagesAvailabilityUnknown := stateswitch.And(stateswitch.Not(If(SuccessfulContainerImageAvailability)), If(SucessfullOrUnknownContainerImagesAvailability))
// All validations are successful
allConditionsSuccessful := stateswitch.And(If(InstallationDiskSpeedCheckSuccessful), If(SuccessfulContainerImageAvailability))
// All validations are successful, or were not evaluated
allConditionsSuccessfulOrUnknown := stateswitch.And(If(SufficientOrUnknownInstallationDiskSpeed), If(SucessfullOrUnknownContainerImagesAvailability))
// At least one of the validations has not been evaluated and there are no failed validations
atLeastOneConditionUnknown := stateswitch.And(stateswitch.Or(installationDiskSpeedUnknown, imagesAvailabilityUnknown), allConditionsSuccessfulOrUnknown)
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeRefresh,
SourceStates: []stateswitch.State{
stateswitch.State(models.HostStatusPreparingForInstallation),
},
Condition: stateswitch.And(If(IsConnected), If(IsMediaConnected), allConditionsSuccessful, If(ClusterPreparingForInstallation)),
DestinationState: stateswitch.State(models.HostStatusPreparingSuccessful),
PostTransition: th.PostRefreshHost(statusInfoHostPreparationSuccessful),
Documentation: stateswitch.TransitionRuleDoc{
Name: "Refresh successfully preparing host",
Description: "TODO: Document this transition rule",
},
})
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeRefresh,
SourceStates: []stateswitch.State{
stateswitch.State(models.HostStatusPreparingSuccessful),
},
Condition: stateswitch.And(If(IsConnected), If(IsMediaConnected), If(ClusterPreparingForInstallation)),
DestinationState: stateswitch.State(models.HostStatusPreparingSuccessful),
Documentation: stateswitch.TransitionRuleDoc{
Name: "Stay in preparing successful",
Description: "TODO: Document this transition rule",
},
})
// Install host
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeRefresh,
SourceStates: []stateswitch.State{
stateswitch.State(models.HostStatusPreparingSuccessful),
},
Condition: stateswitch.And(If(IsConnected), If(IsMediaConnected), If(ClusterInstalling)),
DestinationState: stateswitch.State(models.HostStatusInstalling),
PostTransition: th.PostRefreshHost(statusInfoInstalling),
Documentation: stateswitch.TransitionRuleDoc{
Name: "Move successfully prepared host to installing",
Description: "TODO: Document this transition rule",
},
})
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeRefresh,
SourceStates: []stateswitch.State{
stateswitch.State(models.HostStatusPreparingForInstallation),
},
Condition: stateswitch.And(If(IsConnected), If(IsMediaConnected), allConditionsSuccessfulOrUnknown, stateswitch.Not(If(ClusterPreparingForInstallation))),
DestinationState: stateswitch.State(models.HostStatusKnown),
PostTransition: th.PostRefreshHost(statusInfoKnown),
Documentation: stateswitch.TransitionRuleDoc{
Name: "Move preparing host to known when cluster stops preparing",
Description: "TODO: Document this transition rule",
},
})
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeRefresh,
SourceStates: []stateswitch.State{
stateswitch.State(models.HostStatusPreparingForInstallation),
stateswitch.State(models.HostStatusPreparingFailed),
stateswitch.State(models.HostStatusKnown),
},
Condition: stateswitch.And(If(IsConnected), If(IsMediaConnected), stateswitch.Not(If(SufficientOrUnknownInstallationDiskSpeed))),
DestinationState: stateswitch.State(models.HostStatusInsufficient),
PostTransition: th.PostRefreshHost(statusInfoNotReadyForInstall),
Documentation: stateswitch.TransitionRuleDoc{
Name: "Preparing failed disk speed host move to insufficient",
Description: "TODO: Document this transition rule",
},
})
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeRefresh,
SourceStates: []stateswitch.State{
stateswitch.State(models.HostStatusPreparingForInstallation),
},
Condition: stateswitch.And(If(IsConnected), If(IsMediaConnected), th.IsPreparingTimedOut, stateswitch.Or(installationDiskSpeedUnknown, imagesAvailabilityUnknown), allConditionsSuccessfulOrUnknown),
DestinationState: stateswitch.State(models.HostStatusPreparingFailed),
PostTransition: th.PostHostPreparationTimeout(),
Documentation: stateswitch.TransitionRuleDoc{
Name: "Preparing timed out host move to known",
Description: "TODO: Document this transition rule",
},
})
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeRefresh,
SourceStates: []stateswitch.State{
stateswitch.State(models.HostStatusPreparingForInstallation),
},
Condition: stateswitch.And(If(IsConnected), If(IsMediaConnected), stateswitch.Not(If(SucessfullOrUnknownContainerImagesAvailability))),
DestinationState: stateswitch.State(models.HostStatusPreparingFailed),
PostTransition: th.PostRefreshHost(statusInfoHostPreparationFailure),
Documentation: stateswitch.TransitionRuleDoc{
Name: "Preparing failed image pull host move to preparing failed",
Description: "TODO: Document this transition rule",
},
})
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeRefresh,
SourceStates: []stateswitch.State{
stateswitch.State(models.HostStatusPreparingForInstallation),
},
Condition: stateswitch.And(If(IsConnected), If(IsMediaConnected), atLeastOneConditionUnknown, If(ClusterPreparingForInstallation)),
DestinationState: stateswitch.State(models.HostStatusPreparingForInstallation),
Documentation: stateswitch.TransitionRuleDoc{
Name: "Stay in preparing for installation",
Description: "TODO: Document this transition rule",
},
})
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeRefresh,
SourceStates: []stateswitch.State{
stateswitch.State(models.HostStatusPreparingFailed),
},
Condition: stateswitch.And(If(IsConnected), If(IsMediaConnected), stateswitch.Not(If(ClusterPreparingForInstallation))),
DestinationState: stateswitch.State(models.HostStatusKnown),
PostTransition: th.PostRefreshHost(statusInfoKnown),
Documentation: stateswitch.TransitionRuleDoc{
Name: "Failed preparing to known when cluster is no longer preparing",
Description: "TODO: Document this transition rule",
},
})
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeRefresh,
SourceStates: []stateswitch.State{
stateswitch.State(models.HostStatusPreparingSuccessful),
},
Condition: stateswitch.And(If(IsConnected), If(IsMediaConnected), stateswitch.Not(stateswitch.Or(If(ClusterPreparingForInstallation), If(ClusterInstalling)))),
DestinationState: stateswitch.State(models.HostStatusKnown),
PostTransition: th.PostRefreshHost(statusInfoKnown),
Documentation: stateswitch.TransitionRuleDoc{
Name: "Successful preparing to known when cluster is no longer preparing",
Description: "TODO: Document this transition rule. Why is ClusterInstalling relevant here?",
},
})
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeRefresh,
SourceStates: []stateswitch.State{
stateswitch.State(models.HostStatusDiscovering),
stateswitch.State(models.HostStatusInsufficient),
stateswitch.State(models.HostStatusKnown),
stateswitch.State(models.HostStatusPendingForInput),
stateswitch.State(models.HostStatusDisconnected),
stateswitch.State(models.HostStatusPreparingFailed),
},
Condition: stateswitch.Or(stateswitch.Not(If(IsConnected)),
stateswitch.Not(If(IsMediaConnected))),
DestinationState: stateswitch.State(models.HostStatusDisconnected),
PostTransition: th.PostRefreshHost(statusInfoDisconnected),
Documentation: stateswitch.TransitionRuleDoc{
Name: "Move host to disconnected when connected times out",
Description: "This transition occurs when no requests are detected from the agent or when the discovery media gets disconnected during pre-installation phases",
},
})
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeMediaDisconnect,
SourceStates: []stateswitch.State{
stateswitch.State(models.HostStatusDiscovering),
stateswitch.State(models.HostStatusInsufficient),
stateswitch.State(models.HostStatusKnown),
stateswitch.State(models.HostStatusPendingForInput),
stateswitch.State(models.HostStatusDisconnected),
stateswitch.State(models.HostStatusBinding),
},
DestinationState: stateswitch.State(models.HostStatusDisconnected),
PostTransition: th.PostHostMediaDisconnected,
Documentation: stateswitch.TransitionRuleDoc{
Name: "Move to disconnected when virtual media disconnects pre-installation",
Description: "TODO: Document this transition rule.",
},
})
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeMediaDisconnect,
SourceStates: []stateswitch.State{
stateswitch.State(models.HostStatusPreparingForInstallation),
stateswitch.State(models.HostStatusPreparingFailed),
stateswitch.State(models.HostStatusPreparingSuccessful),
stateswitch.State(models.HostStatusInstalling),
stateswitch.State(models.HostStatusInstallingInProgress),
stateswitch.State(models.HostStatusError),
},
DestinationState: stateswitch.State(models.HostStatusError),
PostTransition: th.PostHostMediaDisconnected,
Documentation: stateswitch.TransitionRuleDoc{
Name: "Move to error when virtual media disconnects post-installation",
Description: "TODO: Document this transition rule.",
},
})
// Abort host if cluster has errors
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeRefresh,
SourceStates: []stateswitch.State{
stateswitch.State(models.HostStatusInstalling),
stateswitch.State(models.HostStatusInstallingInProgress),
stateswitch.State(models.HostStatusInstalled),
stateswitch.State(models.HostStatusResettingPendingUserAction),
stateswitch.State(models.HostStatusInstallingPendingUserAction),
},
Condition: stateswitch.And(If(ClusterInError), stateswitch.Not(th.IsDay2Host)),
DestinationState: stateswitch.State(models.HostStatusError),
PostTransition: th.PostRefreshHost(statusInfoAbortingDueClusterErrors),
Documentation: stateswitch.TransitionRuleDoc{
Name: "Move host to error when cluster is in error",
Description: "TODO: Document this transition rule. Why not day 2?",
},
})
// Time out while host installation
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeRefresh,
SourceStates: []stateswitch.State{
stateswitch.State(models.HostStatusInstalling)},
Condition: th.HasStatusTimedOut(InstallationTimeout),
DestinationState: stateswitch.State(models.HostStatusError),
PostTransition: th.PostRefreshHost(statusInfoInstallationTimedOut),
Documentation: stateswitch.TransitionRuleDoc{
Name: "Move host to error when installation times out",
Description: "TODO: Document this transition rule.",
},
})
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeRefresh,
SourceStates: []stateswitch.State{
stateswitch.State(models.HostStatusPreparingForInstallation),
stateswitch.State(models.HostStatusPreparingSuccessful),
},
Condition: stateswitch.Or(stateswitch.Not(If(IsConnected)),
stateswitch.Not(If(IsMediaConnected))),
DestinationState: stateswitch.State(models.HostStatusDisconnected),
PostTransition: th.PostRefreshHost(statusInfoConnectionTimedOutPreparing),
Documentation: stateswitch.TransitionRuleDoc{
Name: "Move preparing host to disconnected when connection times out",
Description: "This transition occurs when no requests are detected from the agent or when the discovery media gets disconnected during prepare for installation phases",
},
})
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeRefresh,
SourceStates: []stateswitch.State{
stateswitch.State(models.HostStatusInstalling),
stateswitch.State(models.HostStatusInstallingInProgress),
},
Condition: stateswitch.And(stateswitch.Not(If(IsConnected)), stateswitch.Not(If(SoftTimeoutsEnabled))),
DestinationState: stateswitch.State(models.HostStatusError),
PostTransition: th.PostRefreshHost(statusInfoConnectionTimedOutInstalling),
Documentation: stateswitch.TransitionRuleDoc{
Name: "Move installing host to error when connection times out",
Description: "When host is in one of the installation phases and soft timeout is not enabled and host fails to connect to assisted service, move the host to error",
},
})
for _, st := range []string{models.HostStatusInstalling, models.HostStatusInstallingInProgress} {
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeRefresh,
SourceStates: []stateswitch.State{
stateswitch.State(st),
},
Condition: stateswitch.And(stateswitch.Not(If(IsConnected)),
If(SoftTimeoutsEnabled),
stateswitch.Not(If(ConnectionTimedOut))),
DestinationState: stateswitch.State(st),
PostTransition: th.PostRefreshHostDisconnection(statusInfoConnectionSoftTimedOutInstalling, true),
Documentation: stateswitch.TransitionRuleDoc{
Name: "Keep installing host when connection times out",
Description: "When host is in one of the installation phases and soft timeout is enabled and host fails to connect to assisted service, keep installing host and indicate that timeout has occurred",
},
})
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeRefresh,
SourceStates: []stateswitch.State{
stateswitch.State(st),
},
Condition: stateswitch.And(If(IsConnected),
If(SoftTimeoutsEnabled),
If(ConnectionTimedOut)),
DestinationState: stateswitch.State(st),
PostTransition: th.PostRefreshHostDisconnection(statusInfoConnectionSoftTimedOutInstallingReconnected, false),
Documentation: stateswitch.TransitionRuleDoc{
Name: "Keep installing host when host recovers from disconnection",
Description: "When host is in one of the installation phases and soft timeout is enabled and host recovers from disconnection to assisted service, keep installing host and clear the disconnection indication",
},
})
}
shouldIgnoreInstallationProgressTimeout := stateswitch.And(If(StageInWrongBootStages), If(ClusterPendingUserAction))
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeRefresh,
SourceStates: []stateswitch.State{
stateswitch.State(models.HostStatusInstallingInProgress)},
Condition: shouldIgnoreInstallationProgressTimeout,
DestinationState: stateswitch.State(models.HostStatusInstallingInProgress),
PostTransition: th.PostRefreshHostRefreshStageUpdateTime,
Documentation: stateswitch.TransitionRuleDoc{
Name: "Ignore timeout if host is in particular installation in progress stages",
Description: "TODO: Document this transition rule.",
},
})
// Host stage timeout transitions. They handle all stages when cluster is in 'installing-in-progress' status besides
// rebooting stage which is handled differently - it moves to installing-pending-user-action
// Timeout while host installationInProgress and soft timeouts is not enabled for stages other than [writing-image-to-disk, rebooting]
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeRefresh,
SourceStates: []stateswitch.State{
stateswitch.State(models.HostStatusInstallingInProgress)},
Condition: stateswitch.And(
stateswitch.Not(If(SoftTimeoutsEnabled)),
stateswitch.Not(IsInStages(models.HostStageWritingImageToDisk, models.HostStageRebooting)),
th.HasInstallationInProgressTimedOut,
stateswitch.Not(shouldIgnoreInstallationProgressTimeout)),
DestinationState: stateswitch.State(models.HostStatusError),
PostTransition: th.PostRefreshHost(statusInfoInstallationInProgressTimedOut),
Documentation: stateswitch.TransitionRuleDoc{
Name: "Move to error on timeout if host is in particular installation in progress stages other than [writing-image-to-disk, rebooting]",
Description: "The transition is triggered when soft timeouts is not enabled which means that timeout expiration causes a host to move to error",
},
})
// Timeout while host installationInProgress and soft timeouts is not enabled for stage writing-image-to-disk.
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeRefresh,
SourceStates: []stateswitch.State{
stateswitch.State(models.HostStatusInstallingInProgress)},
Condition: stateswitch.And(
stateswitch.Not(If(SoftTimeoutsEnabled)),
IsInStages(models.HostStageWritingImageToDisk),
th.HasInstallationInProgressTimedOut,
stateswitch.Not(shouldIgnoreInstallationProgressTimeout)),
DestinationState: stateswitch.State(models.HostStatusError),
PostTransition: th.PostRefreshHost(statusInfoInstallationInProgressWritingImageToDiskTimedOut),
Documentation: stateswitch.TransitionRuleDoc{
Name: "Move to error on timeout if host is in particular installation in progress stage writing-image-to-disk",
Description: "The transition is triggered when soft timeouts is not enabled which means that timeout expiration causes a host to move to error",
},
})
// Timeout while host installationInProgress and soft timeouts is enabled for stages other than [writing-image-to-disk, rebooting]
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeRefresh,
SourceStates: []stateswitch.State{
stateswitch.State(models.HostStatusInstallingInProgress)},
Condition: stateswitch.And(
If(SoftTimeoutsEnabled),
stateswitch.Not(If(HostStageTimedOut)),
stateswitch.Not(IsInStages(models.HostStageWritingImageToDisk, models.HostStageRebooting)),
th.HasInstallationInProgressTimedOut,
stateswitch.Not(shouldIgnoreInstallationProgressTimeout)),
DestinationState: stateswitch.State(models.HostStatusInstallingInProgress),
PostTransition: th.PostHostStageTimeout(statusInfoInstallationInProgressSoftTimedOut),
Documentation: stateswitch.TransitionRuleDoc{
Name: "Indicate that timeout occurred and continue installation in particular installation in progress stages other than [writing-image-to-disk, rebooting]",
Description: "The transition is triggered when soft timeouts is enabled which means that timeout expiration causes event generation only",
},
})
// Timeout while host installationInProgress and soft timeouts is not enabled for stage writing-image-to-disk.
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeRefresh,
SourceStates: []stateswitch.State{
stateswitch.State(models.HostStatusInstallingInProgress)},
Condition: stateswitch.And(
If(SoftTimeoutsEnabled),
stateswitch.Not(If(HostStageTimedOut)),
IsInStages(models.HostStageWritingImageToDisk),
th.HasInstallationInProgressTimedOut,
stateswitch.Not(shouldIgnoreInstallationProgressTimeout)),
DestinationState: stateswitch.State(models.HostStatusInstallingInProgress),
PostTransition: th.PostHostStageTimeout(statusInfoInstallationInProgressWritingImageToDiskSoftTimedOut),
Documentation: stateswitch.TransitionRuleDoc{
Name: "Indicate that timeout occurred and continue installation in particular installation in progress stage writing-image-to-disk",
Description: "The transition is triggered when soft timeouts is enabled which means that timeout expiration causes event generation only",
},
})
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeRefresh,
SourceStates: []stateswitch.State{
stateswitch.State(models.HostStatusInstallingInProgress)},
Condition: stateswitch.And(
th.HasInstallationInProgressTimedOut,
th.IsHostInReboot),
DestinationState: stateswitch.State(models.HostStatusInstallingPendingUserAction),
PostTransition: th.PostRefreshHost(statusRebootTimeout),
Documentation: stateswitch.TransitionRuleDoc{
Name: "Tell user about boot order wen reboot takes too long",
Description: "TODO: Document this transition rule.",
},
})
// Noop transitions for cluster error
for _, state := range []stateswitch.State{
stateswitch.State(models.HostStatusInstalling),
stateswitch.State(models.HostStatusInstallingInProgress),
stateswitch.State(models.HostStatusInstalled),
stateswitch.State(models.HostStatusInstallingPendingUserAction),
stateswitch.State(models.HostStatusResettingPendingUserAction),
} {
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeRefresh,
SourceStates: []stateswitch.State{state},
Condition: stateswitch.Not(If(ClusterInError)),
DestinationState: state,
Documentation: stateswitch.TransitionRuleDoc{
Name: fmt.Sprintf("Refresh during %s state without cluster error should stay in %s state", state, state),
Description: "TODO: Document this transition rule. Is this necessary?",
},
})
}
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeRefresh,
SourceStates: []stateswitch.State{
stateswitch.State(models.HostStatusDisconnected),
stateswitch.State(models.HostStatusDiscovering),
},
Condition: stateswitch.And(If(IsConnected), If(IsMediaConnected), stateswitch.Not(If(HasInventory))),
DestinationState: stateswitch.State(models.HostStatusDiscovering),
PostTransition: th.PostRefreshHost(statusInfoDiscovering),
Documentation: stateswitch.TransitionRuleDoc{
Name: "Host reconnected without inventory",
Description: "TODO: Document this transition rule. Why is Discovering in the source states?",
},
})
var hasMinRequiredHardware = stateswitch.And(
If(HasMinValidDisks),
If(HasMinCPUCores),
If(HasMinMemory),
If(CompatibleWithClusterPlatform),
If(DiskEncryptionRequirementsSatisfied),
)
var requiredInputFieldsExist = stateswitch.And(
If(IsMachineCidrDefined),
)
var isSufficientForInstall = stateswitch.And(
If(HasMemoryForRole),
If(HasCPUCoresForRole),
If(BelongsToMachineCidr),
If(IsHostnameUnique),
If(IsHostnameValid),
If(IsIgnitionDownloadable),
If(BelongsToMajorityGroup),
If(AreOdfRequirementsSatisfied),
If(AreLsoRequirementsSatisfied),
If(AreCnvRequirementsSatisfied),
If(AreLvmRequirementsSatisfied),
If(AreMceRequirementsSatisfied),
If(AreMtvRequirementsSatisfied),
If(AreOscRequirementsSatisfied),
If(HasSufficientNetworkLatencyRequirementForRole),
If(HasSufficientPacketLossRequirementForRole),
If(HasDefaultRoute),
If(IsAPIDomainNameResolvedCorrectly),
If(IsAPIInternalDomainNameResolvedCorrectly),
If(IsAppsDomainNameResolvedCorrectly),
If(IsDNSWildcardNotConfigured),
If(IsPlatformNetworkSettingsValid),
If(SufficientOrUnknownInstallationDiskSpeed),
If(NonOverlappingSubnets),
If(CompatibleAgent),
If(IsTimeSyncedBetweenHostAndService),
If(NoSkipInstallationDisk),
If(NoSkipMissingDisk),
If(NoIPCollisionsInNetwork),
If(NoIscsiNicBelongsToMachineCidr),
If(AreNodeFeatureDiscoveryRequirementsSatisfied),
If(AreNvidiaGPURequirementsSatisfied),
If(ArePipelinesRequirementsSatisfied),
If(AreServiceMeshRequirementsSatisfied),
If(AreServerLessRequirementsSatisfied),
If(AreOpenShiftAIRequirementsSatisfied),
If(AreAuthorinoRequirementsSatisfied),
/*
* MGMT-15213: The release domain is not resolved correctly when there is a mirror or proxy. In this case
* validation might fail, but the installation may succeed.
* TODO: MGMT-15213 - Fix the validation bug
If(IsReleaseDomainNameResolvedCorrectly),
*/
)
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeRefresh,
SourceStates: []stateswitch.State{
stateswitch.State(models.HostStatusDisconnected),
stateswitch.State(models.HostStatusDiscovering),
stateswitch.State(models.HostStatusInsufficient),
stateswitch.State(models.HostStatusKnown),
stateswitch.State(models.HostStatusPendingForInput),
},
Condition: stateswitch.And(If(IsConnected), If(IsMediaConnected), If(HasInventory),
stateswitch.Not(hasMinRequiredHardware)),
DestinationState: stateswitch.State(models.HostStatusInsufficient),
PostTransition: th.PostRefreshHost(statusInfoInsufficientHardware),
Documentation: stateswitch.TransitionRuleDoc{
Name: "Host has insufficient hardware",
Description: "In order for this transition to be fired at least one of the validations in minRequiredHardwareValidations must fail. This transition handles the case that a host does not pass minimum hardware requirements for any of the roles",
},
})
sm.AddTransitionRule(stateswitch.TransitionRule{
TransitionType: TransitionTypeRefresh,
SourceStates: []stateswitch.State{
stateswitch.State(models.HostStatusDisconnected),
stateswitch.State(models.HostStatusDiscovering),
stateswitch.State(models.HostStatusInsufficient),
stateswitch.State(models.HostStatusKnown),
stateswitch.State(models.HostStatusPendingForInput),