Skip to content

Commit 0158f35

Browse files
author
OpenShift Bot
authored
Merge pull request #12104 from gabemontero/newappCircle
Merged by openshift-bot
2 parents 38e6fba + 4c93305 commit 0158f35

File tree

4 files changed

+92
-17
lines changed

4 files changed

+92
-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

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: v1
2+
items:
3+
- apiVersion: v1
4+
kind: ImageStream
5+
metadata:
6+
name: newapp-circular-template
7+
spec: {}
8+
kind: List
9+
metadata: {}

test/testdata/circular.yaml

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

0 commit comments

Comments
 (0)