@@ -20,6 +20,9 @@ import (
2020 "k8s.io/client-go/kubernetes/scheme"
2121 ktesting "k8s.io/client-go/testing"
2222
23+ "sigs.k8s.io/controller-runtime/pkg/client"
24+ clientfake "sigs.k8s.io/controller-runtime/pkg/client/fake"
25+
2326 configv1 "github.com/openshift/api/config/v1"
2427 machinev1beta1 "github.com/openshift/api/machine/v1beta1"
2528 operatorv1 "github.com/openshift/api/operator/v1"
@@ -29,8 +32,10 @@ import (
2932 cloudcredentialv1 "github.com/openshift/cloud-credential-operator/pkg/apis/cloudcredential/v1"
3033
3134 "github.com/Azure/ARO-RP/pkg/api"
35+ "github.com/Azure/ARO-RP/pkg/util/clienthelper"
3236 "github.com/Azure/ARO-RP/pkg/util/pointerutils"
3337 utilerror "github.com/Azure/ARO-RP/test/util/error"
38+ testlog "github.com/Azure/ARO-RP/test/util/log"
3439)
3540
3641const errMustBeNilMsg = "err must be nil; condition is retried until timeout"
@@ -413,74 +418,229 @@ func TestAroCredentialsRequestReconciled(t *testing.T) {
413418 }
414419}
415420
416- func TestApiServersReadyAfterCertificateConfig (t * testing.T ) {
421+ func TestHaveClusterOperatorsSettled (t * testing.T ) {
417422 ctx := context .Background ()
418423
419424 for _ , tt := range []struct {
420- name string
421- availableCondition configv1.ConditionStatus
422- progressingCondition configv1.ConditionStatus
423- degradedCondition configv1.ConditionStatus
424- want bool
425+ name string
426+ apiserverConditions []configv1.ClusterOperatorStatusCondition
427+ kubeControllerConditions []configv1.ClusterOperatorStatusCondition
428+ want bool
425429 }{
426430 {
427- name : "Available, not progressing, not degraded - ready" ,
428- availableCondition : configv1 .ConditionTrue ,
429- progressingCondition : configv1 .ConditionFalse ,
430- degradedCondition : configv1 .ConditionFalse ,
431- want : true ,
431+ name : "APIServer Available, not progressing, KCM OK - ready" ,
432+ apiserverConditions : []configv1.ClusterOperatorStatusCondition {
433+ {
434+ Type : configv1 .OperatorAvailable ,
435+ Status : configv1 .ConditionTrue ,
436+ },
437+ {
438+ Type : configv1 .OperatorProgressing ,
439+ Status : configv1 .ConditionFalse ,
440+ },
441+ {
442+ Type : configv1 .OperatorDegraded ,
443+ Status : configv1 .ConditionFalse ,
444+ },
445+ },
446+ kubeControllerConditions : []configv1.ClusterOperatorStatusCondition {
447+ {
448+ Type : configv1 .OperatorAvailable ,
449+ Status : configv1 .ConditionTrue ,
450+ },
451+ {
452+ Type : configv1 .OperatorProgressing ,
453+ Status : configv1 .ConditionFalse ,
454+ },
455+ {
456+ Type : configv1 .OperatorDegraded ,
457+ Status : configv1 .ConditionFalse ,
458+ },
459+ },
460+ want : true ,
432461 },
433462 {
434- name : "Available but still progressing - not ready" ,
435- availableCondition : configv1 .ConditionTrue ,
436- progressingCondition : configv1 .ConditionTrue ,
437- degradedCondition : configv1 .ConditionFalse ,
438- want : false ,
463+ name : "APIServer OK, KCM degraded - not ready" ,
464+ apiserverConditions : []configv1.ClusterOperatorStatusCondition {
465+ {
466+ Type : configv1 .OperatorAvailable ,
467+ Status : configv1 .ConditionTrue ,
468+ },
469+ {
470+ Type : configv1 .OperatorProgressing ,
471+ Status : configv1 .ConditionFalse ,
472+ },
473+ {
474+ Type : configv1 .OperatorDegraded ,
475+ Status : configv1 .ConditionFalse ,
476+ },
477+ },
478+ kubeControllerConditions : []configv1.ClusterOperatorStatusCondition {
479+ {
480+ Type : configv1 .OperatorAvailable ,
481+ Status : configv1 .ConditionTrue ,
482+ },
483+ {
484+ Type : configv1 .OperatorProgressing ,
485+ Status : configv1 .ConditionFalse ,
486+ },
487+ {
488+ Type : configv1 .OperatorDegraded ,
489+ Status : configv1 .ConditionTrue ,
490+ },
491+ },
492+ want : false ,
439493 },
440494 {
441- name : "Available but degraded - not ready" ,
442- availableCondition : configv1 .ConditionTrue ,
443- progressingCondition : configv1 .ConditionFalse ,
444- degradedCondition : configv1 .ConditionTrue ,
445- want : false ,
495+ name : "APIServer Available but still progressing, KCM OK - not ready" ,
496+ apiserverConditions : []configv1.ClusterOperatorStatusCondition {
497+ {
498+ Type : configv1 .OperatorAvailable ,
499+ Status : configv1 .ConditionTrue ,
500+ },
501+ {
502+ Type : configv1 .OperatorProgressing ,
503+ Status : configv1 .ConditionTrue ,
504+ },
505+ {
506+ Type : configv1 .OperatorDegraded ,
507+ Status : configv1 .ConditionFalse ,
508+ },
509+ },
510+ kubeControllerConditions : []configv1.ClusterOperatorStatusCondition {
511+ {
512+ Type : configv1 .OperatorAvailable ,
513+ Status : configv1 .ConditionTrue ,
514+ },
515+ {
516+ Type : configv1 .OperatorProgressing ,
517+ Status : configv1 .ConditionFalse ,
518+ },
519+ {
520+ Type : configv1 .OperatorDegraded ,
521+ Status : configv1 .ConditionFalse ,
522+ },
523+ },
524+ want : false ,
525+ },
526+ {
527+ name : "APIServer Available but degraded, KCM OK - not ready" ,
528+ apiserverConditions : []configv1.ClusterOperatorStatusCondition {
529+ {
530+ Type : configv1 .OperatorAvailable ,
531+ Status : configv1 .ConditionTrue ,
532+ },
533+ {
534+ Type : configv1 .OperatorProgressing ,
535+ Status : configv1 .ConditionFalse ,
536+ },
537+ {
538+ Type : configv1 .OperatorDegraded ,
539+ Status : configv1 .ConditionTrue ,
540+ },
541+ },
542+ kubeControllerConditions : []configv1.ClusterOperatorStatusCondition {
543+ {
544+ Type : configv1 .OperatorAvailable ,
545+ Status : configv1 .ConditionTrue ,
546+ },
547+ {
548+ Type : configv1 .OperatorProgressing ,
549+ Status : configv1 .ConditionFalse ,
550+ },
551+ {
552+ Type : configv1 .OperatorDegraded ,
553+ Status : configv1 .ConditionFalse ,
554+ },
555+ },
556+ want : false ,
446557 },
447558 {
448- name : "Not available - not ready" ,
449- availableCondition : configv1 .ConditionFalse ,
450- progressingCondition : configv1 .ConditionFalse ,
451- degradedCondition : configv1 .ConditionFalse ,
452- want : false ,
559+ name : "APIServer Not available, KCM OK - not ready" ,
560+ apiserverConditions : []configv1.ClusterOperatorStatusCondition {
561+ {
562+ Type : configv1 .OperatorAvailable ,
563+ Status : configv1 .ConditionFalse ,
564+ },
565+ {
566+ Type : configv1 .OperatorProgressing ,
567+ Status : configv1 .ConditionFalse ,
568+ },
569+ {
570+ Type : configv1 .OperatorDegraded ,
571+ Status : configv1 .ConditionFalse ,
572+ },
573+ },
574+ kubeControllerConditions : []configv1.ClusterOperatorStatusCondition {
575+ {
576+ Type : configv1 .OperatorAvailable ,
577+ Status : configv1 .ConditionTrue ,
578+ },
579+ {
580+ Type : configv1 .OperatorProgressing ,
581+ Status : configv1 .ConditionFalse ,
582+ },
583+ {
584+ Type : configv1 .OperatorDegraded ,
585+ Status : configv1 .ConditionFalse ,
586+ },
587+ },
588+ want : false ,
453589 },
454590 } {
455591 t .Run (tt .name , func (t * testing.T ) {
456- configcli := configfake .NewSimpleClientset (& configv1.ClusterOperator {
457- ObjectMeta : metav1.ObjectMeta {
458- Name : "kube-apiserver" ,
592+ objects := []client.Object {
593+ & configv1.ClusterOperator {
594+ ObjectMeta : metav1.ObjectMeta {
595+ Name : "kube-apiserver" ,
596+ },
597+ Status : configv1.ClusterOperatorStatus {
598+ Conditions : tt .apiserverConditions ,
599+ },
459600 },
460- Status : configv1.ClusterOperatorStatus {
461- Conditions : []configv1.ClusterOperatorStatusCondition {
462- {
463- Type : configv1 .OperatorAvailable ,
464- Status : tt .availableCondition ,
465- },
466- {
467- Type : configv1 .OperatorProgressing ,
468- Status : tt .progressingCondition ,
469- },
470- {
471- Type : configv1 .OperatorDegraded ,
472- Status : tt .degradedCondition ,
601+ & configv1.ClusterOperator {
602+ ObjectMeta : metav1.ObjectMeta {
603+ Name : "kube-controller-manager" ,
604+ },
605+ Status : configv1.ClusterOperatorStatus {
606+ Conditions : tt .kubeControllerConditions ,
607+ },
608+ },
609+ // this being degraded should not affect the APIServer
610+ & configv1.ClusterOperator {
611+ ObjectMeta : metav1.ObjectMeta {
612+ Name : "kube-widget-operator" ,
613+ },
614+ Status : configv1.ClusterOperatorStatus {
615+ Conditions : []configv1.ClusterOperatorStatusCondition {
616+ {
617+ Type : configv1 .OperatorAvailable ,
618+ Status : configv1 .ConditionFalse ,
619+ },
620+ {
621+ Type : configv1 .OperatorProgressing ,
622+ Status : configv1 .ConditionTrue ,
623+ },
624+ {
625+ Type : configv1 .OperatorDegraded ,
626+ Status : configv1 .ConditionTrue ,
627+ },
473628 },
474629 },
475630 },
476- })
631+ }
632+ _ , log := testlog .New ()
633+ ch := clienthelper .NewWithClient (log , clientfake .
634+ NewClientBuilder ().
635+ WithObjects (objects ... ).
636+ Build ())
477637
478638 m := & manager {
479- log : logrus . NewEntry ( logrus . StandardLogger ()) ,
480- configcli : configcli ,
639+ log : log ,
640+ ch : ch ,
481641 }
482642
483- result , err := m .apiServersReadyAfterCertificateConfig (ctx )
643+ result , err := m .clusterOperatorsHaveSettled (ctx )
484644 if err != nil {
485645 t .Errorf ("Unexpected error: %v" , err )
486646 }
0 commit comments