Skip to content
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

Merged
merged 1 commit into from
Feb 7, 2017

Conversation

mfojtik
Copy link
Contributor

@mfojtik mfojtik commented Feb 2, 2017

@miminar @bparees just a WIP (will return to this after meetings.,..)

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1412029

@mfojtik
Copy link
Contributor Author

mfojtik commented Feb 2, 2017

[test]

@mfojtik mfojtik force-pushed the resolve-image-by-reference branch from 3579a13 to a3d4df7 Compare February 2, 2017 08:56
Copy link

@miminar miminar left a 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.

@mfojtik mfojtik force-pushed the resolve-image-by-reference branch from a3d4df7 to d1b7d03 Compare February 2, 2017 13:16
Status: imageapi.ImageStreamStatus{
DockerImageRepository: originalImage,
Tags: map[string]imageapi.TagEventList{
"tag1": {
Copy link
Contributor Author

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,
Copy link
Contributor Author

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?

Copy link
Contributor

@bparees bparees Feb 2, 2017

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)

Copy link
Contributor

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.

@mfojtik
Copy link
Contributor Author

mfojtik commented Feb 2, 2017

@miminar added handing for ImageStreamImage as well by lookup to images and finding the appropriate tag. PTAL.

return "", err
}
tag := ""
for tagName, imageList := range stream.Status.Tags {
Copy link

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",
Copy link

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.

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bparees @miminar i think it was like this before, I can fix it to reflect the reality

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

@mfojtik mfojtik force-pushed the resolve-image-by-reference branch from d1b7d03 to 5e8076b Compare February 2, 2017 16:05
@bparees
Copy link
Contributor

bparees commented Feb 2, 2017

lgtm aside from @miminar's question about the tag ref.
[testextended][extended:core(builds)]

@bparees bparees self-assigned this Feb 2, 2017
@bparees
Copy link
Contributor

bparees commented Feb 2, 2017

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.

#12341

@mfojtik mfojtik force-pushed the resolve-image-by-reference branch from 5e8076b to 7e1c633 Compare February 6, 2017 11:24
@mfojtik
Copy link
Contributor Author

mfojtik commented Feb 6, 2017

@miminar @bparees PTAL (this should be ready to go)

@bparees
Copy link
Contributor

bparees commented Feb 6, 2017

lgtm, will merge after extended tests pass.

glog.V(2).Info(err)
return "", err
}
reference, ok := imageapi.ResolveLatestTaggedImage(stream, tag)
Copy link

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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...

Copy link

@miminar miminar left a 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.

@mfojtik mfojtik force-pushed the resolve-image-by-reference branch from 7e1c633 to fdc60f5 Compare February 6, 2017 15:47
// 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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the

@@ -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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

contains

}
switch ref.ReferencePolicy.Type {
case LocalTagReferencePolicy:
ref, err := ParseDockerImageReference(event.DockerImageReference)
Copy link

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.

@mfojtik mfojtik force-pushed the resolve-image-by-reference branch from fdc60f5 to 6f33f96 Compare February 7, 2017 10:19
@mfojtik
Copy link
Contributor Author

mfojtik commented Feb 7, 2017

@miminar thanks! all fixed, ptal.

@openshift-bot
Copy link
Contributor

Evaluated for origin test up to 6f33f96

@openshift-bot
Copy link
Contributor

Evaluated for origin testextended up to 6f33f96

Copy link

@miminar miminar left a 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.

@mfojtik
Copy link
Contributor Author

mfojtik commented Feb 7, 2017

@miminar will add as follow up.

[merge]

@openshift-bot
Copy link
Contributor

Evaluated for origin merge up to 6f33f96

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/test SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/13648/) (Base Commit: 4ec486d)

@openshift-bot
Copy link
Contributor

openshift-bot commented Feb 7, 2017

continuous-integration/openshift-jenkins/merge SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/13650/) (Base Commit: feb429e) (Image: devenv-rhel7_5868)

@openshift-bot
Copy link
Contributor

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))

@openshift-bot openshift-bot merged commit 37ef206 into openshift:master Feb 7, 2017
@mfojtik mfojtik deleted the resolve-image-by-reference branch September 5, 2018 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants