Skip to content

Improving circular dependency checking for new-build#10067

Merged
openshift-bot merged 1 commit intoopenshift:masterfrom
jupierce:dev/jupierce/bug/7453
Aug 11, 2016
Merged

Improving circular dependency checking for new-build#10067
openshift-bot merged 1 commit intoopenshift:masterfrom
jupierce:dev/jupierce/bug/7453

Conversation

@jupierce
Copy link
Copy Markdown
Contributor

@jupierce jupierce commented Jul 27, 2016

Fixes #7453

Problematic invocations I found:

  • oc new-build --docker-image=jupierce/ruby-22-centos7 --to-docker=true --to=jupierce/ruby-22-centos7 https://github.com/openshift/ruby-hello-world
  • oc new-build --docker-image=jupierce/ruby-22-centos7:latest --to-docker=true --to=jupierce/ruby-22-centos7 https://github.com/openshift/ruby-hello-world
  • oc new-build -D $'FROM jupierce/ruby-22-centos7' --to ruby-22-centos7
  • oc new-build -D $'FROM jupierce/ruby-22-centos7:latest' --to ruby-22-centos7

fwiw, I found a way to sneak past the existing check without --to-docker=true with a sequence like:

  1. oc new-build https://github.com/openshift/ruby-hello-world
  2. oc new-build --image-stream=ruby-hello-world --to=ruby-hello-world https://github.com/openshift/ruby-hello-world --name=cycle
    It introduced a namespace attribute which caused the DeepEqual to fail. This PR accounts for this.

This will not fix docker image pushes to the local registry from causing a circular build process. For example:
oc new-build https://github.com/openshift/ruby-hello-world --to-docker=true --to=172.30.96.226:5000/myproject/ruby-22-centos7
(Where --to is pointing to the openshift docker registry/authorized project)

Adding additional cycle inducing commands that involve IST to IST references (this requires oc create of centos7 image streams and assumes latest points to 10.0):

  • oc new-build -D "FROM openshift/wildfly:latest" --to-docker=true --to openshift/wildfly-100-centos7

@jupierce
Copy link
Copy Markdown
Contributor Author

@bparees @rhcarvalho

@bparees
Copy link
Copy Markdown
Contributor

bparees commented Jul 27, 2016

So does this handle:

oc new-build https://github.com/openshift/ruby-hello-world --to-docker=true --to=centos/ruby-22-centos7 

?

that seems like the most likely error path a user would hit. or a variant of that in which even without the --to, the generated Output value ends up matching the image referenced in the source repo's dockerfile.

@jupierce
Copy link
Copy Markdown
Contributor Author

That will issue a warning, yes. My examples are more contrived since I wanted them to have the potential for success. --to=centos/ruby-22-centos7 will always fail since the user will lack the credentials to push to docker.io.

One important note: all of these examples generate a warning, but otherwise proceed. I preserved the existing logic that turns cycle detection into a warning if the user specifies --to.

@bparees
Copy link
Copy Markdown
Contributor

bparees commented Jul 27, 2016

--to=centos/ruby-22-centos7 will always fail since the user will lack the credentials to push to docker.io.

sure, i didn't feel like creating an example with actual repo a user might have access to, but the concept is the same. (and there are people w/ those credentials)

@jupierce
Copy link
Copy Markdown
Contributor Author

Understood. In either case, it should be caught. It is a similar codepath to the first bullet in the PR -- just with a defaulting builder image.

// Some code paths add namespace and others don't. Make things
// consistent.
if len(ref.Namespace) == 0 {
ref.Namespace = ns
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ns is going to be the input namespace here, right? if we're looking at the output image, we should be setting the ns to the origin(current/chosen) namespace, not the input namespace.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes. I just couldn't come up with a scenario in which they would differ and got too aggressive in trimming the code :-) . Next commit removes this assumption.

@rhcarvalho
Copy link
Copy Markdown
Contributor

I'm missing tests to accompany the code changes.

@jupierce
Copy link
Copy Markdown
Contributor Author

@rhcarvalho Tests cases underway. Just wanted to know if the approach seemed like it was on the right track.

@bparees
Copy link
Copy Markdown
Contributor

bparees commented Jul 28, 2016

Just wanted to know if the approach seemed like it was on the right track.

i think so.

@jupierce
Copy link
Copy Markdown
Contributor Author

Just an update..

Adding test cases is conceptually simple, but a magic flag used by newapp is taking time to figure out. If it is not set, the client does not populate the Tags element of ImageStream resources (apparently for backwards compatibility with older servers).

In the existing test cases, ImageStream objects are being created without Tags, but the new checkCircularReferences requires them. I will be adding backwards compatibility to checkCircularReferences to support tagless ImageStreams, but I would like the test case to exercise the newer ImageStream Spec.

https://github.com/openshift/origin/blob/master/pkg/generate/app/imagestreamlookup.go#L201-L203
https://github.com/openshift/origin/blob/master/pkg/generate/app/imageref.go#L315-L324

@jupierce
Copy link
Copy Markdown
Contributor Author

[test]

@stevekuznetsov
Copy link
Copy Markdown
Contributor

re[test]

1 similar comment
@jupierce
Copy link
Copy Markdown
Contributor Author

jupierce commented Aug 2, 2016

re[test]

@jupierce
Copy link
Copy Markdown
Contributor Author

jupierce commented Aug 2, 2016

@bparees Just to get back on your radar.

if err != nil {
return err
}
want := "--> WARNING: output image of \"default/centos/ruby-22-centos7:latest\" must be different than input\n"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can we change this actual warning message:
s/must.*/should be different from the input to avoid circular build triggering\n/

(since it's a warning, not an error, it doesn't make sense to say "must")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Will do.

@jupierce
Copy link
Copy Markdown
Contributor Author

jupierce commented Aug 8, 2016

@bparees @rhcarvalho Added support for IST->IST references. Ready for another round of review.

isNS = c.OriginNamespace
}

// Otherwise, we are tracing an IST reference
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is there a test for this scenario? it wasn't obvious to me when i scanned the unit tests.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

To be clear, this line a verbose guard to let someone know that they are misusing the current method's implementation. e.g. If a new type of To/From ObjectReference is encountered, this path will annoy folks and remind them the cycle check logic needs to be updated -- but do so without breaking newapp.
In short, I don't believe newapp's current implementation can actually trigger the error. I will add a test case to cover the code, but it will need to invoke checkCircularReferences with contrived data.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

hm? i'm referring to the scenario where someone uses an imagestreamtag as an input but that imagestreamtag is a "following" imagestreamtag, rather than one that directly points to a docker pull spec. that can happen, right? (unless we have resolved the indirect reference earlier in new-app code)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I mistakenly thought you were talking about the if ref.Kind != "ImageStreamTag" . I will add a test for the IST->IST.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

cool, thanks!

@jupierce
Copy link
Copy Markdown
Contributor Author

@bparees

  • Added test case to exercise unexpected ObjectReference kind code path
  • Improved doc & formatting

}

// followRefToDockerImage follows a buildconfig...To/From reference until it t
// erminates in docker image information. This can include dereferencing chains
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

looks like "terminates" was broken into the 2 lines

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

erminate (verb) - meaning to improperly line break comments in code.

fixed :)

@jupierce
Copy link
Copy Markdown
Contributor Author

@bparees TestBuildOutputCycleWithFollowingTag now checks for following tag support.

@bparees
Copy link
Copy Markdown
Contributor

bparees commented Aug 11, 2016

lgtm [merge]

@openshift-bot
Copy link
Copy Markdown
Contributor

openshift-bot commented Aug 11, 2016

continuous-integration/openshift-jenkins/merge SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/7808/) (Image: devenv-rhel7_4806)

@openshift-bot
Copy link
Copy Markdown
Contributor

Evaluated for origin merge up to 76800c3

@openshift-bot
Copy link
Copy Markdown
Contributor

Evaluated for origin test up to 76800c3

@openshift-bot
Copy link
Copy Markdown
Contributor

continuous-integration/openshift-jenkins/test SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/7808/)

@openshift-bot openshift-bot merged commit 17b08ae into openshift:master Aug 11, 2016
@jupierce
Copy link
Copy Markdown
Contributor Author

@oatmealraisin Over to you!

@oatmealraisin
Copy link
Copy Markdown

@jupierce merci!

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.

Improve circular input/output detection in oc new-build

6 participants