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

Make odo dev work if no endpoint is defined #6472

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 5 additions & 1 deletion pkg/libdevfile/libdevfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,16 @@ func GetContainerEndpointMapping(containers []v1alpha2.Component) map[string][]i
// this is not a container component; continue prevents panic when accessing Endpoints field
continue
}
endpoints := container.Container.Endpoints
if len(endpoints) == 0 {
continue
}

k := container.Name
if _, ok := ceMapping[k]; !ok {
ceMapping[k] = []int{}
}

endpoints := container.Container.Endpoints
for _, e := range endpoints {
ceMapping[k] = append(ceMapping[k], e.TargetPort)
}
Expand Down
4 changes: 1 addition & 3 deletions pkg/libdevfile/libdevfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ func TestGetContainerEndpointMapping(t *testing.T) {
args: args{
containers: []v1alpha2.Component{containerWithNoEndpoints},
},
want: map[string][]int{containerWithNoEndpoints.Name: {}},
want: map[string][]int{},
},
{
name: "multiple containers with varying types of endpoints",
Expand All @@ -667,7 +667,6 @@ func TestGetContainerEndpointMapping(t *testing.T) {
},
},
want: map[string][]int{
containerWithNoEndpoints.Name: {},
containerWithOnePublicEndpoint.Name: {8080},
containerWithOneInternalEndpoint.Name: {9090},
containerWithOneNoneInternalEndpoint.Name: {9099},
Expand All @@ -685,7 +684,6 @@ func TestGetContainerEndpointMapping(t *testing.T) {
},
},
want: map[string][]int{
containerWithNoEndpoints.Name: {},
containerWithOnePublicEndpoint.Name: {8080},
containerWithOneInternalEndpoint.Name: {9090},
containerWithOneNoneInternalEndpoint.Name: {9099},
Expand Down
4 changes: 4 additions & 0 deletions pkg/portForward/portForward.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ func (o *PFClient) StartPortForwarding(

o.StopPortForwarding()

if len(ceMapping) == 0 {
return nil
}

o.stopChan = make(chan struct{}, 1)

var portPairs map[string][]string
Expand Down
47 changes: 47 additions & 0 deletions tests/examples/source/devfiles/nodejs/devfile-no-endpoint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
schemaVersion: 2.0.0
metadata:
name: nodejs
projectType: nodejs
language: nodejs
starterProjects:
- name: nodejs-starter
git:
remotes:
origin: "https://github.com/odo-devfiles/nodejs-ex.git"
components:
- name: runtime
container:
image: registry.access.redhat.com/ubi8/nodejs-12:1-36
memoryLimit: 1024Mi
mountSources: true
commands:
- id: devbuild
exec:
component: runtime
commandLine: npm install
workingDir: ${PROJECTS_ROOT}
group:
kind: build
isDefault: true
- id: build
exec:
component: runtime
commandLine: npm install
workingDir: ${PROJECTS_ROOT}
group:
kind: build
- id: devrun
exec:
component: runtime
commandLine: npm start
workingDir: ${PROJECTS_ROOT}
group:
kind: run
isDefault: true
- id: run
exec:
component: runtime
commandLine: npm start
workingDir: ${PROJECTS_ROOT}
group:
kind: run
36 changes: 36 additions & 0 deletions tests/integration/cmd_dev_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,42 @@ ComponentSettings:
manual := manual
podman := podman
Context("port-forwarding for the component", helper.LabelPodmanIf(podman, func() {
When("devfile has no endpoint", func() {
BeforeEach(func() {
if !podman {
helper.Cmd("odo", "set", "project", commonVar.Project).ShouldPass()
}
helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), commonVar.Context)
helper.Cmd("odo", "init", "--name", cmpName, "--devfile-path", helper.GetExamplePath("source", "devfiles", "nodejs", "devfile-no-endpoint.yaml")).ShouldPass()
})

When("running odo dev", func() {
var devSession helper.DevSession
var ports map[string]string
BeforeEach(func() {
var err error
opts := []string{}
if manual {
opts = append(opts, "--no-watch")
}
devSession, _, _, ports, err = helper.StartDevMode(helper.DevSessionOpts{
CmdlineArgs: opts,
RunOnPodman: podman,
})
Expect(err).ToNot(HaveOccurred())
})

AfterEach(func() {
devSession.Stop()
devSession.WaitEnd()
})

It("should have no endpoint forwarded", func() {
Expect(len(ports)).To(BeZero())
})
})
})

When("devfile has single endpoint", func() {
BeforeEach(func() {
if !podman {
Expand Down