@@ -5,6 +5,7 @@ package integration
5
5
import (
6
6
"fmt"
7
7
"testing"
8
+ "time"
8
9
9
10
kapi "k8s.io/kubernetes/pkg/api"
10
11
kclient "k8s.io/kubernetes/pkg/client/unversioned"
@@ -114,17 +115,17 @@ func TestTriggers_imageChange(t *testing.T) {
114
115
115
116
configWatch , err := openshiftProjectAdminClient .DeploymentConfigs (testutil .Namespace ()).Watch (kapi.ListOptions {})
116
117
if err != nil {
117
- t .Fatalf ("Couldn't subscribe to Deployments %v" , err )
118
+ t .Fatalf ("Couldn't subscribe to deploymentconfigs %v" , err )
118
119
}
119
120
defer configWatch .Stop ()
120
121
121
122
if imageStream , err = openshiftProjectAdminClient .ImageStreams (testutil .Namespace ()).Create (imageStream ); err != nil {
122
- t .Fatalf ("Couldn't create ImageStream : %v" , err )
123
+ t .Fatalf ("Couldn't create imagestream : %v" , err )
123
124
}
124
125
125
126
imageWatch , err := openshiftProjectAdminClient .ImageStreams (testutil .Namespace ()).Watch (kapi.ListOptions {})
126
127
if err != nil {
127
- t .Fatalf ("Couldn't subscribe to ImageStreams : %s " , err )
128
+ t .Fatalf ("Couldn't subscribe to imagestreams : %v " , err )
128
129
}
129
130
defer imageWatch .Stop ()
130
131
@@ -147,29 +148,29 @@ func TestTriggers_imageChange(t *testing.T) {
147
148
t .Fatalf ("unexpected error: %v" , err )
148
149
}
149
150
150
- t .Log ("Waiting for image stream mapping to be reflected in the IS status..." )
151
+ t .Log ("Waiting for image stream mapping to be reflected in the image stream status..." )
151
152
statusLoop:
152
153
for {
153
154
select {
154
155
case event := <- imageWatch .ResultChan ():
155
156
stream := event .Object .(* imageapi.ImageStream )
156
157
if _ , ok := stream .Status .Tags [imageapi .DefaultImageTag ]; ok {
157
- t .Logf ("ImageStream %s now has Status with tags: %#v" , stream .Name , stream .Status .Tags )
158
+ t .Logf ("imagestream %q now has status with tags: %#v" , stream .Name , stream .Status .Tags )
158
159
break statusLoop
159
160
}
160
- t .Logf ("Still waiting for latest tag status on ImageStream %s " , stream .Name )
161
+ t .Logf ("Still waiting for latest tag status on imagestream %q " , stream .Name )
161
162
}
162
163
}
163
164
}
164
165
165
166
if config , err = openshiftProjectAdminClient .DeploymentConfigs (testutil .Namespace ()).Create (config ); err != nil {
166
- t .Fatalf ("Couldn't create DeploymentConfig : %v" , err )
167
+ t .Fatalf ("Couldn't create deploymentconfig : %v" , err )
167
168
}
168
169
169
170
createTagEvent ()
170
171
171
172
var newConfig * deployapi.DeploymentConfig
172
- t .Log ("Waiting for a new deployment config in response to ImageStream update" )
173
+ t .Log ("Waiting for a new deployment config in response to imagestream update" )
173
174
waitForNewConfig:
174
175
for {
175
176
select {
@@ -184,12 +185,155 @@ waitForNewConfig:
184
185
}
185
186
break waitForNewConfig
186
187
}
187
- t .Log ("Still waiting for a new deployment config in response to ImageStream update" )
188
+ t .Log ("Still waiting for a new deployment config in response to imagestream update" )
188
189
}
189
190
}
190
191
}
191
192
}
192
193
194
+ func TestTriggers_imageChange_nonAutomatic (t * testing.T ) {
195
+ testutil .RequireEtcd (t )
196
+ _ , clusterAdminKubeConfig , err := testserver .StartTestMaster ()
197
+ if err != nil {
198
+ t .Fatalf ("error starting master: %v" , err )
199
+ }
200
+ openshiftClusterAdminClient , err := testutil .GetClusterAdminClient (clusterAdminKubeConfig )
201
+ if err != nil {
202
+ t .Fatalf ("error getting cluster admin client: %v" , err )
203
+ }
204
+ openshiftClusterAdminClientConfig , err := testutil .GetClusterAdminClientConfig (clusterAdminKubeConfig )
205
+ if err != nil {
206
+ t .Fatalf ("error getting cluster admin client config: %v" , err )
207
+ }
208
+ openshiftProjectAdminClient , err := testserver .CreateNewProject (openshiftClusterAdminClient , * openshiftClusterAdminClientConfig , testutil .Namespace (), "bob" )
209
+ if err != nil {
210
+ t .Fatalf ("error creating project: %v" , err )
211
+ }
212
+
213
+ imageStream := & imageapi.ImageStream {ObjectMeta : kapi.ObjectMeta {Name : deploytest .ImageStreamName }}
214
+
215
+ if imageStream , err = openshiftProjectAdminClient .ImageStreams (testutil .Namespace ()).Create (imageStream ); err != nil {
216
+ t .Fatalf ("Couldn't create imagestream: %v" , err )
217
+ }
218
+
219
+ imageWatch , err := openshiftProjectAdminClient .ImageStreams (testutil .Namespace ()).Watch (kapi.ListOptions {})
220
+ if err != nil {
221
+ t .Fatalf ("Couldn't subscribe to imagestreams: %v" , err )
222
+ }
223
+ defer imageWatch .Stop ()
224
+
225
+ image := fmt .Sprintf ("sha256:%s" , deploytest .ImageID )
226
+ pullSpec := fmt .Sprintf ("registry:8080/%s/%s@%s" , testutil .Namespace (), deploytest .ImageStreamName , image )
227
+ // Make a function which can create a new tag event for the image stream and
228
+ // then wait for the stream status to be asynchronously updated.
229
+ mapping := & imageapi.ImageStreamMapping {
230
+ ObjectMeta : kapi.ObjectMeta {Name : imageStream .Name },
231
+ Tag : imageapi .DefaultImageTag ,
232
+ Image : imageapi.Image {
233
+ ObjectMeta : kapi.ObjectMeta {
234
+ Name : image ,
235
+ },
236
+ DockerImageReference : pullSpec ,
237
+ },
238
+ }
239
+ updated := ""
240
+
241
+ createTagEvent := func (mapping * imageapi.ImageStreamMapping ) {
242
+ if err := openshiftProjectAdminClient .ImageStreamMappings (testutil .Namespace ()).Create (mapping ); err != nil {
243
+ t .Fatalf ("unexpected error: %v" , err )
244
+ }
245
+
246
+ t .Log ("Waiting for image stream mapping to be reflected in the image stream status..." )
247
+
248
+ for {
249
+ select {
250
+ case event := <- imageWatch .ResultChan ():
251
+ stream := event .Object .(* imageapi.ImageStream )
252
+ tagEventList , ok := stream .Status .Tags [imageapi .DefaultImageTag ]
253
+ if ok {
254
+ if updated != tagEventList .Items [0 ].DockerImageReference {
255
+ updated = tagEventList .Items [0 ].DockerImageReference
256
+ return
257
+ }
258
+ }
259
+ t .Logf ("Still waiting for latest tag status update on imagestream %q" , stream .Name )
260
+ }
261
+ }
262
+ }
263
+
264
+ configWatch , err := openshiftProjectAdminClient .DeploymentConfigs (testutil .Namespace ()).Watch (kapi.ListOptions {})
265
+ if err != nil {
266
+ t .Fatalf ("Couldn't subscribe to deploymentconfigs: %v" , err )
267
+ }
268
+ defer configWatch .Stop ()
269
+
270
+ config := deploytest .OkDeploymentConfig (0 )
271
+ config .Namespace = testutil .Namespace ()
272
+ config .Spec .Triggers = []deployapi.DeploymentTriggerPolicy {deploytest .OkImageChangeTrigger ()}
273
+ config .Spec .Triggers [0 ].ImageChangeParams .Automatic = false
274
+ if config , err = openshiftProjectAdminClient .DeploymentConfigs (testutil .Namespace ()).Create (config ); err != nil {
275
+ t .Fatalf ("Couldn't create deploymentconfig: %v" , err )
276
+ }
277
+
278
+ createTagEvent (mapping )
279
+
280
+ var newConfig * deployapi.DeploymentConfig
281
+ t .Log ("Waiting for the initial deploymentconfig update in response to the imagestream update" )
282
+
283
+ timeout := time .After (30 * time .Second )
284
+
285
+ // This is the initial deployment with automatic=false in its ICT - it should be updated to pullSpec
286
+ out:
287
+ for {
288
+ select {
289
+ case event := <- configWatch .ResultChan ():
290
+ if event .Type != watchapi .Modified {
291
+ continue
292
+ }
293
+
294
+ newConfig = event .Object .(* deployapi.DeploymentConfig )
295
+
296
+ if newConfig .Status .LatestVersion > 0 {
297
+ t .Fatalf ("unexpected latestVersion update - the config has no config change trigger" )
298
+ }
299
+
300
+ if e , a := updated , newConfig .Spec .Template .Spec .Containers [0 ].Image ; e == a {
301
+ break out
302
+ }
303
+ case <- timeout :
304
+ t .Fatalf ("timed out waiting for the image update to happen" )
305
+ }
306
+ }
307
+
308
+ t .Log ("Waiting for the second imagestream update - it shouldn't update the deploymentconfig" )
309
+
310
+ // Subsequent updates to the image shouldn't update the pod template image
311
+ mapping .Image .Name = "sha256:thisupdatedimageshouldneverlandinthepodtemplate"
312
+ mapping .Image .DockerImageReference = fmt .Sprintf ("registry:8080/%s/%s@%s" , testutil .Namespace (), deploytest .ImageStreamName , mapping .Image .Name )
313
+ createTagEvent (mapping )
314
+
315
+ for {
316
+ select {
317
+ case event := <- configWatch .ResultChan ():
318
+ if event .Type != watchapi .Modified {
319
+ continue
320
+ }
321
+
322
+ newConfig = event .Object .(* deployapi.DeploymentConfig )
323
+
324
+ if newConfig .Status .LatestVersion > 0 {
325
+ t .Fatalf ("unexpected latestVersion update - the config has no config change trigger" )
326
+ }
327
+
328
+ if e , a := updated , newConfig .Spec .Template .Spec .Containers [0 ].Image ; e == a {
329
+ t .Fatalf ("unexpected image update, expected initial image to be the same" )
330
+ }
331
+ case <- timeout :
332
+ return
333
+ }
334
+ }
335
+ }
336
+
193
337
func TestTriggers_configChange (t * testing.T ) {
194
338
const namespace = "test-triggers-configchange"
195
339
0 commit comments