Skip to content

Commit d983370

Browse files
author
Jim Minter
committed
new-app hidden imagestreams: fix behaviour when no tag is specified
1 parent 5ffd95f commit d983370

File tree

2 files changed

+72
-11
lines changed

2 files changed

+72
-11
lines changed

pkg/generate/app/imagestreamlookup.go

+18-8
Original file line numberDiff line numberDiff line change
@@ -113,21 +113,31 @@ func (r ImageStreamSearcher) Search(precise bool, terms ...string) (ComponentMat
113113
componentMatches = append(componentMatches, match)
114114
}
115115

116-
// When an image stream contains a tag that references another local tag, and the user has not
117-
// provided a tag themselves (i.e. they asked for mysql and we defaulted to mysql:latest), walk
118-
// the chain of references to the end. This ensures that applications can default to using a "stable"
119-
// branch by giving the control over version to the image stream author.
116+
// When the user has not provided a tag themselves (i.e. they asked for
117+
// mysql and we defaulted to mysql:latest), and "latest" references
118+
// another local tag, and neither tag is hidden, use the referenced tag
119+
// instead of "latest". This ensures that applications can default to
120+
// using a "stable" branch by giving the control over version to the
121+
// image stream author.
120122
finalTag := searchTag
121-
if specTag, ok := stream.Spec.Tags[searchTag]; ok && followTag {
123+
if specTag, ok := stream.Spec.Tags[searchTag]; ok && followTag && !specTag.HasAnnotationTag(imageapi.TagReferenceAnnotationTagHidden) {
122124
if specTag.From != nil && specTag.From.Kind == "ImageStreamTag" && !strings.Contains(specTag.From.Name, ":") {
123-
if imageapi.LatestTaggedImage(stream, specTag.From.Name) != nil {
124-
finalTag = specTag.From.Name
125+
if destSpecTag, ok := stream.Spec.Tags[specTag.From.Name]; ok && !destSpecTag.HasAnnotationTag(imageapi.TagReferenceAnnotationTagHidden) {
126+
if imageapi.LatestTaggedImage(stream, specTag.From.Name) != nil {
127+
finalTag = specTag.From.Name
128+
}
125129
}
126130
}
127131
}
128132

129133
latest := imageapi.LatestTaggedImage(stream, finalTag)
130-
if latest == nil || len(latest.Image) == 0 {
134+
135+
// Special case in addition to the other tag not found cases: if no tag
136+
// was specified, and "latest" is hidden, then behave as if "latest"
137+
// doesn't exist (in this case, to get to "latest", the user must hard
138+
// specify tag "latest").
139+
if specTag, ok := stream.Spec.Tags[searchTag]; (ok && followTag && specTag.HasAnnotationTag(imageapi.TagReferenceAnnotationTagHidden)) ||
140+
latest == nil || len(latest.Image) == 0 {
131141

132142
glog.V(2).Infof("no image recorded for %s/%s:%s", stream.Namespace, stream.Name, finalTag)
133143
if r.AllowMissingTags {

pkg/generate/app/imagestreamlookup_test.go

+54-3
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,38 @@ func TestImageStreamSearcher(t *testing.T) {
136136
},
137137
},
138138
},
139+
&fakeImageStreamDesc{
140+
name: "nodejs3",
141+
tags: map[string]imageapi.TagReference{
142+
"4": {
143+
Annotations: map[string]string{
144+
"supports": "nodejs3:4,nodejs3",
145+
"tags": "hidden",
146+
},
147+
},
148+
},
149+
latest: "4",
150+
},
151+
&fakeImageStreamDesc{
152+
name: "nodejs4",
153+
tags: map[string]imageapi.TagReference{
154+
"0.10": {
155+
Annotations: map[string]string{
156+
"supports": "nodejs4:0.10,nodejs4:0.1,nodejs4",
157+
},
158+
},
159+
"4": {
160+
Annotations: map[string]string{
161+
"supports": "nodejs4:4,nodejs4",
162+
"tags": "hidden",
163+
},
164+
},
165+
},
166+
latest: "4",
167+
latestannotations: map[string]string{
168+
"tags": "hidden",
169+
},
170+
},
139171
&fakeImageStreamDesc{
140172
name: "ruby20",
141173
tags: map[string]imageapi.TagReference{
@@ -194,6 +226,16 @@ func TestImageStreamSearcher(t *testing.T) {
194226
value: "nodejs2",
195227
expectMatch: false,
196228
},
229+
{
230+
value: "nodejs3",
231+
expectMatch: true,
232+
expectTag: "latest",
233+
},
234+
{
235+
value: "nodejs4",
236+
expectMatch: true,
237+
expectTag: "0.10",
238+
},
197239
}
198240

199241
for _, test := range tests {
@@ -358,9 +400,10 @@ func TestAnnotationMatches(t *testing.T) {
358400
}
359401

360402
type fakeImageStreamDesc struct {
361-
name string
362-
tags map[string]imageapi.TagReference
363-
latest string
403+
name string
404+
tags map[string]imageapi.TagReference
405+
latest string
406+
latestannotations map[string]string
364407
}
365408

366409
func fakeImageStreams(descs ...*fakeImageStreamDesc) (*imageapi.ImageStreamList, map[string]*imageapi.ImageStreamImage) {
@@ -415,6 +458,14 @@ func fakeImageStream(desc *fakeImageStreamDesc) (*imageapi.ImageStream, map[stri
415458
Name: desc.latest,
416459
Namespace: "namespace",
417460
},
461+
Annotations: desc.latestannotations,
462+
}
463+
stream.Status.Tags["latest"] = imageapi.TagEventList{
464+
Items: []imageapi.TagEvent{
465+
{
466+
Image: desc.latest + "-image",
467+
},
468+
},
418469
}
419470
}
420471
return stream, images

0 commit comments

Comments
 (0)