Skip to content

Commit 3c5875f

Browse files
Merge pull request #15145 from kargakis/fix-instantiating-templates-with-real-images-master
Update lastTriggeredImage if not set when instantiating DCs
2 parents 4c51c95 + 56c4920 commit 3c5875f

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

pkg/deploy/registry/instantiate/rest.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func processTriggers(config *deployapi.DeploymentConfig, isn client.ImageStreams
164164
if !names.Has(container.Name) {
165165
continue
166166
}
167-
if container.Image != latestReference {
167+
if container.Image != latestReference || params.LastTriggeredImage != latestReference {
168168
// Update the image
169169
container.Image = latestReference
170170
// Log the last triggered image ID
@@ -176,7 +176,7 @@ func processTriggers(config *deployapi.DeploymentConfig, isn client.ImageStreams
176176
if !names.Has(container.Name) {
177177
continue
178178
}
179-
if container.Image != latestReference {
179+
if container.Image != latestReference || params.LastTriggeredImage != latestReference {
180180
// Update the image
181181
container.Image = latestReference
182182
// Log the last triggered image ID

pkg/deploy/registry/instantiate/rest_test.go

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,9 @@ func TestProcess_matchScenarios(t *testing.T) {
134134
tests := []struct {
135135
name string
136136

137-
param *deployapi.DeploymentTriggerImageChangeParams
138-
notFound bool
137+
param *deployapi.DeploymentTriggerImageChangeParams
138+
containerImageFunc func() string
139+
notFound bool
139140

140141
expected bool
141142
}{
@@ -212,6 +213,23 @@ func TestProcess_matchScenarios(t *testing.T) {
212213

213214
expected: false,
214215
},
216+
{
217+
name: "allow lastTriggeredImage to resolve",
218+
219+
containerImageFunc: func() string {
220+
image := "registry:5000/openshift/test-image-stream@sha256:0000000000000000000000000000000000000000000000000000000000000001"
221+
return image
222+
},
223+
param: &deployapi.DeploymentTriggerImageChangeParams{
224+
Automatic: true,
225+
ContainerNames: []string{"container1"},
226+
From: kapi.ObjectReference{Name: imageapi.JoinImageStreamTag(deploytest.ImageStreamName, imageapi.DefaultImageTag)},
227+
LastTriggeredImage: "",
228+
},
229+
notFound: false,
230+
231+
expected: true,
232+
},
215233
}
216234

217235
for i := range tests {
@@ -237,17 +255,26 @@ func TestProcess_matchScenarios(t *testing.T) {
237255
},
238256
}
239257

258+
if test.containerImageFunc != nil {
259+
config.Spec.Template.Spec.Containers[0].Image = test.containerImageFunc()
260+
}
240261
image := config.Spec.Template.Spec.Containers[0].Image
241262

242263
err := processTriggers(config, fake, false, nil)
243264
if err != nil {
244265
t.Errorf("unexpected error: %v", err)
245266
continue
246267
}
247-
if test.expected && config.Spec.Template.Spec.Containers[0].Image == image {
268+
if test.containerImageFunc == nil && test.expected && config.Spec.Template.Spec.Containers[0].Image == image {
248269
t.Errorf("%s: expected an image update but got none", test.name)
249-
} else if !test.expected && config.Spec.Template.Spec.Containers[0].Image != image {
270+
continue
271+
}
272+
if !test.expected && config.Spec.Template.Spec.Containers[0].Image != image {
250273
t.Errorf("%s: didn't expect an image update but got %s", test.name, image)
274+
continue
275+
}
276+
if test.containerImageFunc != nil && image != config.Spec.Triggers[0].ImageChangeParams.LastTriggeredImage {
277+
t.Errorf("%s: expected a lastTriggeredImage update to %q, got none", test.name, image)
251278
}
252279
}
253280
}

0 commit comments

Comments
 (0)