5
5
"fmt"
6
6
"reflect"
7
7
"testing"
8
+ "time"
8
9
9
10
"github.com/google/go-cmp/cmp"
10
11
"github.com/google/go-cmp/cmp/cmpopts"
@@ -358,12 +359,27 @@ func TestUpdateClusterVersionStatus_FilteringMultipleErrorsForFailingCondition(t
358
359
type args struct {
359
360
syncWorkerStatus * SyncWorkerStatus
360
361
}
362
+ payload .COUpdateStartTimesEnsure ("co-not-timeout" )
363
+ payload .COUpdateStartTimesEnsure ("co-bar-not-timeout" )
364
+ payload .COUpdateStartTimesEnsure ("co-foo-not-timeout" )
365
+ payload .COUpdateStartTimesAt ("co-timeout" , time .Now ().Add (- 60 * time .Minute ))
366
+ payload .COUpdateStartTimesAt ("co-bar-timeout" , time .Now ().Add (- 60 * time .Minute ))
367
+ defer func () {
368
+ payload .COUpdateStartTimesRemove ("co-not-timeout" )
369
+ payload .COUpdateStartTimesRemove ("co-bar-not-timeout" )
370
+ payload .COUpdateStartTimesRemove ("co-foo-not-timeout" )
371
+ payload .COUpdateStartTimesRemove ("co-timeout" )
372
+ payload .COUpdateStartTimesRemove ("co-bar-timeout" )
373
+ }()
374
+
361
375
tests := []struct {
362
376
name string
363
377
args args
364
378
shouldModifyWhenNotReconcilingAndHistoryNotEmpty bool
365
379
expectedConditionNotModified * configv1.ClusterOperatorStatusCondition
366
380
expectedConditionModified * configv1.ClusterOperatorStatusCondition
381
+ machineConfigTimeout bool
382
+ expectedProgressingCondition * configv1.ClusterOperatorStatusCondition
367
383
}{
368
384
{
369
385
name : "no errors are present" ,
@@ -394,10 +410,12 @@ func TestUpdateClusterVersionStatus_FilteringMultipleErrorsForFailingCondition(t
394
410
name : "single UpdateEffectNone error" ,
395
411
args : args {
396
412
syncWorkerStatus : & SyncWorkerStatus {
413
+ Actual : configv1.Release {Version : "1.2.3" },
397
414
Failure : & payload.UpdateError {
398
415
UpdateEffect : payload .UpdateEffectNone ,
399
416
Reason : "ClusterOperatorUpdating" ,
400
417
Message : "Cluster operator A is updating" ,
418
+ Name : "co-not-timeout" ,
401
419
},
402
420
},
403
421
},
@@ -412,6 +430,110 @@ func TestUpdateClusterVersionStatus_FilteringMultipleErrorsForFailingCondition(t
412
430
Type : ClusterStatusFailing ,
413
431
Status : configv1 .ConditionFalse ,
414
432
},
433
+ expectedProgressingCondition : & configv1.ClusterOperatorStatusCondition {
434
+ Type : configv1 .OperatorProgressing ,
435
+ Status : configv1 .ConditionTrue ,
436
+ Reason : "ClusterOperatorUpdating" ,
437
+ Message : "Working towards 1.2.3: waiting on co-not-timeout" ,
438
+ },
439
+ },
440
+ {
441
+ name : "single UpdateEffectNone error and timeout" ,
442
+ args : args {
443
+ syncWorkerStatus : & SyncWorkerStatus {
444
+ Actual : configv1.Release {Version : "1.2.3" },
445
+ Failure : & payload.UpdateError {
446
+ UpdateEffect : payload .UpdateEffectNone ,
447
+ Reason : "ClusterOperatorUpdating" ,
448
+ Message : "Cluster operator A is updating" ,
449
+ Name : "co-timeout" ,
450
+ },
451
+ },
452
+ },
453
+ expectedConditionNotModified : & configv1.ClusterOperatorStatusCondition {
454
+ Type : ClusterStatusFailing ,
455
+ Status : configv1 .ConditionTrue ,
456
+ Reason : "ClusterOperatorUpdating" ,
457
+ Message : "Cluster operator A is updating" ,
458
+ },
459
+ shouldModifyWhenNotReconcilingAndHistoryNotEmpty : true ,
460
+ expectedConditionModified : & configv1.ClusterOperatorStatusCondition {
461
+ Type : ClusterStatusFailing ,
462
+ Status : configv1 .ConditionUnknown ,
463
+ Reason : "SlowClusterOperator" ,
464
+ Message : "waiting on co-timeout over 30 minutes which is longer than expected" ,
465
+ },
466
+ expectedProgressingCondition : & configv1.ClusterOperatorStatusCondition {
467
+ Type : configv1 .OperatorProgressing ,
468
+ Status : configv1 .ConditionTrue ,
469
+ Reason : "ClusterOperatorUpdating" ,
470
+ Message : "Working towards 1.2.3: waiting on co-timeout over 30 minutes which is longer than expected" ,
471
+ },
472
+ },
473
+ {
474
+ name : "single UpdateEffectNone error and machine-config" ,
475
+ args : args {
476
+ syncWorkerStatus : & SyncWorkerStatus {
477
+ Actual : configv1.Release {Version : "1.2.3" },
478
+ Failure : & payload.UpdateError {
479
+ UpdateEffect : payload .UpdateEffectNone ,
480
+ Reason : "ClusterOperatorUpdating" ,
481
+ Message : "Cluster operator A is updating" ,
482
+ Name : "machine-config" ,
483
+ },
484
+ },
485
+ },
486
+ expectedConditionNotModified : & configv1.ClusterOperatorStatusCondition {
487
+ Type : ClusterStatusFailing ,
488
+ Status : configv1 .ConditionTrue ,
489
+ Reason : "ClusterOperatorUpdating" ,
490
+ Message : "Cluster operator A is updating" ,
491
+ },
492
+ shouldModifyWhenNotReconcilingAndHistoryNotEmpty : true ,
493
+ expectedConditionModified : & configv1.ClusterOperatorStatusCondition {
494
+ Type : ClusterStatusFailing ,
495
+ Status : configv1 .ConditionFalse ,
496
+ },
497
+ expectedProgressingCondition : & configv1.ClusterOperatorStatusCondition {
498
+ Type : configv1 .OperatorProgressing ,
499
+ Status : configv1 .ConditionTrue ,
500
+ Reason : "ClusterOperatorUpdating" ,
501
+ Message : "Working towards 1.2.3: waiting on machine-config" ,
502
+ },
503
+ },
504
+ {
505
+ name : "single UpdateEffectNone error and machine-config timeout" ,
506
+ args : args {
507
+ syncWorkerStatus : & SyncWorkerStatus {
508
+ Actual : configv1.Release {Version : "1.2.3" },
509
+ Failure : & payload.UpdateError {
510
+ UpdateEffect : payload .UpdateEffectNone ,
511
+ Reason : "ClusterOperatorUpdating" ,
512
+ Message : "Cluster operator A is updating" ,
513
+ Name : "machine-config" ,
514
+ },
515
+ },
516
+ },
517
+ machineConfigTimeout : true ,
518
+ expectedConditionNotModified : & configv1.ClusterOperatorStatusCondition {
519
+ Type : ClusterStatusFailing ,
520
+ Status : configv1 .ConditionTrue ,
521
+ Reason : "ClusterOperatorUpdating" ,
522
+ Message : "Cluster operator A is updating" ,
523
+ },
524
+ shouldModifyWhenNotReconcilingAndHistoryNotEmpty : true ,
525
+ expectedConditionModified : & configv1.ClusterOperatorStatusCondition {
526
+ Type : ClusterStatusFailing ,
527
+ Status : configv1 .ConditionUnknown ,
528
+ Reason : "SlowClusterOperator" ,
529
+ Message : "waiting on machine-config over 90 minutes which is longer than expected" ,
530
+ },
531
+ expectedProgressingCondition : & configv1.ClusterOperatorStatusCondition {
532
+ Type : configv1 .OperatorProgressing ,
533
+ Status : configv1 .ConditionTrue ,
534
+ Reason : "ClusterOperatorUpdating" ,
535
+ Message : "Working towards 1.2.3: waiting on machine-config over 90 minutes which is longer than expected" ,
536
+ },
415
537
},
416
538
{
417
539
name : "single condensed UpdateEffectFail UpdateError" ,
@@ -587,6 +709,137 @@ func TestUpdateClusterVersionStatus_FilteringMultipleErrorsForFailingCondition(t
587
709
Message : "Multiple errors are preventing progress:\n * Cluster operator A is not available\n * Cluster operator C is degraded" ,
588
710
},
589
711
},
712
+ {
713
+ name : "MultipleErrors: all updating and none slow" ,
714
+ args : args {
715
+ syncWorkerStatus : & SyncWorkerStatus {
716
+ Actual : configv1.Release {Version : "1.2.3" },
717
+ Failure : & payload.UpdateError {
718
+ UpdateEffect : payload .UpdateEffectNone ,
719
+ Reason : "ClusterOperatorsUpdating" ,
720
+ Message : "some-message" ,
721
+ Names : []string {"co-not-timeout" , "co-bar-not-timeout" , "co-foo-not-timeout" },
722
+ },
723
+ },
724
+ },
725
+ expectedConditionNotModified : & configv1.ClusterOperatorStatusCondition {
726
+ Type : ClusterStatusFailing ,
727
+ Status : configv1 .ConditionTrue ,
728
+ Reason : "ClusterOperatorsUpdating" ,
729
+ Message : "some-message" ,
730
+ },
731
+ shouldModifyWhenNotReconcilingAndHistoryNotEmpty : true ,
732
+ expectedConditionModified : & configv1.ClusterOperatorStatusCondition {
733
+ Type : ClusterStatusFailing ,
734
+ Status : configv1 .ConditionFalse ,
735
+ },
736
+ expectedProgressingCondition : & configv1.ClusterOperatorStatusCondition {
737
+ Type : configv1 .OperatorProgressing ,
738
+ Status : configv1 .ConditionTrue ,
739
+ Reason : "ClusterOperatorsUpdating" ,
740
+ Message : "Working towards 1.2.3: waiting on co-not-timeout, co-bar-not-timeout, co-foo-not-timeout" ,
741
+ },
742
+ },
743
+ {
744
+ name : "MultipleErrors: all updating and one slow" ,
745
+ args : args {
746
+ syncWorkerStatus : & SyncWorkerStatus {
747
+ Actual : configv1.Release {Version : "1.2.3" },
748
+ Failure : & payload.UpdateError {
749
+ UpdateEffect : payload .UpdateEffectNone ,
750
+ Reason : "ClusterOperatorsUpdating" ,
751
+ Message : "some-message" ,
752
+ Names : []string {"co-timeout" , "co-bar-not-timeout" , "co-foo-not-timeout" },
753
+ },
754
+ },
755
+ },
756
+ expectedConditionNotModified : & configv1.ClusterOperatorStatusCondition {
757
+ Type : ClusterStatusFailing ,
758
+ Status : configv1 .ConditionTrue ,
759
+ Reason : "ClusterOperatorsUpdating" ,
760
+ Message : "some-message" ,
761
+ },
762
+ shouldModifyWhenNotReconcilingAndHistoryNotEmpty : true ,
763
+ expectedConditionModified : & configv1.ClusterOperatorStatusCondition {
764
+ Type : ClusterStatusFailing ,
765
+ Status : configv1 .ConditionUnknown ,
766
+ Reason : "SlowClusterOperator" ,
767
+ Message : "waiting on co-timeout over 30 minutes which is longer than expected" ,
768
+ },
769
+ expectedProgressingCondition : & configv1.ClusterOperatorStatusCondition {
770
+ Type : configv1 .OperatorProgressing ,
771
+ Status : configv1 .ConditionTrue ,
772
+ Reason : "ClusterOperatorsUpdating" ,
773
+ Message : "Working towards 1.2.3: waiting on co-timeout over 30 minutes which is longer than expected" ,
774
+ },
775
+ },
776
+ {
777
+ name : "MultipleErrors: all updating and some slow" ,
778
+ args : args {
779
+ syncWorkerStatus : & SyncWorkerStatus {
780
+ Actual : configv1.Release {Version : "1.2.3" },
781
+ Failure : & payload.UpdateError {
782
+ UpdateEffect : payload .UpdateEffectNone ,
783
+ Reason : "ClusterOperatorsUpdating" ,
784
+ Message : "some-message" ,
785
+ Names : []string {"co-timeout" , "co-bar-timeout" , "co-foo-not-timeout" },
786
+ },
787
+ },
788
+ },
789
+ expectedConditionNotModified : & configv1.ClusterOperatorStatusCondition {
790
+ Type : ClusterStatusFailing ,
791
+ Status : configv1 .ConditionTrue ,
792
+ Reason : "ClusterOperatorsUpdating" ,
793
+ Message : "some-message" ,
794
+ },
795
+ shouldModifyWhenNotReconcilingAndHistoryNotEmpty : true ,
796
+ expectedConditionModified : & configv1.ClusterOperatorStatusCondition {
797
+ Type : ClusterStatusFailing ,
798
+ Status : configv1 .ConditionUnknown ,
799
+ Reason : "SlowClusterOperator" ,
800
+ Message : "waiting on co-timeout, co-bar-timeout over 30 minutes which is longer than expected" ,
801
+ },
802
+ expectedProgressingCondition : & configv1.ClusterOperatorStatusCondition {
803
+ Type : configv1 .OperatorProgressing ,
804
+ Status : configv1 .ConditionTrue ,
805
+ Reason : "ClusterOperatorsUpdating" ,
806
+ Message : "Working towards 1.2.3: waiting on co-timeout, co-bar-timeout over 30 minutes which is longer than expected" ,
807
+ },
808
+ },
809
+ {
810
+ name : "MultipleErrors: all updating and all slow" ,
811
+ args : args {
812
+ syncWorkerStatus : & SyncWorkerStatus {
813
+ Actual : configv1.Release {Version : "1.2.3" },
814
+ Failure : & payload.UpdateError {
815
+ UpdateEffect : payload .UpdateEffectNone ,
816
+ Reason : "ClusterOperatorsUpdating" ,
817
+ Message : "some-message" ,
818
+ Names : []string {"co-timeout" , "co-bar-timeout" , "machine-config" },
819
+ },
820
+ },
821
+ },
822
+ machineConfigTimeout : true ,
823
+ expectedConditionNotModified : & configv1.ClusterOperatorStatusCondition {
824
+ Type : ClusterStatusFailing ,
825
+ Status : configv1 .ConditionTrue ,
826
+ Reason : "ClusterOperatorsUpdating" ,
827
+ Message : "some-message" ,
828
+ },
829
+ shouldModifyWhenNotReconcilingAndHistoryNotEmpty : true ,
830
+ expectedConditionModified : & configv1.ClusterOperatorStatusCondition {
831
+ Type : ClusterStatusFailing ,
832
+ Status : configv1 .ConditionUnknown ,
833
+ Reason : "SlowClusterOperator" ,
834
+ Message : "waiting on co-timeout, co-bar-timeout over 30 minutes and machine-config over 90 minutes which is longer than expected" ,
835
+ },
836
+ expectedProgressingCondition : & configv1.ClusterOperatorStatusCondition {
837
+ Type : configv1 .OperatorProgressing ,
838
+ Status : configv1 .ConditionTrue ,
839
+ Reason : "ClusterOperatorsUpdating" ,
840
+ Message : "Working towards 1.2.3: waiting on co-timeout, co-bar-timeout over 30 minutes and machine-config over 90 minutes which is longer than expected" ,
841
+ },
842
+ },
590
843
}
591
844
for _ , tc := range tests {
592
845
tc := tc
@@ -606,6 +859,11 @@ func TestUpdateClusterVersionStatus_FilteringMultipleErrorsForFailingCondition(t
606
859
{true , false },
607
860
{true , true },
608
861
}
862
+ if tc .machineConfigTimeout {
863
+ payload .COUpdateStartTimesAt ("machine-config" , time .Now ().Add (- 120 * time .Minute ))
864
+ } else {
865
+ payload .COUpdateStartTimesAt ("machine-config" , time .Now ().Add (- 60 * time .Minute ))
866
+ }
609
867
for _ , c := range combinations {
610
868
tc .args .syncWorkerStatus .Reconciling = c .isReconciling
611
869
cvStatus := & configv1.ClusterVersionStatus {}
@@ -621,7 +879,15 @@ func TestUpdateClusterVersionStatus_FilteringMultipleErrorsForFailingCondition(t
621
879
if diff := cmp .Diff (expectedCondition , condition , ignoreLastTransitionTime ); diff != "" {
622
880
t .Errorf ("unexpected condition when Reconciling == %t && isHistoryEmpty == %t\n :%s" , c .isReconciling , c .isHistoryEmpty , diff )
623
881
}
882
+
883
+ if tc .expectedProgressingCondition != nil && ! c .isReconciling && ! c .isHistoryEmpty {
884
+ progressingCondition := resourcemerge .FindOperatorStatusCondition (cvStatus .Conditions , configv1 .OperatorProgressing )
885
+ if diff := cmp .Diff (tc .expectedProgressingCondition , progressingCondition , ignoreLastTransitionTime ); diff != "" {
886
+ t .Errorf ("unexpected progressingCondition when Reconciling == %t && isHistoryEmpty == %t\n :%s" , c .isReconciling , c .isHistoryEmpty , diff )
887
+ }
888
+ }
624
889
}
890
+ payload .COUpdateStartTimesRemove ("machine-config" )
625
891
})
626
892
}
627
893
}
0 commit comments