diff options
author | theunrealgeek <theunrealgeek@gmail.com> | 2020-05-23 20:47:30 -0700 |
---|---|---|
committer | theunrealgeek <theunrealgeek@gmail.com> | 2020-06-02 20:33:16 -0700 |
commit | 478f296fb345ce9edc707aa4bcd588f8ffd55bb8 (patch) | |
tree | 5d05a272844010dca9b3f3acff6fc82528f1c349 /pkg/domain | |
parent | ce7a9f03146da33007656ded64be3148d6ec8d77 (diff) | |
download | podman-478f296fb345ce9edc707aa4bcd588f8ffd55bb8.tar.gz podman-478f296fb345ce9edc707aa4bcd588f8ffd55bb8.tar.bz2 podman-478f296fb345ce9edc707aa4bcd588f8ffd55bb8.zip |
Modify PlayKubeReport to preserve pod->container mapping
Signed-off-by: Aditya Kamath <theunrealgeek@gmail.com>
Diffstat (limited to 'pkg/domain')
-rw-r--r-- | pkg/domain/entities/play.go | 13 | ||||
-rw-r--r-- | pkg/domain/infra/abi/play.go | 18 |
2 files changed, 20 insertions, 11 deletions
diff --git a/pkg/domain/entities/play.go b/pkg/domain/entities/play.go index fff86daf9..58602d3f9 100644 --- a/pkg/domain/entities/play.go +++ b/pkg/domain/entities/play.go @@ -26,12 +26,17 @@ type PlayKubeOptions struct { SeccompProfileRoot string } -// PlayKubeReport contains the results of running play kube. -type PlayKubeReport struct { - // Pods - the IDs of the created pods. - Pods []string +// PlayKubePods represents a single pod and associated containers created by play kube +type PlayKubePod struct { + ID string // Containers - the IDs of the containers running in the created pod. Containers []string // Logs - non-fatal erros and log messages while processing. Logs []string } + +// PlayKubeReport contains the results of running play kube. +type PlayKubeReport struct { + // Pods - pods created by play kube. + Pods []PlayKubePod +} diff --git a/pkg/domain/infra/abi/play.go b/pkg/domain/infra/abi/play.go index 772cea5fd..ce18930b7 100644 --- a/pkg/domain/infra/abi/play.go +++ b/pkg/domain/infra/abi/play.go @@ -103,8 +103,6 @@ func (ic *ContainerEngine) playKubeDeployment(ctx context.Context, deploymentYAM return nil, errors.Wrapf(err, "Error encountered while bringing up pod %s", podName) } report.Pods = append(report.Pods, podReport.Pods...) - report.Containers = append(report.Containers, podReport.Containers...) - report.Logs = append(report.Logs, podReport.Logs...) } return &report, nil } @@ -116,6 +114,7 @@ func (ic *ContainerEngine) playKubePod(ctx context.Context, podName string, podY podOptions []libpod.PodCreateOption registryCreds *types.DockerAuthConfig writer io.Writer + playKubePod entities.PlayKubePod report entities.PlayKubeReport ) @@ -125,7 +124,7 @@ func (ic *ContainerEngine) playKubePod(ctx context.Context, podName string, podY } for _, n := range podYAML.Spec.Containers { if n.Name == podName { - report.Logs = append(report.Logs, + playKubePod.Logs = append(playKubePod.Logs, fmt.Sprintf("a container exists with the same name (%q) as the pod in your YAML file; changing pod name to %s_pod\n", podName, podName)) podName = fmt.Sprintf("%s_pod", podName) } @@ -314,11 +313,13 @@ func (ic *ContainerEngine) playKubePod(ctx context.Context, podName string, podY } } - report.Pods = append(report.Pods, pod.ID()) + playKubePod.ID = pod.ID() for _, ctr := range containers { - report.Containers = append(report.Containers, ctr.ID()) + playKubePod.Containers = append(playKubePod.Containers, ctr.ID()) } + report.Pods = append(report.Pods, playKubePod) + return &report, nil } @@ -425,9 +426,12 @@ func kubeContainerToCreateConfig(ctx context.Context, containerYAML v1.Container containerConfig.ImageID = newImage.ID() containerConfig.Name = containerYAML.Name - if podName != "" { - containerConfig.Name = fmt.Sprintf("%s-%s", podName, containerYAML.Name) + // podName should be non-empty for Deployment objects to be able to create + // multiple pods having containers with unique names + if podName == "" { + return nil, errors.Errorf("kubeContainerToCreateConfig got empty podName") } + containerConfig.Name = fmt.Sprintf("%s-%s", podName, containerYAML.Name) containerConfig.Tty = containerYAML.TTY |