summaryrefslogtreecommitdiff
path: root/libpod/kube.go
diff options
context:
space:
mode:
authorPeter Hunt <pehunt@redhat.com>2019-07-02 09:21:39 -0400
committerPeter Hunt <pehunt@redhat.com>2019-07-02 14:08:09 -0400
commitdb2cc360334ec04e4c2c0a71335fd51540a1273f (patch)
treee23741bb424aa9fc5471805091c900f6eb00168c /libpod/kube.go
parentaa9de67452af4cf0fdac57ec7657f0184cb0b6fd (diff)
downloadpodman-db2cc360334ec04e4c2c0a71335fd51540a1273f.tar.gz
podman-db2cc360334ec04e4c2c0a71335fd51540a1273f.tar.bz2
podman-db2cc360334ec04e4c2c0a71335fd51540a1273f.zip
Deduplicate volumes
for containers that share volumes, so the pod section doesn't list copies Signed-off-by: Peter Hunt <pehunt@redhat.com>
Diffstat (limited to 'libpod/kube.go')
-rw-r--r--libpod/kube.go21
1 files changed, 15 insertions, 6 deletions
diff --git a/libpod/kube.go b/libpod/kube.go
index 01c70ced8..6a52ff80b 100644
--- a/libpod/kube.go
+++ b/libpod/kube.go
@@ -132,31 +132,40 @@ func containersToServicePorts(containers []v1.Container) []v1.ServicePort {
func (p *Pod) podWithContainers(containers []*Container, ports []v1.ContainerPort) (*v1.Pod, error) {
var (
podContainers []v1.Container
- podVolumes []v1.Volume
)
+ deDupPodVolumes := make(map[string]*v1.Volume)
first := true
for _, ctr := range containers {
if !ctr.IsInfra() {
- result, volumes, err := containerToV1Container(ctr)
+ ctr, volumes, err := containerToV1Container(ctr)
if err != nil {
return nil, err
}
// Since port bindings for the pod are handled by the
// infra container, wipe them here.
- result.Ports = nil
+ ctr.Ports = nil
// We add the original port declarations from the libpod infra container
// to the first kubernetes container description because otherwise we loose
// the original container/port bindings.
if first && len(ports) > 0 {
- result.Ports = ports
+ ctr.Ports = ports
first = false
}
- podContainers = append(podContainers, result)
- podVolumes = append(podVolumes, volumes...)
+ podContainers = append(podContainers, ctr)
+ // Deduplicate volumes, so if containers in the pod share a volume, it's only
+ // listed in the volumes section once
+ for _, vol := range volumes {
+ deDupPodVolumes[vol.Name] = &vol
+ }
}
}
+ podVolumes := make([]v1.Volume, 0, len(deDupPodVolumes))
+ for _, vol := range deDupPodVolumes {
+ podVolumes = append(podVolumes, *vol)
+ }
+
return addContainersAndVolumesToPodObject(podContainers, podVolumes, p.Name()), nil
}