Skip to content

Commit

Permalink
Merge pull request #18461 from bparees/nocache
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue.

check all buildrequest options for validity against build type
  • Loading branch information
openshift-merge-robot authored Feb 7, 2018
2 parents c49e64b + e387676 commit ebb59c4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/build/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,16 @@ func (g *BuildGenerator) instantiate(ctx apirequest.Context, request *buildapi.B
// Update the Docker build args
if dockerOpts.BuildArgs != nil && len(dockerOpts.BuildArgs) > 0 {
if newBuild.Spec.Strategy.DockerStrategy == nil {
return nil, errors.NewBadRequest(fmt.Sprintf("Cannot specify build args on %s/%s, not a Docker build.", bc.Namespace, bc.ObjectMeta.Name))
return nil, errors.NewBadRequest(fmt.Sprintf("Cannot specify Docker build specific options on %s/%s, not a Docker build.", bc.Namespace, bc.ObjectMeta.Name))
}
newBuild.Spec.Strategy.DockerStrategy.BuildArgs = updateBuildArgs(&newBuild.Spec.Strategy.DockerStrategy.BuildArgs, dockerOpts.BuildArgs)
}

// Update the Docker noCache option
if dockerOpts.NoCache != nil {
if newBuild.Spec.Strategy.DockerStrategy == nil {
return nil, errors.NewBadRequest(fmt.Sprintf("Cannot specify Docker build specific options on %s/%s, not a Docker build.", bc.Namespace, bc.ObjectMeta.Name))
}
newBuild.Spec.Strategy.DockerStrategy.NoCache = *dockerOpts.NoCache
}
}
Expand All @@ -292,6 +295,9 @@ func (g *BuildGenerator) instantiate(ctx apirequest.Context, request *buildapi.B

// Update the Source incremental option
if sourceOpts.Incremental != nil {
if newBuild.Spec.Strategy.SourceStrategy == nil {
return nil, errors.NewBadRequest(fmt.Sprintf("Cannot specify Source build specific options on %s/%s, not a Source build.", bc.Namespace, bc.ObjectMeta.Name))
}
newBuild.Spec.Strategy.SourceStrategy.Incremental = sourceOpts.Incremental
}
}
Expand Down
3 changes: 3 additions & 0 deletions test/cmd/builds.sh
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ build_name="$(oc start-build -o=name test)"
os::cmd::expect_success_and_not_text "oc describe ${build_name}" 'Incremental Build'
build_name="$(oc start-build -o=name --incremental test)"
os::cmd::expect_success_and_text "oc describe ${build_name}" 'Incremental Build'
os::cmd::expect_failure_and_text "oc start-build test --no-cache" 'Cannot specify Docker build specific options'
os::cmd::expect_failure_and_text "oc start-build test --build-arg=a=b" 'Cannot specify Docker build specific options'
os::cmd::expect_success 'oc delete all --selector="name=test"'
# --no-cache flag should override Spec.Strategy.SourceStrategy.NoCache
os::cmd::expect_success 'oc create -f test/extended/testdata/builds/test-docker-build.json'
Expand All @@ -159,6 +161,7 @@ build_name="$(oc start-build -o=name test)"
os::cmd::expect_success_and_not_text "oc describe ${build_name}" 'No Cache'
build_name="$(oc start-build -o=name --no-cache test)"
os::cmd::expect_success_and_text "oc describe ${build_name}" 'No Cache'
os::cmd::expect_failure_and_text "oc start-build test --incremental" 'Cannot specify Source build specific options'
os::cmd::expect_success 'oc delete all --selector="name=test"'
echo "start-build: ok"
os::test::junit::declare_suite_end
Expand Down

0 comments on commit ebb59c4

Please sign in to comment.