@@ -94,3 +94,179 @@ func TestPodContainerSecurityContext(t *testing.T) {
94
94
gotContainerSecCtx := gotPod .Spec .Containers [0 ].SecurityContext
95
95
require .Equal (t , expectedContainerSecCtx , gotContainerSecCtx )
96
96
}
97
+
98
+ func TestPodSchedulingOverrides (t * testing.T ) {
99
+ // This test ensures that any overriding pod scheduling configuration elements
100
+ // defined in spec.grpcPodConfig are applied to the catalog source pod created
101
+ // when spec.sourceType = 'grpc' and spec.image is set.
102
+ var tolerationSeconds int64 = 120
103
+ var overriddenPriorityClassName = "some-prio-class"
104
+ var overriddenNodeSelectors = map [string ]string {
105
+ "label" : "value" ,
106
+ "label2" : "value2" ,
107
+ }
108
+ var defaultNodeSelectors = map [string ]string {
109
+ "kubernetes.io/os" : "linux" ,
110
+ }
111
+ var defaultPriorityClassName = ""
112
+
113
+ var overriddenTolerations = []corev1.Toleration {
114
+ {
115
+ Key : "some/key" ,
116
+ Operator : corev1 .TolerationOpExists ,
117
+ Effect : corev1 .TaintEffectNoExecute ,
118
+ TolerationSeconds : & tolerationSeconds ,
119
+ },
120
+ {
121
+ Key : "someother/key" ,
122
+ Operator : corev1 .TolerationOpEqual ,
123
+ Effect : corev1 .TaintEffectNoSchedule ,
124
+ },
125
+ }
126
+
127
+ testCases := []struct {
128
+ title string
129
+ catalogSource * v1alpha1.CatalogSource
130
+ expectedNodeSelectors map [string ]string
131
+ expectedTolerations []corev1.Toleration
132
+ expectedPriorityClassName string
133
+ annotations map [string ]string
134
+ }{
135
+ {
136
+ title : "no overrides" ,
137
+ catalogSource : & v1alpha1.CatalogSource {
138
+ ObjectMeta : metav1.ObjectMeta {
139
+ Name : "test" ,
140
+ Namespace : "testns" ,
141
+ },
142
+ Spec : v1alpha1.CatalogSourceSpec {
143
+ SourceType : v1alpha1 .SourceTypeGrpc ,
144
+ Image : "repo/image:tag" ,
145
+ },
146
+ },
147
+ expectedTolerations : nil ,
148
+ expectedPriorityClassName : defaultPriorityClassName ,
149
+ expectedNodeSelectors : defaultNodeSelectors ,
150
+ }, {
151
+ title : "override node selectors" ,
152
+ catalogSource : & v1alpha1.CatalogSource {
153
+ ObjectMeta : metav1.ObjectMeta {
154
+ Name : "test" ,
155
+ Namespace : "testns" ,
156
+ },
157
+ Spec : v1alpha1.CatalogSourceSpec {
158
+ SourceType : v1alpha1 .SourceTypeGrpc ,
159
+ Image : "repo/image:tag" ,
160
+ GrpcPodConfig : & v1alpha1.GrpcPodConfig {
161
+ NodeSelector : overriddenNodeSelectors ,
162
+ },
163
+ },
164
+ },
165
+ expectedTolerations : nil ,
166
+ expectedPriorityClassName : defaultPriorityClassName ,
167
+ expectedNodeSelectors : overriddenNodeSelectors ,
168
+ }, {
169
+ title : "override priority class name" ,
170
+ catalogSource : & v1alpha1.CatalogSource {
171
+ ObjectMeta : metav1.ObjectMeta {
172
+ Name : "test" ,
173
+ Namespace : "testns" ,
174
+ },
175
+ Spec : v1alpha1.CatalogSourceSpec {
176
+ SourceType : v1alpha1 .SourceTypeGrpc ,
177
+ Image : "repo/image:tag" ,
178
+ GrpcPodConfig : & v1alpha1.GrpcPodConfig {
179
+ PriorityClassName : & overriddenPriorityClassName ,
180
+ },
181
+ },
182
+ },
183
+ expectedTolerations : nil ,
184
+ expectedPriorityClassName : overriddenPriorityClassName ,
185
+ expectedNodeSelectors : defaultNodeSelectors ,
186
+ }, {
187
+ title : "doesn't override priority class name when its nil" ,
188
+ catalogSource : & v1alpha1.CatalogSource {
189
+ ObjectMeta : metav1.ObjectMeta {
190
+ Name : "test" ,
191
+ Namespace : "testns" ,
192
+ },
193
+ Spec : v1alpha1.CatalogSourceSpec {
194
+ SourceType : v1alpha1 .SourceTypeGrpc ,
195
+ Image : "repo/image:tag" ,
196
+ GrpcPodConfig : & v1alpha1.GrpcPodConfig {
197
+ PriorityClassName : nil ,
198
+ },
199
+ },
200
+ },
201
+ expectedTolerations : nil ,
202
+ expectedPriorityClassName : defaultPriorityClassName ,
203
+ expectedNodeSelectors : defaultNodeSelectors ,
204
+ }, {
205
+ title : "Override node tolerations" ,
206
+ catalogSource : & v1alpha1.CatalogSource {
207
+ ObjectMeta : metav1.ObjectMeta {
208
+ Name : "test" ,
209
+ Namespace : "testns" ,
210
+ },
211
+ Spec : v1alpha1.CatalogSourceSpec {
212
+ SourceType : v1alpha1 .SourceTypeGrpc ,
213
+ Image : "repo/image:tag" ,
214
+ GrpcPodConfig : & v1alpha1.GrpcPodConfig {
215
+ Tolerations : overriddenTolerations ,
216
+ },
217
+ },
218
+ },
219
+ expectedTolerations : overriddenTolerations ,
220
+ expectedPriorityClassName : defaultPriorityClassName ,
221
+ expectedNodeSelectors : defaultNodeSelectors ,
222
+ }, {
223
+ title : "Override all the things" ,
224
+ catalogSource : & v1alpha1.CatalogSource {
225
+ ObjectMeta : metav1.ObjectMeta {
226
+ Name : "test" ,
227
+ Namespace : "testns" ,
228
+ },
229
+ Spec : v1alpha1.CatalogSourceSpec {
230
+ SourceType : v1alpha1 .SourceTypeGrpc ,
231
+ Image : "repo/image:tag" ,
232
+ GrpcPodConfig : & v1alpha1.GrpcPodConfig {
233
+ NodeSelector : overriddenNodeSelectors ,
234
+ PriorityClassName : & overriddenPriorityClassName ,
235
+ Tolerations : overriddenTolerations ,
236
+ },
237
+ },
238
+ },
239
+ expectedTolerations : overriddenTolerations ,
240
+ expectedPriorityClassName : overriddenPriorityClassName ,
241
+ expectedNodeSelectors : overriddenNodeSelectors ,
242
+ }, {
243
+ title : "priorityClassName annotation takes precedence" ,
244
+ catalogSource : & v1alpha1.CatalogSource {
245
+ ObjectMeta : metav1.ObjectMeta {
246
+ Name : "test" ,
247
+ Namespace : "testns" ,
248
+ },
249
+ Spec : v1alpha1.CatalogSourceSpec {
250
+ SourceType : v1alpha1 .SourceTypeGrpc ,
251
+ Image : "repo/image:tag" ,
252
+ GrpcPodConfig : & v1alpha1.GrpcPodConfig {
253
+ PriorityClassName : & overriddenPriorityClassName ,
254
+ },
255
+ },
256
+ },
257
+ expectedTolerations : nil ,
258
+ annotations : map [string ]string {
259
+ CatalogPriorityClassKey : "some-OTHER-prio-class" ,
260
+ },
261
+ expectedPriorityClassName : "some-OTHER-prio-class" ,
262
+ expectedNodeSelectors : defaultNodeSelectors ,
263
+ },
264
+ }
265
+
266
+ for _ , testCase := range testCases {
267
+ pod := Pod (testCase .catalogSource , "hello" , "busybox" , "" , map [string ]string {}, testCase .annotations , int32 (0 ), int32 (0 ))
268
+ require .Equal (t , testCase .expectedNodeSelectors , pod .Spec .NodeSelector )
269
+ require .Equal (t , testCase .expectedPriorityClassName , pod .Spec .PriorityClassName )
270
+ require .Equal (t , testCase .expectedTolerations , pod .Spec .Tolerations )
271
+ }
272
+ }
0 commit comments