@@ -15,6 +15,7 @@ import (
1515 operatorv1 "github.com/openshift/api/operator/v1"
1616 "github.com/openshift/library-go/pkg/controller/factory"
1717 "github.com/openshift/library-go/pkg/operator/events"
18+ "github.com/openshift/library-go/pkg/operator/status"
1819 "github.com/openshift/library-go/pkg/operator/v1helpers"
1920 appsv1 "k8s.io/api/apps/v1"
2021 "k8s.io/apimachinery/pkg/api/equality"
@@ -57,13 +58,15 @@ func TestUpdateOperatorStatus(t *testing.T) {
5758
5859 workload * appsv1.Deployment
5960 pods []* corev1.Pod
61+ podListErr error
6062 operatorConfigAtHighestRevision bool
6163 operatorPreconditionsNotReady bool
6264 preconditionError error
6365 errors []error
6466 previousConditions []operatorv1.OperatorCondition
6567
66- validateOperatorStatus func (* operatorv1.OperatorStatus ) error
68+ validateOperatorStatus func (* operatorv1.OperatorStatus ) error
69+ validateVersionRecorder func (status.VersionGetter ) error
6770 }{
6871 {
6972 name : "scenario: no workload, no errors thus we are degraded and we are progressing" ,
@@ -112,7 +115,7 @@ func TestUpdateOperatorStatus(t *testing.T) {
112115 {
113116 Type : fmt .Sprintf ("%sWorkloadDegraded" , defaultControllerName ),
114117 Status : operatorv1 .ConditionTrue ,
115- Message : "nasty error\n " ,
118+ Message : "nasty error" ,
116119 Reason : "SyncError" ,
117120 },
118121 {
@@ -140,7 +143,6 @@ func TestUpdateOperatorStatus(t *testing.T) {
140143 Namespace : "openshift-apiserver" ,
141144 },
142145 Spec : appsv1.DeploymentSpec {
143- Template : corev1.PodTemplateSpec {ObjectMeta : metav1.ObjectMeta {Labels : map [string ]string {"foo" : "bar" }}},
144146 Replicas : ptr.To [int32 ](3 ),
145147 },
146148 Status : appsv1.DeploymentStatus {
@@ -152,7 +154,7 @@ func TestUpdateOperatorStatus(t *testing.T) {
152154 },
153155 pods : []* corev1.Pod {
154156 {
155- ObjectMeta : metav1.ObjectMeta {Name : "apiserver" , Namespace : "openshift-apiserver" , Labels : map [ string ] string { "foo" : "bar" } },
157+ ObjectMeta : metav1.ObjectMeta {Name : "apiserver" , Namespace : "openshift-apiserver" },
156158 Status : corev1.PodStatus {
157159 Phase : corev1 .PodPending ,
158160 ContainerStatuses : []corev1.ContainerStatus {
@@ -214,7 +216,6 @@ func TestUpdateOperatorStatus(t *testing.T) {
214216 Namespace : "openshift-apiserver" ,
215217 },
216218 Spec : appsv1.DeploymentSpec {
217- Template : corev1.PodTemplateSpec {ObjectMeta : metav1.ObjectMeta {Labels : map [string ]string {"foo" : "bar" }}},
218219 Replicas : ptr.To [int32 ](3 ),
219220 },
220221 Status : appsv1.DeploymentStatus {
@@ -226,7 +227,7 @@ func TestUpdateOperatorStatus(t *testing.T) {
226227 },
227228 pods : []* corev1.Pod {
228229 {
229- ObjectMeta : metav1.ObjectMeta {Name : "apiserver" , Namespace : "openshift-apiserver" , Labels : map [ string ] string { "foo" : "bar" } },
230+ ObjectMeta : metav1.ObjectMeta {Name : "apiserver" , Namespace : "openshift-apiserver" },
230231 Status : corev1.PodStatus {
231232 Phase : corev1 .PodPending ,
232233 ContainerStatuses : []corev1.ContainerStatus {
@@ -287,7 +288,6 @@ func TestUpdateOperatorStatus(t *testing.T) {
287288 Namespace : "openshift-apiserver" ,
288289 },
289290 Spec : appsv1.DeploymentSpec {
290- Template : corev1.PodTemplateSpec {ObjectMeta : metav1.ObjectMeta {Labels : map [string ]string {"foo" : "bar" }}},
291291 Replicas : ptr.To [int32 ](3 ),
292292 },
293293 Status : appsv1.DeploymentStatus {
@@ -635,8 +635,6 @@ func TestUpdateOperatorStatus(t *testing.T) {
635635 Namespace : "openshift-apiserver" ,
636636 },
637637 Spec : appsv1.DeploymentSpec {
638- Selector : & metav1.LabelSelector {MatchLabels : map [string ]string {"foo" : "bar" }},
639- Template : corev1.PodTemplateSpec {ObjectMeta : metav1.ObjectMeta {Labels : map [string ]string {"foo" : "bar" }}},
640638 Replicas : ptr.To [int32 ](3 ),
641639 },
642640 Status : appsv1.DeploymentStatus {
@@ -704,16 +702,20 @@ func TestUpdateOperatorStatus(t *testing.T) {
704702 syncErrrors : scenario .errors ,
705703 }
706704
705+ versionRecorder := status .NewVersionGetter ()
706+
707707 // act
708708 target := & Controller {
709- operatorClient : fakeOperatorClient ,
710- targetNamespace : targetNs ,
711- podsLister : & fakePodLister {pods : scenario .pods },
712- delegate : delegate ,
709+ operatorClient : fakeOperatorClient ,
710+ targetNamespace : targetNs ,
711+ targetOperandVersion : "v1.0.0-test" ,
712+ podsLister : & fakePodLister {pods : scenario .pods , err : scenario .podListErr },
713+ delegate : delegate ,
714+ versionRecorder : versionRecorder ,
713715 }
714716
715717 err := target .sync (context .TODO (), factory .NewSyncContext ("workloadcontroller_test" , events .NewInMemoryRecorder ("workloadcontroller_test" , clocktesting .NewFakePassiveClock (time .Now ()))))
716- if err != nil && len (scenario .errors ) == 0 {
718+ if err != nil && len (scenario .errors ) == 0 && scenario . podListErr == nil {
717719 t .Fatal (err )
718720 }
719721
@@ -726,28 +728,34 @@ func TestUpdateOperatorStatus(t *testing.T) {
726728 if err != nil {
727729 t .Fatal (err )
728730 }
731+ if scenario .validateVersionRecorder != nil {
732+ if err := scenario .validateVersionRecorder (versionRecorder ); err != nil {
733+ t .Fatal (err )
734+ }
735+ }
729736 })
730737 }
731738}
732739
733740type fakePodLister struct {
734741 pods []* corev1.Pod
742+ err error
735743}
736744
737745type fakePodNamespaceLister struct {
738746 lister * fakePodLister
739747}
740748
741749func (f * fakePodNamespaceLister ) List (selector labels.Selector ) (ret []* corev1.Pod , err error ) {
742- return f .lister .pods , nil
750+ return f .lister .pods , f . lister . err
743751}
744752
745753func (f * fakePodNamespaceLister ) Get (name string ) (* corev1.Pod , error ) {
746754 panic ("implement me" )
747755}
748756
749757func (f * fakePodLister ) List (selector labels.Selector ) (ret []* corev1.Pod , err error ) {
750- return f .pods , nil
758+ return f .pods , f . err
751759}
752760
753761func (f * fakePodLister ) Pods (namespace string ) corev1listers.PodNamespaceLister {
0 commit comments