4 Commits

Author SHA1 Message Date
Armel Soro
dcf9009df4 Do not error out in port detection if any of the /proc/net/{tc,ud}p{,6} files are missing in the dev container (#6831)
* Do  not error out in port detection if any of `/proc/net/{tc,ud}p{,6}` files are missing

/proc/net/{tc,ud}p6 files might be missing if IPv6 is disabled in the host networking stack,
as reported by a user on RHEL.

Actually /proc/net/{tc,ud}p* files might be totally missing if network stats are disabled.

* Do not error out if we are not able to detect container ports bound on the loopback interface

We are already displaying a warning in such case
(saying that port forwarding might not work correctly);
so this should not prevent port-forwarding messages to be displayed.

We are already behaving this way when detecting if endpoints in the Devfile
are actually opened in the container.
A warning is displayed if any error occurs while checking this.

* fixup! Do  not error out in port detection if any of `/proc/net/{tc,ud}p{,6}` files are missing
2023-05-23 09:36:39 -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
Armel Soro
72ea3cd9e5 Wait until expected ports are opened in the container before starting port-forwarding (#6701)
* Add function in 'port' package allowing to check whether given ports are actually opened and in LISTEN state in specified containers

* Wait on Kubernetes until the application is ready by checking the ports to forward to are actually opened (or a timeout expires)

This allows to display port-forwarding messages when the application is ready to accept requests.
Otherwise, if the application takes time to listen on the port,
and we try to reach the local forwarded port, port forwarding will
be restarted.
If we are using --random-ports, new random ports will be generated.

Known issue: with the backo-go exponential backoff implementation,
it seems hitting Ctrl-C does not stop waiting =>
we need to wait until the timeout is reached or the backoff is done.

* Wait on Podman until the application is ready by checking the ports to forward to are actually opened (or a timeout expires)

This allows to display port-forwarding messages when the application is ready to accept requests.
Otherwise, if the application takes time to listen on the port,
and we try to reach the local forwarded port, port forwarding will
be restarted.
If we are using --random-ports, new random ports will be generated.

Known issue: with the backo-go exponential backoff implementation,
it seems hitting Ctrl-C does not stop waiting =>
we need to wait until the timeout is reached or the backoff is done.

* Display warnings instead if the ports are not opened

While iterating on the application, it might feel
weird to stop the Dev Session immediately.
Plus, a lot of integration tests are not passing because
of source code not strictly matching the ports declared in the
(too many) Devfiles.

* Fix integration test checking the behavior when simulating an app taking long to start

* Fix output expected for documentation tests

* Add hint to run 'odo logs --follow [--platform]' to help understand why app is not listening on the expected ports

Co-authored-by: Parthvi Vala <pvala@redhat.com>

* Collect all unreachable ports along with the containers and return the list to the users

Co-authored-by: Parthvi Vala <pvala@redhat.com>

* Apply suggestions from code review

Co-authored-by: Parthvi Vala <pvala@redhat.com>

* fixup! Add hint to run 'odo logs --follow [--platform]' to help understand why app is not listening on the expected ports

* fixup! Add hint to run 'odo logs --follow [--platform]' to help understand why app is not listening on the expected ports

---------

Co-authored-by: Parthvi Vala <pvala@redhat.com>
2023-04-13 11:56:22 -04:00
Armel Soro
3adf8e5243 On Podman, detect if application is listening on the loopback interface, and either error out or not depending on --ignore-localhost (#6620)
* Add functions allowing to detect ports opened in a given container

Specifically, this will be useful in Podman to detect
applications that are bound to the loopback interface

* Make `odo dev` fail on Podman if we detect that the application is bound to the loopback interface (on any ports supposed to be forwarded)

Next step will be to provide an option for end-users
to override this behavior, by either:
- ignoring this error (--ignore-localhost);
- or explicitly adding a redirect via a side container (--forward-localhost)

More context in https://github.com/redhat-developer/odo/issues/6510#issuecomment-1439986558

* Add '--ignore-localhost' flag to 'odo dev' on Podman

Currently, `odo dev` on Podman will error out
if it detects that the application is listening on the container loopback interface.
Instead of erroring out, this flag allows users to ignore such failure; a warning will be displayed anyway if
the application is listening on the container loopback interface, but odo will not error out.
Ports will be marked as forwarded, but Podman might fail to redirect traffic to the application
if it is bound to this loopback interface.

* Add test cases

* Fix existing integration tests by passing --ignore-localhost on Podman

- odo describe component
- odo dev --debug

Some projects used there are listening to the loopback interface,
so they won't work on Podman unless --ignore-localhost is passed.

Next, we'll pass --forward-localhost when it is implemented,
so we can have a fully working project with port-forwarding.

* Extract logic for handling loopback ports in a separate method

Requested in review
2023-03-01 17:16:57 +01:00