Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn if a docker compose service has no ports #9009

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/cmd/cli/cmd/importer/dockercompose.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func (o *DockerComposeOptions) Run() error {
appcmd.DescribeGeneratedTemplate(o.Action.Out, "", result, o.Namespace)
}

if errs := o.Action.WithMessage("Importing compose file", "creating").Run(&kapi.List{Items: result.Objects}, o.Namespace); len(errs) > 0 {
if errs := o.Action.WithMessage("Importing compose file", "created").Run(&kapi.List{Items: result.Objects}, o.Namespace); len(errs) > 0 {
return cmdutil.ErrExit
}
return nil
Expand Down
2 changes: 2 additions & 0 deletions pkg/generate/dockercompose/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,8 @@ func Generate(paths ...string) (*templateapi.Template, error) {
case *deployapi.DeploymentConfig:
ports := app.UniqueContainerToServicePorts(app.AllContainerPorts(t.Spec.Template.Spec.Containers...))
if len(ports) == 0 {
msg := "no ports defined to send traffic to - no OpenShift service was created"
warnings[msg] = append(warnings[msg], t.Name)
continue
}
svc := app.GenerateService(t.ObjectMeta, t.Spec.Selector)
Expand Down
3 changes: 2 additions & 1 deletion test/cmd/newapp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,10 @@ os::cmd::expect_failure_and_text "oc new-app '${jsonfile}'" "error: unable to lo
# a docker compose file should be transformed into an application by the import command
os::cmd::expect_success_and_text 'oc import docker-compose -f test/fixtures/app-scenarios/docker-compose/complex/docker-compose.yml --dry-run' 'warning: not all docker-compose fields were honored'
os::cmd::expect_success_and_text 'oc import docker-compose -f test/fixtures/app-scenarios/docker-compose/complex/docker-compose.yml --dry-run' 'db: cpuset is not supported'
os::cmd::expect_success_and_text 'oc import docker-compose -f test/fixtures/app-scenarios/docker-compose/complex/docker-compose.yml --dry-run' 'no-ports: no ports defined to send traffic to - no OpenShift service was created'
os::cmd::expect_success_and_text 'oc import docker-compose -f test/fixtures/app-scenarios/docker-compose/complex/docker-compose.yml -o name --dry-run' 'service/redis'
os::cmd::expect_success_and_text 'oc import docker-compose -f test/fixtures/app-scenarios/docker-compose/complex/docker-compose.yml -o name --as-template=other --dry-run' 'template/other'
os::cmd::expect_failure 'diff --suppress-common-lines -y <(oc import docker-compose -f test/fixtures/app-scenarios/docker-compose/complex/docker-compose.yml -o yaml) test/fixtures/app-scenarios/docker-compose/complex/docker-compose.imported.yaml | grep -v secret'
os::cmd::expect_success '[[ $(diff --suppress-common-lines -y <(oc import docker-compose -f test/fixtures/app-scenarios/docker-compose/complex/docker-compose.yml -o yaml) test/fixtures/app-scenarios/docker-compose/complex/docker-compose.imported.yaml | grep -vE "ref\:|secret|uri\:" | wc -l) -eq 0 ]]'

# verify a docker-compose.yml schema 2 resource can be transformed, and that it sets env vars correctly.
os::cmd::expect_success_and_text 'oc import docker-compose -f test/fixtures/app-scenarios/docker-compose/wordpress/docker-compose.yml -o yaml --as-template=other --dry-run' 'value: wordpress'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
apiVersion: v1
kind: Template
metadata:
creationTimestamp: null
name: complex
objects:
items:
- apiVersion: v1
kind: ImageStream
metadata:
Expand Down Expand Up @@ -36,7 +32,7 @@ objects:
source:
contextDir: test/fixtures/app-scenarios/docker-compose/complex/nginx
git:
ref: libcompose
ref: master
uri: [email protected]:openshift/origin.git
secrets: null
type: Git
Expand All @@ -48,10 +44,10 @@ objects:
type: Docker
triggers:
- github:
secret: gKR65ZJCwVsproaayUIz
secret: FdDzZzJCBkHQGxYMMBw0
type: GitHub
- generic:
secret: PnTkFixxvwHK--JxtaJ7
secret: wMAV07N8TWt9dz40LDjL
type: Generic
- type: ConfigChange
- imageChange: {}
Expand Down Expand Up @@ -90,7 +86,7 @@ objects:
source:
contextDir: test/fixtures/app-scenarios/docker-compose/complex/app
git:
ref: libcompose
ref: master
uri: [email protected]:openshift/origin.git
secrets: null
type: Git
Expand All @@ -102,10 +98,10 @@ objects:
type: Docker
triggers:
- github:
secret: f7q0OGOVc-usCy7xA-Ul
secret: 3QSLvrej6A2E-CMYSEvQ
type: GitHub
- generic:
secret: yK_wyTqSxqqoYZ_TVSoo
secret: uBl0LIK0anHOaRJ8-4dI
type: Generic
- type: ConfigChange
- imageChange: {}
Expand Down Expand Up @@ -234,6 +230,56 @@ objects:
name: web:latest
type: ImageChange
status: {}
- apiVersion: v1
kind: ImageStream
metadata:
creationTimestamp: null
name: no-ports
spec:
tags:
- annotations:
openshift.io/imported-from: redis
from:
kind: DockerImage
name: redis
generation: null
importPolicy: {}
name: latest
status:
dockerImageRepository: ""
- apiVersion: v1
kind: DeploymentConfig
metadata:
creationTimestamp: null
name: no-ports
spec:
replicas: 1
selector:
deploymentconfig: no-ports
strategy:
resources: {}
template:
metadata:
creationTimestamp: null
labels:
deploymentconfig: no-ports
spec:
containers:
- image: redis
name: no-ports
resources: {}
test: false
triggers:
- type: ConfigChange
- imageChangeParams:
automatic: true
containerNames:
- no-ports
from:
kind: ImageStreamTag
name: no-ports:latest
type: ImageChange
status: {}
- apiVersion: v1
kind: Service
metadata:
Expand Down Expand Up @@ -265,3 +311,5 @@ objects:
deploymentconfig: nginx
status:
loadBalancer: {}
kind: List
metadata: {}
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ db:
cpu_quota: 10000
mem_limit: 1000000000
cpuset: 1

no-ports:
image: redis