Skip to content

Commit

Permalink
Merge cff113b into 2beda42
Browse files Browse the repository at this point in the history
  • Loading branch information
feloy authored Jan 6, 2023
2 parents 2beda42 + cff113b commit 7aa4e4c
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 4 deletions.
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
5 changes: 5 additions & 0 deletions pkg/portForward/portForward.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ func (o *PFClient) StartPortForwarding(

o.StopPortForwarding()

if len(ceMapping) == 0 {
klog.V(4).Infof("no endpoint declared in the component, no ports are forwarded")
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(ports).To(BeEmpty())
})
})
})

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

0 comments on commit 7aa4e4c

Please sign in to comment.