Skip to content

Commit

Permalink
Merge pull request #7226 from ashley-cui/v2.0
Browse files Browse the repository at this point in the history
v2.0 Backports
  • Loading branch information
openshift-merge-robot authored Aug 5, 2020
2 parents 0d81149 + 3b22faa commit 9a9ad85
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 4 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ podman-remote-release-%.zip:
cp release.txt "$(TMPDIR)/"
cp ./bin/podman-remote-$*$(BINSFX) "$(TMPDIR)/$(SUBDIR)/podman$(BINSFX)"
cp -r ./docs/build/remote/$* "$(TMPDIR)/$(SUBDIR)/docs/"
cp ./contrib/remote/containers.conf "$(TMPDIR)/$(SUBDIR)/"
cd "$(TMPDIR)/$(SUBDIR)" && \
zip --recurse-paths "$(CURDIR)/$@" "./release.txt" "./"
-rm -rf "$(TMPDIR)"
Expand Down
11 changes: 11 additions & 0 deletions contrib/remote/containers.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# The containers configuration file specifies all of the available configuration
# command-line options/flags for container engine tools like Podman
# but in a TOML format that can be easily modified and versioned.

[engine]

# Default Remote URI to access the Podman service.
# Examples:
# remote rootless ssh://engineering.lab.company.com/run/user/1000/podman/podman.sock
# remote rootfull ssh://[email protected]:22/run/podman/podman.sock
# remote_uri= ""
4 changes: 1 addition & 3 deletions pkg/domain/infra/abi/play.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,7 @@ func getPodPorts(containers []v1.Container) []ocicni.PortMapping {
HostPort: p.HostPort,
ContainerPort: p.ContainerPort,
Protocol: strings.ToLower(string(p.Protocol)),
}
if p.HostIP != "" {
logrus.Debug("HostIP on port bindings is not supported")
HostIP: p.HostIP,
}
// only hostPort is utilized in podman context, all container ports
// are accessible inside the shared network namespace
Expand Down
35 changes: 34 additions & 1 deletion test/e2e/play_kube_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ spec:
{{ end }}
privileged: false
readOnlyRootFilesystem: false
ports:
- containerPort: {{ .Port }}
hostIP: {{ .HostIP }}
hostPort: {{ .Port }}
protocol: TCP
workingDir: /
{{ end }}
{{ end }}
Expand Down Expand Up @@ -338,12 +343,14 @@ type Ctr struct {
CapAdd []string
CapDrop []string
PullPolicy string
HostIP string
Port string
}

// getCtr takes a list of ctrOptions and returns a Ctr with sane defaults
// and the configured options
func getCtr(options ...ctrOption) *Ctr {
c := Ctr{defaultCtrName, defaultCtrImage, defaultCtrCmd, defaultCtrArg, true, false, nil, nil, ""}
c := Ctr{defaultCtrName, defaultCtrImage, defaultCtrCmd, defaultCtrArg, true, false, nil, nil, "", "", ""}
for _, option := range options {
option(&c)
}
Expand Down Expand Up @@ -396,6 +403,13 @@ func withPullPolicy(policy string) ctrOption {
}
}

func withHostIP(ip string, port string) ctrOption {
return func(c *Ctr) {
c.HostIP = ip
c.Port = port
}
}

func getCtrNameInPod(pod *Pod) string {
return fmt.Sprintf("%s-%s", pod.Name, defaultCtrName)
}
Expand Down Expand Up @@ -815,4 +829,23 @@ spec:
Expect(inspect.OutputToString()).To(ContainSubstring(correctCmd))
}
})

It("podman play kube test with network portbindings", func() {
ip := "127.0.0.100"
port := "5000"
ctr := getCtr(withHostIP(ip, port), withImage(BB))

pod := getPod(withCtr(ctr))
err := generatePodKubeYaml(pod, kubeYaml)
Expect(err).To(BeNil())

kube := podmanTest.Podman([]string{"play", "kube", kubeYaml})
kube.WaitWithDefaultTimeout()
Expect(kube.ExitCode()).To(Equal(0))

inspect := podmanTest.Podman([]string{"port", getCtrNameInPod(pod)})
inspect.WaitWithDefaultTimeout()
Expect(inspect.ExitCode()).To(Equal(0))
Expect(inspect.OutputToString()).To(Equal("5000/tcp -> 127.0.0.100:5000"))
})
})

0 comments on commit 9a9ad85

Please sign in to comment.