Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable port forwarding on host #10488

Merged
merged 1 commit into from
Jun 1, 2021

Conversation

baude
Copy link
Member

@baude baude commented May 27, 2021

Using the gvproxy application on the host, we can now port forward from
the machine vm on the host. It requires that 'gvproxy' be installed in
an executable location. gvproxy can be found in the
containers/gvisor-tap-vsock github repo.

[NO TESTS NEEDED]

Signed-off-by: Brent Baude bbaude@redhat.com

@openshift-ci
Copy link
Contributor

openshift-ci bot commented May 27, 2021

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: baude

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 27, 2021
@Luap99
Copy link
Member

Luap99 commented May 27, 2021

Ah, always parsing the --network flag breaks podman pod create --infra=false.
This diff should fix this case:

diff --git a/cmd/podman/pods/create.go b/cmd/podman/pods/create.go
index 5600d8794..ce12b386c 100644
--- a/cmd/podman/pods/create.go
+++ b/cmd/podman/pods/create.go
@@ -171,6 +171,20 @@ func create(cmd *cobra.Command, args []string) error {
        if err != nil {
                return err
        }
+
+       net, err := cmd.Flags().GetString("network")
+       if err != nil {
+               return err
+       }
+
+       // If there is no infra container and the network flag was not set or set to "" or "default"
+       // set the the network namespace back to the default value. This is needed because
+       // NetFlagsToNetOptions sets the nsmode to either slirp or bridge in such case and specgen
+       // complains when a nsmode other than default is used with no infra container.
+       if !createOptions.Infra && (!cmd.Flag("network").Changed || net == "" || net == "default") {
+               createOptions.Net.Network = specgen.Namespace{NSMode: specgen.Default}
+       }
+
        if len(createOptions.Net.PublishPorts) > 0 {
                if !createOptions.Infra {
                        return errors.Errorf("you must have an infra container to publish port bindings to the host")

@baude
Copy link
Member Author

baude commented May 27, 2021

@Luap99 fixed, thanks!

@TomSweeneyRedHat
Copy link
Member

All kinds of test unhappiness @baude

@Luap99
Copy link
Member

Luap99 commented May 27, 2021

Sorry @baude, my previous fix broke other things. Please remove my previous change and try this diff instead:

diff --git a/cmd/podman/common/netflags.go b/cmd/podman/common/netflags.go
index bdd642d74..20f8c0a79 100644
--- a/cmd/podman/common/netflags.go
+++ b/cmd/podman/common/netflags.go
@@ -198,20 +198,22 @@ func NetFlagsToNetOptions(cmd *cobra.Command) (*entities.NetOptions, error) {
                return nil, err
        }
 
-       parts := strings.SplitN(network, ":", 2)
+       if network != "" {
+               parts := strings.SplitN(network, ":", 2)
 
-       ns, cniNets, err := specgen.ParseNetworkNamespace(network, containerConfig.Containers.RootlessNetworking == "cni")
-       if err != nil {
-               return nil, err
-       }
+               ns, cniNets, err := specgen.ParseNetworkNamespace(network, containerConfig.Containers.RootlessNetworking == "cni")
+               if err != nil {
+                       return nil, err
+               }
 
-       if len(parts) > 1 {
-               opts.NetworkOptions = make(map[string][]string)
-               opts.NetworkOptions[parts[0]] = strings.Split(parts[1], ",")
-               cniNets = nil
+               if len(parts) > 1 {
+                       opts.NetworkOptions = make(map[string][]string)
+                       opts.NetworkOptions[parts[0]] = strings.Split(parts[1], ",")
+                       cniNets = nil
+               }
+               opts.Network = ns
+               opts.CNINetworks = cniNets
        }
-       opts.Network = ns
-       opts.CNINetworks = cniNets
 
        aliases, err := cmd.Flags().GetStringSlice("network-alias")
        if err != nil {

Edit: This also doesn't work. I will take a look tomorrow but the main problem is that c/common is forcing brige/slirp as --network value.

Using the gvproxy application on the host, we can now port forward from
the machine vm on the host.  It requires that 'gvproxy' be installed in
an executable location.  gvproxy can be found in the
containers/gvisor-tap-vsock github repo.

[NO TESTS NEEDED]

Signed-off-by: Brent Baude <bbaude@redhat.com>
Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mheon
Copy link
Member

mheon commented Jun 1, 2021

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jun 1, 2021
@openshift-merge-robot openshift-merge-robot merged commit cbffddd into containers:master Jun 1, 2021
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 23, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants