18 Commits

Author SHA1 Message Date
Parthvi Vala
010e9634d3 Use custom address for port forwarding (#6766)
* Custom address for port forwarding

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* Add integration tests

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* Use private variables for custom address and ports

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* Update pkg/util/util.go

Co-authored-by: Armel Soro <armel@rm3l.org>

* Assign custom address to HostIP for podman

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* Add validation for free port when --port-forward is provided in the Validate() method, add integration test for running parallel dev sessions on same platform, same port and different addresses

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* Fix unit test failure

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* Attempt at fixing windows failure

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* Add documentation

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* Use default value for --address flag

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* Changes from review

Co-authored-by: Armel Soro <asoro@redhat.com>
Signed-off-by: Parthvi Vala <pvala@redhat.com>

---------

Signed-off-by: Parthvi Vala <pvala@redhat.com>
Co-authored-by: Armel Soro <armel@rm3l.org>
Co-authored-by: Armel Soro <asoro@redhat.com>
2023-05-02 07:34:19 -04:00
Armel Soro
4bab9285fb Allow to cancel execution of odo dev at any phase (e.g. if build command is taking long) (#6736)
* Add test cases simulating build or run commands that take very long

* Pass a context around to relevant functions and methods

This will allow to handle cancellations and timeouts and deadlines as needed

* Pass the context to Podman exec command too

* fixup! Add test cases simulating build or run commands that take very long
2023-04-20 17:12:28 +00:00
Philippe Martin
bd5098eb53 Use devstats.PID.json as devstate (#6713)
* Use devstate.PID.json

* odo describe component gets forwarded ports from devstate.json

* Pass pid in context

* Add platform to state

* Overwrite devstate.json if PId not exists

* odo describe component displays forwarded ports from podman/cluster

* Start only one session on platform

* Fix integration test

* Review

* Fix

* Update pkg/state/errors.go

Co-authored-by: Armel Soro <armel@rm3l.org>

* Integration tests

* Fix integration test

---------

Co-authored-by: Armel Soro <armel@rm3l.org>
2023-04-19 04:16:08 -04:00
Parthvi Vala
912f6d14e6 Fix flaky unit Test_getCompleteCustomPortPairs (#6737)
* Fix flaky unit Test_getCompleteCustomPortPairs

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* Use range check

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* Revert "Use range check"

This reverts commit 1bcbacf184.

* Use order to iterate over ceMapping

Signed-off-by: Parthvi Vala <pvala@redhat.com>

---------

Signed-off-by: Parthvi Vala <pvala@redhat.com>
2023-04-18 10:18:49 -04:00
Parthvi Vala
e6a7f0253b Fix: random port matches a custom local port (#6727)
Signed-off-by: Parthvi Vala <pvala@redhat.com>
2023-04-12 02:42:32 -04:00
Parthvi Vala
c82583bdc3 Allow users to define custom port-mappings for port forwarding [Kubernetes] (#6704)
* Allow users to define custom port-mappings for port forwarding: add methods to parse and validate  the flag

* Add methods to kube port-forwarding to obtain custom port pairs

Co-authored-by: Armel Soro <asoro@redhat.com>
Co-authored-by: Philippe Martin <phmartin@redhat.com>

* Pass custom port-mappings from CLI to Business layer

Co-authored-by: Armel Soro <asoro@redhat.com>
Co-authored-by: Philippe Martin <phmartin@redhat.com>

* Add integration test

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* Add integration test for debug

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* Add check for using --random-ports and --port-forward together

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* Return all validation errors for --port-forward flag at once

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* Use random local ports for integration testing

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* Fix ci failures

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* Print invalids of --port-forward to stderr so that they are printed when debugging

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* Attempt at fixing the test failure on windows

Signed-off-by: Parthvi Vala <pvala@redhat.com>

Remove the use of seed for randomzing

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* Use global counters for generate port number

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* Apply changes from code review

Co-authored-by: Armel Soro <asoro@redhat.com>

---------

Signed-off-by: Parthvi Vala <pvala@redhat.com>
Co-authored-by: Armel Soro <asoro@redhat.com>
Co-authored-by: Philippe Martin <phmartin@redhat.com>
2023-04-06 15:37:36 -04:00
Armel Soro
29b5a38f88 Make port-forwarding work on Podman with apps listening on the loopback interface, via a new --forward-localhost flag (#6629)
* Embed platform.Client interface in platform-specific interfaces

This avoids repeating the same methods in both interfaces,
and makes the intent clearer.

* Verify interface compliance of PodmanCli at compile time

This is recommended in the Coding Conventions guidelines [1].
Specifically, what's important here is checking that it meets the 'platform.Client' contract.

[1] https://github.com/redhat-developer/odo/wiki/Dev:-Coding-Conventions#verify-interface-compliance

* Move K8s-specific implementation of port-forwarding to a dedicated package

This paves the way to providing a different implementation for Podman

* Remove GetPortsToForward method from the portForward.Client interface

Current implementation relies on the Devfile object,
so it makes more sense to be in the libdevfile package.

* Monitor and send appropriate status events after starting a remote command process

This allows callers to get more meaningful events about the process.

* Implement port-forwarding logic on Podman

As explained in [1], this makes use of a helper sidecar container
(aptly named "odo-helper-port-forwarding") to be added to the Pod Spec created by odo.
In this scope, port-forwarding will be equivalent of executing a socat command in this
helper container, like so:

socat -d tcp-listen:20002,reuseaddr,fork tcp:localhost:5858

In the command above, this will open up port 20001 on the helper container,
and forwarding requests to localhost:5858
(which would be in the application container, part of the same Pod)

[1] https://github.com/redhat-developer/odo/issues/6510

* Update portForward.Client interface methods

Specifically, the 'StartPortForwarding' method
can now accept an explicit list of ports that needs to
be forwarded, if the caller can compute provide such information.

This is currently useful on Podman where the ports
(even the random ones) are known in advance.

* Add helper sidecar container to the Pod Spec generated on Podman

As explained in [1], this helper sidecar container (aptly named "odo-helper-port-forwarding")
will hold the actual container/host ports mapping in the spec
(to overcome the limitation of using hostPort against a container app listening on the loopback interface);
this running container will be used to execute the actual port-forwarding commands (based on socat), e.g:

```
apiVersion: v1
kind: Pod
metadata:
  name: my-component-app
  labels:
    app: my-component-app
spec:
  containers:
  - name: runtime
    command: [ 'tail', '-f', '/dev/null']
    # Omitted for brevity, but imagine an application being executed by odo
    # and listening on both 0.0.0.0:3000 and 127.0.0.1:5858

  - name: odo-helper-port-forwarding
    image: quay.io/devfile/base-developer-image:ubi8-latest
    command: [ 'tail', '-f', '/dev/null']
    ports:
    - containerPort: 20001
      # A command will be executed by odo, e.g.: 'socat -d -d tcp-listen:20001,reuseaddr,fork tcp:localhost:3000'
      hostPort: 20001
    - containerPort: 20002
      # A command will be executed by odo, e.g.: 'socat -d -d tcp-listen:20002,reuseaddr,fork tcp:localhost:5858'
      hostPort: 20002

# ... Omitted for brevity
```

In this scope, port-forwarding from 20002 to 5858 for example will be equivalent of executing
a socat command in this helper container, like so:

socat -d tcp-listen:20002,reuseaddr,fork tcp:localhost:5858

In the command above, this will open up port 20001 on the helper container,
and forwarding requests to localhost:5858
(which would be in the 'runtime' container, part of the same Pod)

[1] https://github.com/redhat-developer/odo/issues/6510

* Inject the right portForward client depending on the platform

* Delegate port-forwarding on Podman to the appropriate client

* Implement --forward-localhost on Podman

* Add unit and integration test cases

* Cover more debug-related test cases on Podman

* Expose the endpoint protocol so as to instruct socat to listen and forward the right protocol

* Fix sub-deps of EXEC and PORT_FORWARD, as suggested in review
2023-03-06 08:12:22 +01:00
Armel Soro
9a39462615 Show information about forwarded debug ports in odo describe component (#6537)
* Refactor 'libdevfile#GetContainerEndpointMapping' so it returns the whole Endpoint struct

It will help extract useful information like the port name and exposure.

* Fix typo in parameter name (in portForward#Client interface)

* Display the port names in the output of 'odo describe component'

* Display the port exposures in the output of 'odo describe component'

* Tell whether the port is a debug one or not in the output of 'odo describe component'

* Add integration tests meeting the expectations

* Update documentation
2023-01-27 12:02:57 -05:00
Parthvi Vala
19f8e0ebdb Update devfile/library to support pod-overrides and container-overrides attributes and add integration test for it (#6512)
* Update the Devfile library

* Add test for container-overrides and pod-overrides attributes

Signed-off-by: Parthvi Vala <pvala@redhat.com>

Attempt at fixing CI failures

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* Fix CI failure

* Attempt at fixing OC integration test failures

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* Use random name in integration test

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* Rebase and fix integration test failure

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* Make integration test work for podman

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* Temp attempt at fixing podman test for GH

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* Another attempt at fixing CI test for podman

Signed-off-by: Parthvi Vala <pvala@redhat.com>

* One more attempt at fixing integration test for podman

Signed-off-by: Parthvi Vala <pvala@redhat.com>

Signed-off-by: Parthvi Vala <pvala@redhat.com>
2023-01-23 15:21:18 -05:00
Philippe Martin
d2443d0fc0 Change port range used for port-forwarding endpoints to start at 20001 (#6519)
* Change port forward to start at 20001

* Update docs
2023-01-23 13:21:00 -05:00
Armel Soro
d468842a32 Port-forward Debug endpoints only when running odo dev with --debug (#6505)
* Add integration tests meeting the expectations

* Refactor 'libdevfile.GetContainerEndpointMapping' such that it returns debug endpoints only if told so

* [Kubernetes] Port-forward Debug endpoints only if running in Debug mode

* [Podman] Port-forward Debug endpoints only if running in Debug mode

* Use '--inspect' instead of '--inspect-brk' to run the "debug" script in Node.JS sample projects

'--inspect-brk' stops the execution at the start of the command
(waiting for a debugger to attach to it) while '--inspect' does not.
We need the application to be started regardless of whether a debugger
is attached or not, as we are testing that we can communicate with
the forwarded ports.

* Temporarily skip the test step on Podman that connects to the forwarded debug port until [1] is fixed

We can work on fixing the issue on Podman in a separate PR.

[1] https://github.com/redhat-developer/odo/issues/6510
2023-01-19 06:21:55 -05:00
Philippe Martin
d982a751d6 Make odo dev work if no endpoint is defined (#6472)
* odo dev works if no endpoint is defined

* Update tests/integration/cmd_dev_test.go

Co-authored-by: Armel Soro <armel@rm3l.org>

* Add log when no port to forward

Co-authored-by: Armel Soro <armel@rm3l.org>
2023-01-06 15:14:22 -05:00
Philippe Martin
6c99ca1024 Get next free port when forwarding ports on podman (#6377)
* Refacto get first free port

* Use next free port for Podman

* Save used ports to reuse them

* Fix unit tests

* Do not rely on system for ports during tests
2022-12-09 06:41:29 -05:00
Armel Soro
5660093167 Use go-cmp instead of reflect.DeepEqual to compare unit test results (#6343) 2022-11-24 07:24:32 -05:00
Philippe Martin
53a7c3cd1b Restart port forwarding on failure (#6013)
* Restart port forwarding on failure

* Save ports again when port forward is restarted

* Integration test

* Update pkg/portForward/portForward.go

Co-authored-by: Dharmit Shah <shahdharmit@gmail.com>

* Fix rebase

* Fix integration test with run composite command

* Copy errorhandlers

* Add timeout for first-time port forwarding

Co-authored-by: Dharmit Shah <shahdharmit@gmail.com>
2022-08-11 08:20:41 +00:00
Philippe Martin
f22c3f854d odo dev: react to changes as soon as possible (#5933)
* Create auxialiary functions to find current deployment and pod name

* Create auxialiary function for pushing Kubernetes components to cluster

* Auxiliary function getPushDevfileCommands and remocve RunModeChanged flag as it is not possible anymore with long running dev command
+ move prelimiray tests at the beginning

* Create auxiliary function updatePVCsOwnerReferences + move isMainStorageEphemeral inside aux. function

* Watch for deployments in addition to watching for files during odo dev

* - Check the Deployment Generation to return earlier when generation changed
- Return earlier when pod is not ready

* Push receives a Status that it can update, to indicate the status of the component when the function returns. This status is passed from Start to Watch

* Use status to decide to sync files

* Simplify getting pod

* Status for PostStartEvents

* - Touch .gitignore earlier so it is not synced
- Add devstate.jso file to .gitignore

* Fix the integration tests.

* Make --no-watch work again

* Get smaller volumes for tests

* Quit when fail to exec port forwarding

* Exponential delay after an error

* Fix: get running pod

* Remove testing odo dev stops when the build command fails. odo dev now gives a change to the user to fix the problem

* Fix order or volumes and volume mounts in pod spec

* Use server side apply for updating PVC when supported

* Watch Devfile separately

* Adapt tests for devfile handled separately

* Update forwarded ports when necessary

* Display kubernetes resources created only when created/updated

* Do not set ResourceVersion when patching

* TEMP: Add more logs on failing integrattests

* Tests: select the *running* pod

* Use forward slashes for .gitignore content, even on Windows

* Rename GetOnePodFromSelector to GetRunningPodFromSelector

* Cleanup logs

* Fix 'odo log' integration test

* Add log "Waiting for Kubernetes resources"

* Fail if service bindings are not injected

* Rename sources related watcher, timer

* Fix delay after error

* Display info about Pod

* Disambiguate error messages

* Display events related to components pod

* Remove now unused functions used to wait for Deployment / Pod

* Typos + function renaming

* Do not watch devfile with --no-watch

* Use type switch for Kubernertes watch event

* Do not fail when watching Events is Forbidden

* Do not fail when servicebinding resources are forbidden

* Exit when build command fails on no-watch mode

* Sync devfile.yaml by default, workaround when commands change on devfile

* Rename to warningsWatcher

* Fix comment
2022-08-08 10:20:55 +00:00
Charlie Drage
02bd7b8d01 Refactor color througout interactive mode and dev (#5963)
* Refactor color througout interactive mode and dev

<!--
Thank you for opening a PR! Here are some things you need to know before submitting:

1. Please read our developer guideline: https://github.com/redhat-developer/odo/wiki/Dev:-odo-Dev-Guidelines
2. Label this PR accordingly with the '/kind' line
3. Ensure you have written and ran the appropriate tests: https://github.com/redhat-developer/odo/wiki/Dev:-Writing-and-running-tests
4. Read how we approve and LGTM each PR: https://github.com/redhat-developer/odo/wiki/Pull-Requests:-Review-guideline

Documentation:

If you are pushing a change to documentation, please read: https://github.com/redhat-developer/odo/wiki/Documentation:-Contributing
-->

**What type of PR is this:**

<!--
Add one of the following kinds:
/kind bug
/kind feature
/kind tests
/kind documentation

Feel free to use other [labels](https://github.com/redhat-developer/odo/labels) as needed. However one of the above labels must be present or the PR will not be reviewed. This instruction is for reviewers as well.
-->
/kind cleanup

**What does this PR do / why we need it:**

This PR fixes the following:
- Updates the interactive mode so it's better looking when outputting
  configuration so it's similar to the rest of the output:

```sh
? Is this correct? Yes
 ✓  Downloading devfile "nodejs" from registry "DefaultDevfileRegistry" [1s]

↪ Container Configuration "runtime":
  OPEN PORTS:
    - 3000
  ENVIRONMENT VARIABLES:

? Select container for which you want to change configuration? runtime
? What configuration do you want change? Delete port "3000"
? What configuration do you want change? NOTHING - configuration is correct

↪ Container Configuration "runtime":
  OPEN PORTS:
  ENVIRONMENT VARIABLES:

? Select container for which you want to change configuration?  [Use arrows to move, type to filter]
  runtime
> NONE - configuration is correct
```

- Removes issue of fgGreen not appearing correctly because of direct use
  of `color` instead of log/status.go. This is due to color not
  detecting if the terminal supports the color, which is done in
  `log/status.go` instead.

**Which issue(s) this PR fixes:**
<!--
Specifying the issue will automatically close it when this PR is merged
-->

Fixes https://github.com/redhat-developer/odo/issues/5843

**How to test changes / Special notes to the reviewer:**

Signed-off-by: Charlie Drage <charlie@charliedrage.com>

* Update to not use println in business layer

Signed-off-by: Charlie Drage <charlie@charliedrage.com>
2022-07-26 18:12:33 +02:00
Philippe Martin
336b9e1702 odo dev: handle port forwarding after pod restart (#5885)
* Move port forwarding to reconcile loop

* Add integration test

* Fix dependencies on cli/dev + remove message to restart odo dev after devfile.yaml changes

* Restart port forwarding when endpoints are modified in Devfile

* Fix setNamespace

* Fix componentName

* Move message back to CLI

* add doc

* Move port forwarding after starting application

* Remove unnecessary dependency to State module

* Fix err
2022-07-04 08:43:37 +00:00