summaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorzhangguanzhang <zhangguanzhang@qq.com>2020-08-27 15:45:04 +0800
committerzhangguanzhang <zhangguanzhang@qq.com>2020-08-27 17:32:51 +0800
commita2bb7bd36b22f45dbccabbab9dcca83abfda1682 (patch)
tree76919e0667f2c65ceeb6da30398b293f580d2d41 /libpod
parentf99954c7ca4428e501676fa47a63b5cecadd9454 (diff)
downloadpodman-a2bb7bd36b22f45dbccabbab9dcca83abfda1682.tar.gz
podman-a2bb7bd36b22f45dbccabbab9dcca83abfda1682.tar.bz2
podman-a2bb7bd36b22f45dbccabbab9dcca83abfda1682.zip
fix podman generate kube with HostAliases
Signed-off-by: zhangguanzhang <zhangguanzhang@qq.com>
Diffstat (limited to 'libpod')
-rw-r--r--libpod/kube.go18
1 files changed, 16 insertions, 2 deletions
diff --git a/libpod/kube.go b/libpod/kube.go
index 0068427a5..5f2c9e0fd 100644
--- a/libpod/kube.go
+++ b/libpod/kube.go
@@ -48,12 +48,22 @@ func (p *Pod) GenerateForKube() (*v1.Pod, []v1.ServicePort, error) {
return nil, servicePorts, errors.Errorf("pod %s only has an infra container", p.ID())
}
+ extraHost := make([]v1.HostAlias, 0)
if p.HasInfraContainer() {
infraContainer, err := p.getInfraContainer()
if err != nil {
return nil, servicePorts, err
}
-
+ for _, host := range infraContainer.config.ContainerNetworkConfig.HostAdd {
+ hostSli := strings.SplitN(host, ":", 2)
+ if len(hostSli) != 2 {
+ return nil, servicePorts, errors.New("invalid hostAdd")
+ }
+ extraHost = append(extraHost, v1.HostAlias{
+ IP: hostSli[1],
+ Hostnames: []string{hostSli[0]},
+ })
+ }
ports, err = ocicniPortMappingToContainerPort(infraContainer.config.PortMappings)
if err != nil {
return nil, servicePorts, err
@@ -61,7 +71,11 @@ func (p *Pod) GenerateForKube() (*v1.Pod, []v1.ServicePort, error) {
servicePorts = containerPortsToServicePorts(ports)
}
pod, err := p.podWithContainers(allContainers, ports)
- return pod, servicePorts, err
+ if err != nil {
+ return nil, servicePorts, err
+ }
+ pod.Spec.HostAliases = extraHost
+ return pod, servicePorts, nil
}
func (p *Pod) getInfraContainer() (*Container, error) {