diff options
author | zhangguanzhang <zhangguanzhang@qq.com> | 2020-08-27 15:45:04 +0800 |
---|---|---|
committer | zhangguanzhang <zhangguanzhang@qq.com> | 2020-08-27 17:32:51 +0800 |
commit | a2bb7bd36b22f45dbccabbab9dcca83abfda1682 (patch) | |
tree | 76919e0667f2c65ceeb6da30398b293f580d2d41 /libpod/kube.go | |
parent | f99954c7ca4428e501676fa47a63b5cecadd9454 (diff) | |
download | podman-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/kube.go')
-rw-r--r-- | libpod/kube.go | 18 |
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) { |