Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make port-forwarding work on Podman with apps listening on the loopba…
…ck 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] #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] #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
- Loading branch information