-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
build: take referencePolicy into account when resolving istag #12767
build: take referencePolicy into account when resolving istag #12767
Conversation
[test] |
3579a13
to
a3d4df7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, handle "ImageStreamImage"
as well. It's more common in cluster.
If the image is tagged exactly once (or even multiple times) in the image stream with local resolve policy, it shall be honored.
a3d4df7
to
d1b7d03
Compare
Status: imageapi.ImageStreamStatus{ | ||
DockerImageRepository: originalImage, | ||
Tags: map[string]imageapi.TagEventList{ | ||
"tag1": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bparees this looks ugly but I haven't found a better way to inject the tag the trigger expects to change :-)
@@ -1421,7 +1453,7 @@ func TestResolveImageStreamRef(t *testing.T) { | |||
Name: imageRepoName + ":" + tagName, | |||
}, | |||
expectedSuccess: true, | |||
expectedDockerRef: latestDockerReference, | |||
expectedDockerRef: dockerReference, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bparees this one is weird... you are trying to resolve the "foo:test" to "foo:latestDockerReference", can you or somebody explain the intention of this test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we're trying to resolve the image stream tag "testRepo:test" to the docker image reference "latestDockerReference"
the intent being to prove we properly convert imagestreamtags (which builds can't consume) to dockerimagereferences (which they can)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you've switched from using the mocked GetImageStreamTagFunc to the GetImageStreamFunc, you're getting different behavior. The GetImageStreamTag func always returned a DockerImageRef of "latestDockerReference" but the GetImageStreamFunc returns two tags, one for dockerReference and one for latestDockerReference. So your change is probably fine.
@miminar added handing for ImageStreamImage as well by lookup to images and finding the appropriate tag. PTAL. |
pkg/build/generator/generator.go
Outdated
return "", err | ||
} | ||
tag := "" | ||
for tagName, imageList := range stream.Status.Tags { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will pick up tags in random order, which means I can have different results for two runs on exact same ImageStream.
If I have an image tagged under is:tag
somewhere in an ancient history and I re-tag it again as is:latest
and I update the tag with:
oc patch istag/is:latest -p '{"tag":{"referencePolicy":{"type":"Local"}}}'
I'd probably expect that all the new build(configs) will resolve it as a local image.
With this code, I get completely random result.
"tag1": { | ||
Items: []imageapi.TagEvent{ | ||
{ | ||
DockerImageReference: "ref@" + name + ":tag1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't look like a valid reference. Is it on purpose?
"ref/"+name+":tag1"
is saner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't look like a valid reference. Is it on purpose?
@mfojtik bump on this question.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
d1b7d03
to
5e8076b
Compare
lgtm aside from @miminar's question about the tag ref. |
extended test failure "Extended.[builds][Slow] update failure status Build status failed assemble runtime artifacts should contain the failure reason related to failing to fetch runtime image artifacts" is a known flake. |
5e8076b
to
7e1c633
Compare
lgtm, will merge after extended tests pass. |
pkg/build/generator/generator.go
Outdated
glog.V(2).Info(err) | ||
return "", err | ||
} | ||
reference, ok := imageapi.ResolveLatestTaggedImage(stream, tag) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wrong. Returned reference may be for completely different image than requested.
Imagine image stream is
with a tag having two images in history:
"latest": { "items": [ "image": "a", "image": "b" ]}
Now this is called with a reference to image stream tag is:b
. The imageapi.LatestImageTagEvent
returns the right tag event with "image": "b"
. However, this call takes the tag, looks into is
and takes the first image a
. So the returned reference contains image name a
instead of b
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh you're right I forgot about this case, thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@miminar you mean to say that the "tag" argument to ResolveLatestTaggedImage is being effectively ignored? That wasn't my interpretation of how ResolveLatestTaggedImage works, but if it is that sounds like bad behavior for the helper function and not aligned with the godoc which says:
ResolveLatestTaggedImage returns the appropriate pull spec for a given tag in
the image stream, handling the tag's reference policy if necessary to return
a resolved image.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok nm, I see the scenario you're describing is more subtle than what I was thinking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@miminar added special function to handle ImageStreamImage. In that case we try to find the image stream that references this image and also lookup the "tag" which the given image exists. If there is matching tag event, we use the docker reference from it and read the referencePolicy...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to fix ImageStreamImage
handling.
7e1c633
to
fdc60f5
Compare
pkg/image/api/helper.go
Outdated
// DockerImageReferenceForImage returns the docker reference for specified image. Assuming | ||
// the image stream contain the image and the image has corresponding tag, this function | ||
// will try to find this tag and take the reference policy into the account. | ||
// The the image stream does not reference the image or the image does not have |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the
pkg/image/api/helper.go
Outdated
@@ -610,6 +634,34 @@ func ResolveLatestTaggedImage(stream *ImageStream, tag string) (string, bool) { | |||
} | |||
} | |||
|
|||
// DockerImageReferenceForImage returns the docker reference for specified image. Assuming | |||
// the image stream contain the image and the image has corresponding tag, this function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
contains
pkg/image/api/helper.go
Outdated
} | ||
switch ref.ReferencePolicy.Type { | ||
case LocalTagReferencePolicy: | ||
ref, err := ParseDockerImageReference(event.DockerImageReference) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use stream.Status.DockerImageRepository
as a base reference. Override its ID and unset its Tag.
fdc60f5
to
6f33f96
Compare
@miminar thanks! all fixed, ptal. |
Evaluated for origin test up to 6f33f96 |
Evaluated for origin testextended up to 6f33f96 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Some unit test for ImageStreamImage handling would be nice though.
@miminar will add as follow up. [merge] |
Evaluated for origin merge up to 6f33f96 |
continuous-integration/openshift-jenkins/test SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/13648/) (Base Commit: 4ec486d) |
continuous-integration/openshift-jenkins/merge SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/13650/) (Base Commit: feb429e) (Image: devenv-rhel7_5868) |
continuous-integration/openshift-jenkins/testextended SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin_extended/1070/) (Base Commit: 4ec486d) (Extended Tests: core(builds)) |
@miminar @bparees just a WIP (will return to this after meetings.,..)
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1412029