Skip to content

Commit a303fa3

Browse files
Merge pull request #18631 from coreydaley/github_17675_specify_image_stream_to_overwrite_from
Automatic merge from submit-queue. --source-image should count as a source input - the --source-image flag should count as a source input - the --strategy flag should override the build strategy in all source repositories Fixes #17675
2 parents 622de3d + a13dcdf commit a303fa3

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-12
lines changed

pkg/oc/generate/cmd/resolve.go

+23-12
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,38 @@ func Resolve(appConfig *AppConfig) (*ResolvedComponents, error) {
107107
if err := AddComponentInputsToRefBuilder(b, r, c, g, s, i); err != nil {
108108
return nil, err
109109
}
110+
110111
components, repositories, errs := b.Result()
111112
if len(errs) > 0 {
112113
return nil, kutilerrors.NewAggregate(errs)
113114
}
114115

116+
// Add source components if source-image points to another location
117+
// TODO: image sources aren't really "source repositories" and we should probably find another way to
118+
// represent them
119+
imageComp, repositories, err := AddImageSourceRepository(repositories, r.ImageSourceResolver(), g)
120+
if err != nil {
121+
return nil, err
122+
}
123+
115124
// TODO: the second half of this method is potentially splittable - each chunk below amends or qualifies
116125
// the inputs provided by the user (mostly via flags). c is cleared to prevent it from being used accidentally.
117126
c = nil
118127

119-
// set context dir on all repositories
120-
for _, repo := range repositories {
121-
repo.SetContextDir(g.ContextDir)
128+
// if the --context-dir flag was passed, set the context directory on all repositories
129+
if len(g.ContextDir) > 0 && len(repositories) > 0 {
130+
glog.V(5).Infof("Setting contextDir on all repositories to %v", g.ContextDir)
131+
for _, repo := range repositories {
132+
repo.SetContextDir(g.ContextDir)
133+
}
134+
}
135+
136+
// if the --strategy flag was passed, set the build strategy on all repositories
137+
if g.Strategy != generate.StrategyUnspecified && len(repositories) > 0 {
138+
glog.V(5).Infof("Setting build strategy on all repositories to %v", g.Strategy)
139+
for _, repo := range repositories {
140+
repo.SetStrategy(g.Strategy)
141+
}
122142
}
123143

124144
if g.Strategy != generate.StrategyUnspecified && len(repositories) == 0 && !g.BinaryBuild {
@@ -129,15 +149,6 @@ func Resolve(appConfig *AppConfig) (*ResolvedComponents, error) {
129149
return nil, errors.New("specifying binary builds and source repositories at the same time is not allowed")
130150
}
131151

132-
// Add source components if source-image points to another location
133-
// TODO: image sources aren't really "source repositories" and we should probably find another way to
134-
// represent them
135-
var err error
136-
var imageComp app.ComponentReference
137-
imageComp, repositories, err = AddImageSourceRepository(repositories, r.ImageSourceResolver(), g)
138-
if err != nil {
139-
return nil, err
140-
}
141152
componentsIncludingImageComps := components
142153
if imageComp != nil {
143154
componentsIncludingImageComps = append(components, imageComp)

test/cmd/newapp.sh

+13
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,19 @@ os::cmd::expect_success_and_not_text 'oc new-app https://github.com/openshift/ru
502502
# We permit running new-app against a remote URL which returns a template
503503
os::cmd::expect_success 'oc new-app https://raw.githubusercontent.com/openshift/origin/master/examples/wordpress/template/wordpress-mysql.json --dry-run'
504504

505+
# ensure that --strategy sets the build strategy
506+
os::cmd::expect_success_and_text 'oc new-build --name sourcetest python~https://github.com/sclorg/django-ex --source-image centos:latest --source-image-path /tmp --strategy source --dry-run -o yaml' 'sourceStrategy'
507+
os::cmd::expect_success_and_text 'oc new-build --name sourcetest python~https://github.com/sclorg/django-ex --source-image centos:latest --source-image-path /tmp --strategy pipeline --dry-run -o yaml' 'jenkinsPipelineStrategy'
508+
os::cmd::expect_success_and_text 'oc new-build --name sourcetest python~https://github.com/sclorg/django-ex --source-image centos:latest --source-image-path /tmp --strategy docker --dry-run -o yaml' 'dockerStrategy'
509+
510+
os::cmd::expect_success 'oc create -f examples/image-streams/image-streams-centos7.json'
511+
os::cmd::try_until_success 'oc get imagestreamtags nodejs:latest'
512+
# ensure that a build can be created with just image inputs without the --binary flag
513+
os::cmd::expect_success_and_text 'oc new-build --name sourcetest --source-image centos:latest --source-image-path /tmp --image-stream nodejs --dry-run -o yaml' 'sourceStrategy'
514+
# ensure that using only image inputs and the --binary flag results in an error
515+
os::cmd::expect_failure_and_text 'oc new-build --name sourcetest --source-image centos:latest --source-image-path /tmp --image-stream nodejs --binary --dry-run -o yaml' 'specifying binary builds and source repositories at the same time is not allowed'
516+
os::cmd::expect_success 'oc delete imagestreams --all --ignore-not-found'
517+
505518
# new-app different syntax for new-app functionality
506519
os::cmd::expect_success 'oc new-project new-app-syntax'
507520
os::cmd::expect_success 'oc import-image openshift/ruby-20-centos7:latest --confirm'

0 commit comments

Comments
 (0)