Skip to content

Commit

Permalink
odo dev works if no endpoint is defined
Browse files Browse the repository at this point in the history
  • Loading branch information
feloy committed Jan 6, 2023
1 parent edcd2c7 commit eb1e1b0
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 1 deletion.
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: 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

0 comments on commit eb1e1b0

Please sign in to comment.