diff --git a/libpod/kube.go b/libpod/kube.go index b376f9ef8f..8c1c8770a1 100644 --- a/libpod/kube.go +++ b/libpod/kube.go @@ -512,7 +512,28 @@ func (p *Pod) podWithContainers(ctx context.Context, containers []*Container, po sort.Slice(containers, func(i, j int) bool { return containers[i].CreatedTime().Before(containers[j].CreatedTime()) }) for _, ctr := range containers { - if !ctr.IsInfra() { + if ctr.IsInfra() { + _, _, infraDNS, _, err := containerToV1Container(ctx, ctr, getService) + if err != nil { + return nil, err + } + if infraDNS != nil { + if servers := infraDNS.Nameservers; len(servers) > 0 { + dnsInfo.Nameservers = servers + } + if searches := infraDNS.Searches; len(searches) > 0 { + dnsInfo.Searches = searches + } + if options := infraDNS.Options; len(options) > 0 { + dnsInfo.Options = options + } + } + // If the infraName is not the podID-infra, that means the user set another infra name using + // --infra-name during pod creation + if infraName != "" && infraName != p.ID()[:12]+"-infra" { + podAnnotations[define.InfraNameAnnotation] = infraName + } + } else { for k, v := range ctr.config.Spec.Annotations { if !podmanOnly && (define.IsReservedAnnotation(k)) { continue @@ -574,27 +595,6 @@ func (p *Pod) podWithContainers(ctx context.Context, containers []*Container, po vol := vol deDupPodVolumes[vol.Name] = &vol } - } else { - _, _, infraDNS, _, err := containerToV1Container(ctx, ctr, getService) - if err != nil { - return nil, err - } - if infraDNS != nil { - if servers := infraDNS.Nameservers; len(servers) > 0 { - dnsInfo.Nameservers = servers - } - if searches := infraDNS.Searches; len(searches) > 0 { - dnsInfo.Searches = searches - } - if options := infraDNS.Options; len(options) > 0 { - dnsInfo.Options = options - } - } - // If the infraName is not the podID-infra, that means the user set another infra name using - // --infra-name during pod creation - if infraName != "" && infraName != p.ID()[:12]+"-infra" { - podAnnotations[define.InfraNameAnnotation] = infraName - } } } podVolumes := []v1.Volume{}