Skip to content

Commit

Permalink
Fix ci failures
Browse files Browse the repository at this point in the history
Signed-off-by: Parthvi Vala <pvala@redhat.com>
  • Loading branch information
valaparthvi committed Apr 3, 2023
1 parent 8b337ae commit 9212408
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
10 changes: 7 additions & 3 deletions pkg/odo/cli/dev/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"k8s.io/klog"
"path/filepath"
"regexp"
"sort"
"strconv"
"strings"

Expand Down Expand Up @@ -65,7 +66,7 @@ type DevOptions struct {
runCommandFlag string
ignoreLocalhostFlag bool
forwardLocalhostFlag bool
portForwardFlag []string
portForwardFlag []string
}

var _ genericclioptions.Runnable = (*DevOptions)(nil)
Expand Down Expand Up @@ -355,7 +356,9 @@ portLoop:
} else {
// Validate that a custom port mapping for port forwarding config without a container targets a unique containerPort
if containers, ok := portContainerMapping[fPort.ContainerPort]; ok && len(containers) > 1 {
msg := fmt.Sprintf("multiple container components (%s) found with same container port %d in the devfile, port forwarding must be defined with format <localPort>:<containerName>:<containerPort>", strings.Join(portContainerMapping[fPort.ContainerPort], ", "), fPort.ContainerPort)
// this workaround makes sure the unit tests do not fail because of a change in the order
sort.Strings(containers)
msg := fmt.Sprintf("multiple container components (%s) found with same container port %d in the devfile, port forwarding must be defined with format <localPort>:<containerName>:<containerPort>", strings.Join(containers, ", "), fPort.ContainerPort)
if !strings.Contains(strings.Join(errors, ", "), msg) {
errors = append(errors, msg)
}
Expand Down Expand Up @@ -384,9 +387,10 @@ func parsePortForwardFlag(portForwardFlag []string) (forwardedPorts []api.Forwar
// acceptable examples: 8000:runtime_123:8080, 8000:9000, 8000:runtime:8080, 20001:20000
// unacceptable examples: :8000, 80000:
pattern := `^(\d{1,5})(:\w*)?:(\d{1,5})$`
portReg := regexp.MustCompile(pattern)
const largestPortValue = 65535
for _, portData := range portForwardFlag {
if matched, _ := regexp.MatchString(pattern, portData); !matched {
if !portReg.MatchString(portData) {
return nil, errors.New("ports are not defined properly, acceptable formats are: <localPort>:<containerPort>, <localPort>:<containerName>:<containerPort>")
}
var portF api.ForwardedPort
Expand Down
6 changes: 3 additions & 3 deletions tests/helper/helper_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func GetRandomFreePort(portRange ...int) string {
max := 65535
min := 1024
var (
startPort = rand.Intn(max-min) + min
startPort = rand.Intn(max-min) + min // #nosec // cannot use crypto/rand library here
endPort = max
)
// WARN: If length of portRange is anything other than 2 and first index is gte second index, it will be ignored
Expand All @@ -68,8 +68,8 @@ func GetRandomFreePort(portRange ...int) string {
}
freePort, err := util.NextFreePort(startPort, endPort, nil)
if err != nil {
Fail(fmt.Sprintf("failed to obtain a free port"))
Fail("failed to obtain a free port")
}
return strconv.Itoa(freePort)

}
}
1 change: 1 addition & 0 deletions tests/helper/helper_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func CmdRunner(program string, args ...string) *gexec.Session {
func WaitForOutputToContain(substring string, timeoutInSeconds int, intervalInSeconds int, session *gexec.Session) {

Eventually(func() string {
// TODO: if the session has exited, return early
contents := string(session.Out.Contents())
return contents
}, timeoutInSeconds, intervalInSeconds).Should(ContainSubstring(substring))
Expand Down

0 comments on commit 9212408

Please sign in to comment.