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

Error when user gives build args with non-Docker strat #13257

Merged
merged 1 commit into from
Mar 9, 2017
Merged

Error when user gives build args with non-Docker strat #13257

merged 1 commit into from
Mar 9, 2017

Conversation

oatmealraisin
Copy link

Adds a new error message when a user specifies Docker build-args on a non-Docker build.

Fixes bz1429326
Related Trello card here

@openshift/devex @bparees @dongboyan77 ptal?

[test]


if len(config.BuildArgs) > 0 && config.Strategy != generate.StrategyDocker {
return kcmdutil.UsageError(c, "build arguments can only be used with Docker builds.")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

do we necessarily know the strategy that's going to be used at this point? what is the behavior when no strategy is explicitly specified?

Copy link
Author

Choose a reason for hiding this comment

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

You're right, I didn't catch generate.StrategyUnspecified. I've added that to the check. Do we want to error out if the Build doesn't use the BuildArgs? Currently, the BuildArgs will not be used if no ComponentReferences have a DockerStrategy.

However, since we'll likely only have one SourceRepository while using new-build, we could throw an error if the Strategy for that is not DockerStrategy.

Copy link
Contributor

Choose a reason for hiding this comment

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

i have mixed feelings as it is a slippery slope, but yes i guess if someone explicitly indicated they want to use build-args, we should throw an error if we aren't going to produce a docker build object.

@bparees
Copy link
Contributor

bparees commented Mar 6, 2017

also a change like this should have a test added so we don't regress it later.

@oatmealraisin
Copy link
Author

@bparees Added a test, and the check for unspecified strategy, ptal?

@@ -183,6 +183,9 @@ os::cmd::expect_failure_and_text "echo 'S P A C E S=test' | oc new-build --binar
# new-build - check that we can set build-args in DockerStrategy
os::cmd::expect_success_and_text "oc new-build ${OS_ROOT}/test/testdata/build-arg-dockerfile --build-arg 'foo=bar' --to 'test' -o jsonpath='{.items[?(@.kind==\"BuildConfig\")].spec.strategy.dockerStrategy.buildArgs[?(@.name==\"foo\")].value}'" 'bar'

# check that we cannot set build-args in a non-DockerStrategy build
os::cmd::expect_failure "oc new-build https://github.com/openshift/ruby-hello-world --strategy=source --build-arg 'foo=bar'"
Copy link
Contributor

Choose a reason for hiding this comment

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

should also run it w/ the strategy unspecified.

@oatmealraisin
Copy link
Author

@bparees Ready for another lookover, ptal? Added another test, and a check during the buildPipeline step

// needs to be modified to handle that.
if len(c.BuildArgs) > 0 && refInput.Uses.GetStrategy() != generate.StrategyDocker {
return nil, fmt.Errorf("Cannot use build arguments, not a Docker build")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

why not just iterate the objects at the end? if build-args was passed, and at least one of the objects being created is not a buildconfig w/ a docker strategy, throw an error.

@oatmealraisin
Copy link
Author

Flake #13271
[test]

@oatmealraisin
Copy link
Author

@csrwng Since Ben is on PTO, ptal?

return nil, fmt.Errorf("Cannot use build arguments without a Docker build")
}
if numDockerBuilds > 1 {
fmt.Fprintf(c.ErrOut, "--> WARNING: Using applying build arguments to multiple Docker builds.\n")
Copy link
Contributor

Choose a reason for hiding this comment

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

grammar


if len(c.BuildArgs) > 0 {
if numDockerBuilds == 0 {
return nil, fmt.Errorf("Cannot use build arguments without a Docker build")
Copy link
Contributor

Choose a reason for hiding this comment

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

is this the error that gets reported to the user? "build arguments" is probably too vague (all arguments to "oc new-build" are build arguments). Specify --build-args (or whatever the flag name is) instead.

@@ -193,6 +193,10 @@ os::cmd::expect_failure_and_text "echo 'S P A C E S=test' | oc new-build --binar
# new-build - check that we can set build-args in DockerStrategy
os::cmd::expect_success_and_text "oc new-build ${OS_ROOT}/test/testdata/build-arg-dockerfile --build-arg 'foo=bar' --to 'test' -o jsonpath='{.items[?(@.kind==\"BuildConfig\")].spec.strategy.dockerStrategy.buildArgs[?(@.name==\"foo\")].value}'" 'bar'

# check that we cannot set build-args in a non-DockerStrategy build
os::cmd::expect_failure "oc new-build https://github.com/openshift/ruby-hello-world --strategy=source --build-arg 'foo=bar'"
os::cmd::expect_failure "oc new-build https://github.com/openshift/ruby-ex --build-arg 'foo=bar'"
Copy link
Contributor

Choose a reason for hiding this comment

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

use expect_failure_and_text for both of these. make sure you're getting the error you expect.

@oatmealraisin
Copy link
Author

Flake #13288, [test]

@openshift-bot
Copy link
Contributor

Evaluated for origin test up to 7e52d29

@oatmealraisin
Copy link
Author

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/test SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pull_request_origin/49/) (Base Commit: a4efef0)

@bparees
Copy link
Contributor

bparees commented Mar 9, 2017

[merge]

@openshift-bot
Copy link
Contributor

openshift-bot commented Mar 9, 2017

continuous-integration/openshift-jenkins/merge SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pull_request_origin/49/) (Base Commit: a4efef0) (Image: devenv-rhel7_6058)

@openshift-bot
Copy link
Contributor

Evaluated for origin merge up to 7e52d29

@openshift-bot openshift-bot merged commit c9ed4e5 into openshift:master Mar 9, 2017
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.

3 participants