@@ -5,18 +5,18 @@ import (
5
5
"testing"
6
6
"time"
7
7
8
+ openshiftv1 "github.com/openshift/api/config/v1"
9
+ fakeos "github.com/openshift/client-go/config/clientset/versioned/fake"
10
+ configinformersv1 "github.com/openshift/client-go/config/informers/externalversions"
11
+ "github.com/stretchr/testify/assert"
12
+ appsv1 "k8s.io/api/apps/v1"
8
13
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
9
14
"k8s.io/apimachinery/pkg/runtime"
10
15
"k8s.io/apimachinery/pkg/util/wait"
11
16
"k8s.io/client-go/informers"
12
17
fakekube "k8s.io/client-go/kubernetes/fake"
13
18
"k8s.io/client-go/tools/record"
14
19
"k8s.io/client-go/util/workqueue"
15
-
16
- v1 "github.com/openshift/api/config/v1"
17
- fakeos "github.com/openshift/client-go/config/clientset/versioned/fake"
18
- configinformersv1 "github.com/openshift/client-go/config/informers/externalversions"
19
- "github.com/stretchr/testify/assert"
20
20
)
21
21
22
22
const (
@@ -25,12 +25,12 @@ const (
25
25
hcControllerName = "machine-healthcheck-controller"
26
26
)
27
27
28
- func newFeatureGate (featureSet v1 .FeatureSet ) * v1 .FeatureGate {
29
- return & v1 .FeatureGate {
28
+ func newFeatureGate (featureSet openshiftv1 .FeatureSet ) * openshiftv1 .FeatureGate {
29
+ return & openshiftv1 .FeatureGate {
30
30
ObjectMeta : metav1.ObjectMeta {
31
31
Name : MachineAPIFeatureGateName ,
32
32
},
33
- Spec : v1 .FeatureGateSpec {
33
+ Spec : openshiftv1 .FeatureGateSpec {
34
34
FeatureSet : featureSet ,
35
35
},
36
36
}
@@ -75,7 +75,7 @@ func newFakeOperator(kubeObjects []runtime.Object, osObjects []runtime.Object, s
75
75
kubeNamespacedSharedInformer .Start (stopCh )
76
76
77
77
optr .syncHandler = optr .sync
78
- deployInformer .Informer ().AddEventHandler (optr .eventHandler ())
78
+ deployInformer .Informer ().AddEventHandler (optr .eventHandlerDeployments ())
79
79
featureGateInformer .Informer ().AddEventHandler (optr .eventHandler ())
80
80
81
81
return optr
@@ -85,43 +85,43 @@ func newFakeOperator(kubeObjects []runtime.Object, osObjects []runtime.Object, s
85
85
// for platforms that are no-ops.
86
86
func TestOperatorSync_NoOp (t * testing.T ) {
87
87
cases := []struct {
88
- platform v1 .PlatformType
88
+ platform openshiftv1 .PlatformType
89
89
expectedNoop bool
90
90
}{
91
91
{
92
- platform : v1 .AWSPlatformType ,
92
+ platform : openshiftv1 .AWSPlatformType ,
93
93
expectedNoop : false ,
94
94
},
95
95
{
96
- platform : v1 .LibvirtPlatformType ,
96
+ platform : openshiftv1 .LibvirtPlatformType ,
97
97
expectedNoop : false ,
98
98
},
99
99
{
100
- platform : v1 .OpenStackPlatformType ,
100
+ platform : openshiftv1 .OpenStackPlatformType ,
101
101
expectedNoop : false ,
102
102
},
103
103
{
104
- platform : v1 .AzurePlatformType ,
104
+ platform : openshiftv1 .AzurePlatformType ,
105
105
expectedNoop : false ,
106
106
},
107
107
{
108
- platform : v1 .BareMetalPlatformType ,
108
+ platform : openshiftv1 .BareMetalPlatformType ,
109
109
expectedNoop : false ,
110
110
},
111
111
{
112
- platform : v1 .GCPPlatformType ,
112
+ platform : openshiftv1 .GCPPlatformType ,
113
113
expectedNoop : false ,
114
114
},
115
115
{
116
116
platform : kubemarkPlatform ,
117
117
expectedNoop : false ,
118
118
},
119
119
{
120
- platform : v1 .VSpherePlatformType ,
120
+ platform : openshiftv1 .VSpherePlatformType ,
121
121
expectedNoop : true ,
122
122
},
123
123
{
124
- platform : v1 .NonePlatformType ,
124
+ platform : openshiftv1 .NonePlatformType ,
125
125
expectedNoop : true ,
126
126
},
127
127
{
@@ -132,17 +132,17 @@ func TestOperatorSync_NoOp(t *testing.T) {
132
132
133
133
for _ , tc := range cases {
134
134
t .Run (string (tc .platform ), func (t * testing.T ) {
135
- infra := & v1 .Infrastructure {
135
+ infra := & openshiftv1 .Infrastructure {
136
136
ObjectMeta : metav1.ObjectMeta {
137
137
Name : "cluster" ,
138
138
},
139
- Status : v1 .InfrastructureStatus {
139
+ Status : openshiftv1 .InfrastructureStatus {
140
140
Platform : tc .platform ,
141
141
},
142
142
}
143
143
144
144
stopCh := make (<- chan struct {})
145
- optr := newFakeOperator (nil , []runtime.Object {newFeatureGate (v1 .TechPreviewNoUpgrade ), infra }, stopCh )
145
+ optr := newFakeOperator (nil , []runtime.Object {newFeatureGate (openshiftv1 .TechPreviewNoUpgrade ), infra }, stopCh )
146
146
go optr .Run (2 , stopCh )
147
147
148
148
err := wait .PollImmediate (1 * time .Second , 5 * time .Second , func () (bool , error ) {
@@ -162,15 +162,64 @@ func TestOperatorSync_NoOp(t *testing.T) {
162
162
if ! assert .NoError (t , err , "failed to get clusteroperator" ) {
163
163
t .Fatal ()
164
164
}
165
- expectedConditions := map [v1 .ClusterStatusConditionType ]v1 .ConditionStatus {
166
- v1 .OperatorAvailable : v1 .ConditionTrue ,
167
- v1 .OperatorProgressing : v1 .ConditionFalse ,
168
- v1 .OperatorDegraded : v1 .ConditionFalse ,
169
- v1 .OperatorUpgradeable : v1 .ConditionTrue ,
165
+ expectedConditions := map [openshiftv1 .ClusterStatusConditionType ]openshiftv1 .ConditionStatus {
166
+ openshiftv1 .OperatorAvailable : openshiftv1 .ConditionTrue ,
167
+ openshiftv1 .OperatorProgressing : openshiftv1 .ConditionFalse ,
168
+ openshiftv1 .OperatorDegraded : openshiftv1 .ConditionFalse ,
169
+ openshiftv1 .OperatorUpgradeable : openshiftv1 .ConditionTrue ,
170
170
}
171
171
for _ , c := range o .Status .Conditions {
172
172
assert .Equal (t , expectedConditions [c .Type ], c .Status , fmt .Sprintf ("unexpected clusteroperator condition %s status" , c .Type ))
173
173
}
174
174
})
175
175
}
176
176
}
177
+
178
+ func TestIsOwned (t * testing.T ) {
179
+ testCases := []struct {
180
+ testCase string
181
+ obj interface {}
182
+ expected bool
183
+ expectedError bool
184
+ }{
185
+ {
186
+ testCase : "with maoOwnedAnnotation returns true" ,
187
+ obj : & appsv1.Deployment {
188
+ ObjectMeta : metav1.ObjectMeta {
189
+ Annotations : map [string ]string {
190
+ maoOwnedAnnotation : "" ,
191
+ },
192
+ },
193
+ },
194
+ expected : true ,
195
+ },
196
+ {
197
+ testCase : "with no maoOwnedAnnotation returns false" ,
198
+ obj : & appsv1.Deployment {
199
+ ObjectMeta : metav1.ObjectMeta {
200
+ Annotations : map [string ]string {
201
+ "any" : "" ,
202
+ },
203
+ },
204
+ },
205
+ expected : false ,
206
+ },
207
+ {
208
+ testCase : "bad type object returns error" ,
209
+ obj : "bad object" ,
210
+ expected : false ,
211
+ expectedError : true ,
212
+ },
213
+ }
214
+ for _ , tc := range testCases {
215
+ t .Run (string (tc .testCase ), func (t * testing.T ) {
216
+ got , err := isOwned (tc .obj )
217
+ if got != tc .expected {
218
+ t .Errorf ("Expected: %v, got: %v" , tc .expected , got )
219
+ }
220
+ if tc .expectedError != (err != nil ) {
221
+ t .Errorf ("ExpectedError: %v, got: %v" , tc .expectedError , err )
222
+ }
223
+ })
224
+ }
225
+ }
0 commit comments