diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-08-28 16:06:11 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-28 16:06:11 -0400 |
commit | 4e3ea01243665259dededa7e3fa924cb5bd2ee3c (patch) | |
tree | 5b1b6a575f63465a001f15d2fa7e753ae9ac422b /libpod/kube.go | |
parent | 97780a110b58a3bcc983bff75f3665768271631c (diff) | |
parent | a2bb7bd36b22f45dbccabbab9dcca83abfda1682 (diff) | |
download | podman-4e3ea01243665259dededa7e3fa924cb5bd2ee3c.tar.gz podman-4e3ea01243665259dededa7e3fa924cb5bd2ee3c.tar.bz2 podman-4e3ea01243665259dededa7e3fa924cb5bd2ee3c.zip |
Merge pull request #7469 from zhangguanzhang/generate-kube-with-ExtraHosts
fix podman generate kube with HostAliases
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) { |