Skip to content
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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ require (
github.com/Netflix/go-expect v0.0.0-20201125194554-85d881c3777e
github.com/Xuanwo/go-locale v1.0.0
github.com/blang/semver v3.5.1+incompatible
github.com/devfile/api/v2 v2.0.0-20211118170330-959f3c8007c3
github.com/devfile/library v1.2.1-0.20211207205254-de570f015d84
github.com/devfile/api/v2 v2.0.0-20220126144139-f6d7cd85a481
github.com/devfile/library v1.2.1-0.20220201022328-58ef0b78c0fe
github.com/devfile/registry-support/index/generator v0.0.0-20211012185733-0a73f866043f
github.com/devfile/registry-support/registry-library v0.0.0-20211125162259-d7edf148d3e2
github.com/fatih/color v1.10.0
Expand Down
9 changes: 5 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,12 @@ github.com/deislabs/oras v0.8.1/go.mod h1:Mx0rMSbBNaNfY9hjpccEnxkOqJL6KGjtxNHPLC
github.com/denisenkom/go-mssqldb v0.0.0-20190515213511-eb9f6a1743f3/go.mod h1:zAg7JM8CkOJ43xKXIj7eRO9kmWm/TW578qo+oDO6tuM=
github.com/denverdino/aliyungo v0.0.0-20190125010748-a747050bb1ba/go.mod h1:dV8lFg6daOBZbT6/BDGIz6Y3WFGn8juu6G+CQ6LHtl0=
github.com/devfile/api/v2 v2.0.0-20210910153124-da620cd1a7a1/go.mod h1:kLX/nW93gigOHXK3NLeJL2fSS/sgEe+OHu8bo3aoOi4=
github.com/devfile/api/v2 v2.0.0-20211118170330-959f3c8007c3 h1:G7TIrgpGx5lcZ3X7bpQeVCeeeO7tv6SAzPPvB9ThHXE=
github.com/devfile/api/v2 v2.0.0-20211118170330-959f3c8007c3/go.mod h1:d99eTN6QxgzihOOFyOZA+VpUyD4Q1pYRYHZ/ci9J96Q=
github.com/devfile/api/v2 v2.0.0-20220117162434-6e6e6a8bc14c/go.mod h1:d99eTN6QxgzihOOFyOZA+VpUyD4Q1pYRYHZ/ci9J96Q=
github.com/devfile/api/v2 v2.0.0-20220126144139-f6d7cd85a481 h1:G4trvnLOua7AsSetNa8k4u9VUNavPIwXa3CNfBwQwx4=
github.com/devfile/api/v2 v2.0.0-20220126144139-f6d7cd85a481/go.mod h1:kLX/nW93gigOHXK3NLeJL2fSS/sgEe+OHu8bo3aoOi4=
github.com/devfile/library v1.1.1-0.20210910214722-7c5ff63711ec/go.mod h1:svPWwWb+BP15SXCHl0dyOeE4Sohrjl5a2BaOzc/riLc=
github.com/devfile/library v1.2.1-0.20211207205254-de570f015d84 h1:9Tce6BIw9PCdA1AopHxVo0gheU+dP3jfl2MgBKLnMRQ=
github.com/devfile/library v1.2.1-0.20211207205254-de570f015d84/go.mod h1:qSS0cLIKTyysdkvGr4cMlTOHO0zkoobFcfvAVPtoq5Y=
github.com/devfile/library v1.2.1-0.20220201022328-58ef0b78c0fe h1:IzpRD2XS7m7k+6lFLYjaFAPYy0CSv0861teFvzNFkdM=
github.com/devfile/library v1.2.1-0.20220201022328-58ef0b78c0fe/go.mod h1:Fp8wxWPVA5pz8geGIp0DioGVgnZAdwyqsgohvRaR5rk=
github.com/devfile/registry-support/index/generator v0.0.0-20211012185733-0a73f866043f h1:fKNUmoOPh7yAs69uMRZWHvev+m3e7T4jBL/hOXZB9ys=
github.com/devfile/registry-support/index/generator v0.0.0-20211012185733-0a73f866043f/go.mod h1:bLGagbW2SFn7jo5+kUPlCMehIGqWkRtLKc5O0OyJMJM=
github.com/devfile/registry-support/registry-library v0.0.0-20211125162259-d7edf148d3e2 h1:Rwuc0bdx8xSZWdIwXjAxaKYnZIWHneJmDAAZ6a5jXzY=
Expand Down
14 changes: 9 additions & 5 deletions pkg/envinfo/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/redhat-developer/odo/pkg/util"
)

//getPorts gets the ports from devfile
// getPorts gets the ports from devfile
func (ei *EnvInfo) getPorts(container string) ([]string, error) {
var portList []string
containerComponents, err := ei.devfileObj.Data.GetDevfileContainerComponents(common.DevfileOptions{})
Expand All @@ -42,20 +42,20 @@ func (ei *EnvInfo) getPorts(container string) ([]string, error) {
return portList, nil
}

//GetContainerPorts returns list of the ports of specified container, if it exists
// GetContainerPorts returns list of the ports of specified container, if it exists
func (ei *EnvInfo) GetContainerPorts(container string) ([]string, error) {
if container == "" {
return nil, fmt.Errorf("please provide a container")
}
return ei.getPorts(container)
}

//GetComponentPorts returns all unique ports declared in all the containers
// GetComponentPorts returns all unique ports declared in all the containers
func (ei *EnvInfo) GetComponentPorts() ([]string, error) {
return ei.getPorts("")
}

//checkValidPort checks and retrieves valid port from devfile when no port is specified
// checkValidPort checks and retrieves valid port from devfile when no port is specified
func (ei *EnvInfo) checkValidPort(url *localConfigProvider.LocalURL, portsOf string, ports []string) (err error) {
if url.Port == -1 {
if len(ports) > 1 {
Expand Down Expand Up @@ -191,7 +191,11 @@ func (ei *EnvInfo) ValidateURL(url localConfigProvider.LocalURL) error {
}
for _, endpoint := range component.Container.Endpoints {
if endpoint.Name == url.Name && !ei.updateURL {
return fmt.Errorf("url %v already exist in devfile endpoint entry under container %v", url.Name, component.Name)
return fmt.Errorf("url %v already exists in devfile endpoint entry under container %q", url.Name, component.Name)
}
// Check for a duplicate port entry
if endpoint.TargetPort == url.Port && !ei.updateURL {
return fmt.Errorf("port %v already exists in devfile endpoint entry under container %q", url.Port, component.Name)
}
containerPortMap[endpoint.TargetPort] = component.Name
}
Expand Down
39 changes: 34 additions & 5 deletions pkg/envinfo/url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,11 +520,7 @@ func TestEnvInfo_ValidateURL(t *testing.T) {
fields: fields{
devfileObj: odoTestingUtil.GetTestDevfileObj(fs),
componentSettings: ComponentSettings{
URL: &[]localConfigProvider.LocalURL{
{
Name: "port-3030",
},
},
URL: &[]localConfigProvider.LocalURL{},
},
},
args: args{
Expand Down Expand Up @@ -616,6 +612,39 @@ func TestEnvInfo_ValidateURL(t *testing.T) {
updateURL: true,
wantErr: false,
},
{
name: "case 14: create a new url with a port that already exists in a devfile endpoint",
fields: fields{
devfileObj: odoTestingUtil.GetTestDevfileObj(fs),
componentSettings: ComponentSettings{
URL: &[]localConfigProvider.LocalURL{},
},
},
args: args{
url: localConfigProvider.LocalURL{
Name: "myport",
Port: 3000,
},
},
wantErr: true,
},
{
name: "case 15: update url with a port that already exists in a devfile endpoint",
fields: fields{
devfileObj: odoTestingUtil.GetTestDevfileObj(fs),
componentSettings: ComponentSettings{
URL: &[]localConfigProvider.LocalURL{},
},
},
args: args{
url: localConfigProvider.LocalURL{
Port: 3000,
Host: "something.com",
},
},
wantErr: false,
updateURL: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
15 changes: 7 additions & 8 deletions tests/integration/cmd_link_unlink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package integration

import (
"fmt"
"path/filepath"
"strings"

. "github.com/onsi/ginkgo"
Expand Down Expand Up @@ -61,22 +60,21 @@ var _ = Describe("odo link and unlink command tests", func() {
}

// createAndPush: creates component, a URL for it and deploys it
var createAndPush = func(compType string, compName string, contextDir string) {
helper.CopyExample(filepath.Join("source", compType), contextDir)
helper.Cmd("odo", "create", compName, "--context", contextDir, "--project", commonVar.Project, "--devfile", helper.GetExamplePath("source", "devfiles", compType, "devfile-registry.yaml")).ShouldPass()
helper.Cmd("odo", "url", "create", "--port", "8080", "--context", contextDir).ShouldPass()
var createAndPush = func(compType string, compName string, contextDir string, starterName string) {
// Download the starter project since the ones present locally are not downloaded from the same registry(staging) as devfile-registry.yaml, and will fail
helper.Cmd("odo", "create", compName, "--context", contextDir, "--project", commonVar.Project, "--devfile", helper.GetExamplePath("source", "devfiles", compType, "devfile-registry.yaml"), "--starter", starterName).ShouldPass()
helper.Cmd("odo", "push", "--context", contextDir).ShouldPass()
}

BeforeEach(func() {
frontendComp = fmt.Sprintf("frontend-%v", helper.RandString(3))
frontendContext = helper.CreateNewContext()
createAndPush("nodejs", frontendComp, frontendContext)
createAndPush("nodejs", frontendComp, frontendContext, "nodejs-starter")
frontendURL = helper.DetermineRouteURL(frontendContext)

backendComp = fmt.Sprintf("backend-%v", helper.RandString(3))
backendContext = helper.CreateNewContext()
createAndPush("python", backendComp, backendContext)
createAndPush("python", backendComp, backendContext, "python-example")
})

AfterEach(func() {
Expand All @@ -101,11 +99,12 @@ var _ = Describe("odo link and unlink command tests", func() {
When("the link is pushed", func() {
BeforeEach(func() {
helper.Cmd("odo", "push", "--context", frontendContext).ShouldPass()
frontendURL = helper.DetermineRouteURL(frontendContext)
})
It("should ensure that the proper envFrom entry was created", func() {
envFromOutput := commonVar.CliRunner.GetEnvFromEntry(frontendComp, "app", commonVar.Project)
Expect(envFromOutput).To(ContainSubstring(backendComp))
helper.HttpWaitFor(frontendURL, "Hello world from node.js!", 20, 1)
helper.HttpWaitFor(frontendURL, "Hello from Node.js Starter Application!", 20, 1)
})
It("should find the link and environment variables in odo describe", func() {
checkDescribe(frontendContext, backendComp, true, false)
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/devfile/cmd_devfile_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ var _ = Describe("odo devfile app command tests", func() {
helper.Cmd("odo", "create", "--project", namespace, component00, "--context", context00, "--app", app0, "--devfile", helper.GetExamplePath("source", "devfiles", "nodejs", "devfileNestedCompCommands.yaml")).ShouldPass()
helper.CopyExample(filepath.Join("source", "devfiles", "nodejs", "project"), context00)
helper.Cmd("odo", "storage", "create", storage00, "--path", "/data", "--size", "1Gi", "--context", context00).ShouldPass()
helper.Cmd("odo", "url", "create", url00, "--port", "3000", "--context", context00, "--host", "com", "--ingress").ShouldPass()
helper.Cmd("odo", "url", "create", url00, "--port", "2000", "--context", context00, "--host", "com", "--ingress").ShouldPass()
helper.Cmd("odo", "push", "--context", context00).ShouldPass()

info = testInfo{
Expand Down Expand Up @@ -199,7 +199,7 @@ func runner(info testInfo) {
Expect(helper.IsJSON(stdOut)).To(BeTrue())

stdOut = helper.Cmd("odo", "app", "describe", info.app0, "--project", info.namespace).ShouldPass().Out()
helper.MatchAllInOutput(stdOut, []string{info.app0, info.comp0, info.comp00, info.storage00, info.url00, "http", "3000"})
helper.MatchAllInOutput(stdOut, []string{info.app0, info.comp0, info.comp00, info.storage00, info.url00, "http", "2000"})

// test the json output
stdOut = helper.Cmd("odo", "app", "describe", info.app0, "--project", info.namespace, "-o", "json").ShouldPass().Out()
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/devfile/cmd_devfile_delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,10 @@ var _ = Describe("odo devfile delete command tests", func() {
resourceTypes := []string{helper.ResourceTypeDeployment, helper.ResourceTypePod, helper.ResourceTypeService, helper.ResourceTypeIngress, helper.ResourceTypePVC}

BeforeEach(func() {
helper.Cmd("odo", "url", "create", "example", "--host", "1.2.3.4.nip.io", "--port", "3000", "--ingress").ShouldPass()
helper.Cmd("odo", "url", "create", "example", "--host", "1.2.3.4.nip.io", "--port", "3030", "--ingress").ShouldPass()

if os.Getenv("KUBERNETES") != "true" {
helper.Cmd("odo", "url", "create", "example-1", "--port", "3000").ShouldPass()
helper.Cmd("odo", "url", "create", "example-1", "--port", "4000").ShouldPass()
resourceTypes = append(resourceTypes, helper.ResourceTypeRoute)
}
helper.Cmd("odo", "storage", "create", "storage-1", "--size", "1Gi", "--path", "/data1", "--context", commonVar.Context).ShouldPass()
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/devfile/cmd_devfile_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var _ = Describe("odo devfile status command tests", func() {
helper.CommonAfterEach(commonVar)
})

//Function used to test context: "Verify URL status is correctly reported"
// Function used to test context: "Verify URL status is correctly reported"
testCombo := func(ingress bool, secure bool, name string) {
defer GinkgoRecover()
It("Verify that odo component status detects the URL status: "+name, func() {
Expand All @@ -48,7 +48,7 @@ var _ = Describe("odo devfile status command tests", func() {
}
urlHost := helper.RandString(12) + ".com"

urlParams := []string{"url", "create", "my-url", "--port", "3000"}
urlParams := []string{"url", "create", "my-url", "--port", "4000"}
if secure {
urlParams = append(urlParams, "--secure")
}
Expand Down
Loading