Skip to content

Commit 7c8f428

Browse files
committed
new-app: appropriately warn/error on circular builds
Bug 1393549 Bugzilla link https://bugzilla.redhat.com/show_bug.cgi?id=1393549 Detailed explanation Citing of cirular builds were performed for new-build but not new-app; With new-app, if template, simply warn, if not template fail command
1 parent 556fe4b commit 7c8f428

File tree

4 files changed

+81
-6
lines changed

4 files changed

+81
-6
lines changed

pkg/generate/app/cmd/newapp.go

+15-6
Original file line numberDiff line numberDiff line change
@@ -710,20 +710,29 @@ func (c *AppConfig) Run() (*AppResult, error) {
710710
}
711711
}
712712

713-
// Only check circular references for `oc new-build`.
714-
if c.ExpectToBuild {
715-
err = c.checkCircularReferences(objects)
716-
if err != nil {
717-
if err, ok := err.(app.CircularOutputReferenceError); ok {
713+
err = c.checkCircularReferences(objects)
714+
if err != nil {
715+
if err, ok := err.(app.CircularOutputReferenceError); ok {
716+
if c.ExpectToBuild {
717+
// circular reference handling for `oc new-build`.
718718
if len(c.To) == 0 {
719719
// Output reference was generated, return error.
720720
return nil, fmt.Errorf("%v, set a different tag with --to", err)
721721
}
722722
// Output reference was explicitly provided, print warning.
723723
fmt.Fprintf(c.ErrOut, "--> WARNING: %v\n", err)
724724
} else {
725-
return nil, err
725+
// circular reference handling for `oc new-app`
726+
if len(templateObjects) > 0 {
727+
fmt.Fprintf(c.ErrOut, "--> WARNING: %v\n", err)
728+
} else if len(c.Name) == 0 {
729+
return nil, fmt.Errorf("%v, override artifact names with --name", err)
730+
} else {
731+
return nil, err
732+
}
726733
}
734+
} else {
735+
return nil, err
727736
}
728737
}
729738

test/cmd/newapp.sh

+4
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,10 @@ os::cmd::expect_success_and_text 'oc new-build --name mybuild --binary --strateg
264264
os::cmd::expect_failure_and_text 'oc new-build mysql --source-image centos' 'error: --source-image-path must be specified when --source-image is specified.'
265265
os::cmd::expect_failure_and_text 'oc new-build mysql --source-image-path foo' 'error: --source-image must be specified when --source-image-path is specified.'
266266

267+
# ensure circular ref flagged but allowed for template
268+
os::cmd::expect_success 'oc create -f test/testdata/circular-is.json'
269+
os::cmd::expect_success_and_text 'oc new-app -f test/testdata/circular.yaml' 'should be different than input'
270+
267271
# do not allow use of non-existent image (should fail)
268272
os::cmd::expect_failure_and_text 'oc new-app openshift/bogusimage https://github.com/openshift/ruby-hello-world.git -o yaml' "no match for"
269273
# allow use of non-existent image (should succeed)

test/testdata/circular-is.json

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"kind": "List",
3+
"apiVersion": "v1",
4+
"metadata": {},
5+
"items": [
6+
{
7+
8+
"kind": "ImageStream",
9+
"apiVersion": "v1",
10+
"metadata": {
11+
"name": "newapp-circular-template",
12+
"creationTimestamp": null
13+
},
14+
"spec": {},
15+
"status": {
16+
"dockerImageRepository": ""
17+
}
18+
19+
}
20+
]
21+
}

test/testdata/circular.yaml

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
apiVersion: v1
2+
kind: Template
3+
metadata:
4+
creationTimestamp: null
5+
name: circular
6+
objects:
7+
- apiVersion: v1
8+
kind: BuildConfig
9+
metadata:
10+
creationTimestamp: null
11+
name: newapp-circular-template
12+
spec:
13+
nodeSelector: null
14+
output:
15+
to:
16+
kind: ImageStreamTag
17+
name: newapp-circular-template:latest
18+
postCommit: {}
19+
resources: {}
20+
runPolicy: Serial
21+
source:
22+
git:
23+
uri: https://github.com/openshift/ruby-hello-world
24+
type: Git
25+
strategy:
26+
dockerStrategy:
27+
from:
28+
kind: ImageStreamTag
29+
name: newapp-circular-template:latest
30+
type: Docker
31+
triggers:
32+
- github:
33+
secret: faSaQS1VY-gdRMwge4eV
34+
type: GitHub
35+
- generic:
36+
secret: u-_J-vtKR5K3GykKwCuK
37+
type: Generic
38+
- imageChange: {}
39+
type: ImageChange
40+
status:
41+
lastVersion: 0

0 commit comments

Comments
 (0)