Skip to content

Commit e6849c9

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 1023112 commit e6849c9

File tree

4 files changed

+101
-17
lines changed

4 files changed

+101
-17
lines changed

pkg/generate/app/cmd/newapp.go

+40-17
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,46 @@ func (c *AppConfig) Run() (*AppResult, error) {
684684
if err != nil {
685685
return nil, err
686686
}
687+
688+
// check for circular reference specifically from the template objects and print warnings if they exist
689+
err = c.checkCircularReferences(templateObjects)
690+
if err != nil {
691+
if err, ok := err.(app.CircularOutputReferenceError); ok {
692+
// templates only apply to `oc new-app`
693+
addOn := ""
694+
if len(c.Name) == 0 {
695+
addOn = ", override artifact names with --name"
696+
}
697+
fmt.Fprintf(c.ErrOut, "--> WARNING: %v\n%s", err, addOn)
698+
} else {
699+
return nil, err
700+
}
701+
}
702+
// check for circular reference specifically from the newly generated objects, handling new-app vs. new-build nuances as needed
703+
err = c.checkCircularReferences(objects)
704+
if err != nil {
705+
if err, ok := err.(app.CircularOutputReferenceError); ok {
706+
if c.ExpectToBuild {
707+
// circular reference handling for `oc new-build`.
708+
if len(c.To) == 0 {
709+
// Output reference was generated, return error.
710+
return nil, fmt.Errorf("%v, set a different tag with --to", err)
711+
}
712+
// Output reference was explicitly provided, print warning.
713+
fmt.Fprintf(c.ErrOut, "--> WARNING: %v\n", err)
714+
} else {
715+
// circular reference handling for `oc new-app`
716+
if len(c.Name) == 0 {
717+
return nil, fmt.Errorf("%v, override artifact names with --name", err)
718+
}
719+
// Output reference was explicitly provided, print warning.
720+
fmt.Fprintf(c.ErrOut, "--> WARNING: %v\n", err)
721+
}
722+
} else {
723+
return nil, err
724+
}
725+
}
726+
687727
objects = append(objects, templateObjects...)
688728

689729
name = c.Name
@@ -707,23 +747,6 @@ func (c *AppConfig) Run() (*AppResult, error) {
707747
}
708748
}
709749

710-
// Only check circular references for `oc new-build`.
711-
if c.ExpectToBuild {
712-
err = c.checkCircularReferences(objects)
713-
if err != nil {
714-
if err, ok := err.(app.CircularOutputReferenceError); ok {
715-
if len(c.To) == 0 {
716-
// Output reference was generated, return error.
717-
return nil, fmt.Errorf("%v, set a different tag with --to", err)
718-
}
719-
// Output reference was explicitly provided, print warning.
720-
fmt.Fprintf(c.ErrOut, "--> WARNING: %v\n", err)
721-
} else {
722-
return nil, err
723-
}
724-
}
725-
}
726-
727750
return &AppResult{
728751
List: &kapi.List{Items: objects},
729752
Name: name,

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.yaml'
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.yaml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: v1
2+
items:
3+
- apiVersion: v1
4+
kind: ImageStream
5+
metadata:
6+
creationTimestamp: 2016-12-02T18:55:30Z
7+
generation: 1
8+
name: newapp-circular-template
9+
resourceVersion: "764"
10+
selfLink: /oapi/v1/namespaces/myproject/imagestreams/newapp-circular-template
11+
uid: e5ad1d91-b8c0-11e6-9803-68f7287398a7
12+
spec: {}
13+
status:
14+
dockerImageRepository: 172.30.101.11:5000/myproject/newapp-circular-template
15+
kind: List
16+
metadata: {}

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)