mirror of
https://github.com/containers/podman.git
synced 2025-06-27 21:50:18 +08:00
Publish IP from YAML (podman play kube)
podman play kube didn't set host ip correctly from YAML Signed-off-by: Ashley Cui <acui@redhat.com>
This commit is contained in:
@ -340,9 +340,7 @@ func getPodPorts(containers []v1.Container) []ocicni.PortMapping {
|
|||||||
HostPort: p.HostPort,
|
HostPort: p.HostPort,
|
||||||
ContainerPort: p.ContainerPort,
|
ContainerPort: p.ContainerPort,
|
||||||
Protocol: strings.ToLower(string(p.Protocol)),
|
Protocol: strings.ToLower(string(p.Protocol)),
|
||||||
}
|
HostIP: p.HostIP,
|
||||||
if p.HostIP != "" {
|
|
||||||
logrus.Debug("HostIP on port bindings is not supported")
|
|
||||||
}
|
}
|
||||||
// only hostPort is utilized in podman context, all container ports
|
// only hostPort is utilized in podman context, all container ports
|
||||||
// are accessible inside the shared network namespace
|
// are accessible inside the shared network namespace
|
||||||
|
@ -87,6 +87,11 @@ spec:
|
|||||||
{{ end }}
|
{{ end }}
|
||||||
privileged: false
|
privileged: false
|
||||||
readOnlyRootFilesystem: false
|
readOnlyRootFilesystem: false
|
||||||
|
ports:
|
||||||
|
- containerPort: {{ .Port }}
|
||||||
|
hostIP: {{ .HostIP }}
|
||||||
|
hostPort: {{ .Port }}
|
||||||
|
protocol: TCP
|
||||||
workingDir: /
|
workingDir: /
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
@ -338,12 +343,14 @@ type Ctr struct {
|
|||||||
CapAdd []string
|
CapAdd []string
|
||||||
CapDrop []string
|
CapDrop []string
|
||||||
PullPolicy string
|
PullPolicy string
|
||||||
|
HostIP string
|
||||||
|
Port string
|
||||||
}
|
}
|
||||||
|
|
||||||
// getCtr takes a list of ctrOptions and returns a Ctr with sane defaults
|
// getCtr takes a list of ctrOptions and returns a Ctr with sane defaults
|
||||||
// and the configured options
|
// and the configured options
|
||||||
func getCtr(options ...ctrOption) *Ctr {
|
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 {
|
for _, option := range options {
|
||||||
option(&c)
|
option(&c)
|
||||||
}
|
}
|
||||||
@ -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 {
|
func getCtrNameInPod(pod *Pod) string {
|
||||||
return fmt.Sprintf("%s-%s", pod.Name, defaultCtrName)
|
return fmt.Sprintf("%s-%s", pod.Name, defaultCtrName)
|
||||||
}
|
}
|
||||||
@ -815,4 +829,23 @@ spec:
|
|||||||
Expect(inspect.OutputToString()).To(ContainSubstring(correctCmd))
|
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"))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user