Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cmd/podman/kube/play.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ func playFlags(cmd *cobra.Command) {
exitFlagName := "service-exit-code-propagation"
flags.StringVar(&playOptions.ExitCodePropagation, exitFlagName, "", "Exit-code propagation of the service container")
_ = flags.MarkHidden(exitFlagName)

multiplePods := "multiple-pods"
flags.BoolVar(&playOptions.MultiplePods, multiplePods, false, "Allows creating of multiple Pods")
}
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/domain/entities/play.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ type PlayKubeOptions struct {
Wait bool
// SystemContext - used when building the image
SystemContext *types.SystemContext
// MultiplePods - allows creating of multiple Pods
MultiplePods bool
}

// PlayKubePod represents a single pod and associated containers created by play kube
Expand Down
56 changes: 40 additions & 16 deletions pkg/domain/infra/abi/play.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ func (ic *ContainerEngine) PlayKube(ctx context.Context, body io.Reader, options
ipIndex := 0

var configMaps []v1.ConfigMap
var numReplicas int32

ranContainers := false
// set the ranContainers bool to true if at least one container was successfully started.
Expand Down Expand Up @@ -404,15 +405,46 @@ func (ic *ContainerEngine) PlayKube(ctx context.Context, body io.Reader, options
return nil, fmt.Errorf("unable to read YAML as Kube Deployment: %w", err)
}

r, proxies, err := ic.playKubeDeployment(ctx, &deploymentYAML, options, &ipIndex, configMaps, serviceContainer)
if err != nil {
return nil, err
numReplicas = 1
if deploymentYAML.Spec.Replicas != nil {
numReplicas = *deploymentYAML.Spec.Replicas
}
notifyProxies = append(notifyProxies, proxies...)

report.Pods = append(report.Pods, r.Pods...)
if numReplicas > 1 && options.MultiplePods {
if len(options.PublishPorts) > 0 && len(options.PublishPorts) != int(numReplicas) {
return nil, fmt.Errorf("number of Pod replics aren't equal to number of published ports: %d replicas, %d published ports", numReplicas, len(options.PublishPorts))
}

var portToPublish = make([]string, numReplicas)
copy(portToPublish, options.PublishPorts)
options.PublishPorts = make([]string, 1)
for i := numReplicas; i != 0; i-- {
options.PublishPorts[0] = (portToPublish[(len(portToPublish) - int(i))])
podName := fmt.Sprintf("%s-pod-%d", deploymentYAML.ObjectMeta.Name, i)
r, proxies, err := ic.playKubeDeployment(ctx, &deploymentYAML, options, &ipIndex, configMaps, serviceContainer, podName)
if err != nil {
return nil, err
}
notifyProxies = append(notifyProxies, proxies...)

report.Pods = append(report.Pods, r.Pods...)
setRanContainers(r)
}
} else {
if numReplicas > 1 {
logrus.Warnf("Limiting replica count to 1, more than one replica is not supported by Podman")
}
podName := fmt.Sprintf("%s-pod", deploymentYAML.ObjectMeta.Name)
r, proxies, err := ic.playKubeDeployment(ctx, &deploymentYAML, options, &ipIndex, configMaps, serviceContainer, podName)
if err != nil {
return nil, err
}
notifyProxies = append(notifyProxies, proxies...)

report.Pods = append(report.Pods, r.Pods...)
setRanContainers(r)
}
validKinds++
setRanContainers(r)
case "Job":
var jobYAML v1.Job

Expand Down Expand Up @@ -563,28 +595,20 @@ func (ic *ContainerEngine) playKubeDaemonSet(ctx context.Context, daemonSetYAML
return &report, proxies, nil
}

func (ic *ContainerEngine) playKubeDeployment(ctx context.Context, deploymentYAML *v1apps.Deployment, options entities.PlayKubeOptions, ipIndex *int, configMaps []v1.ConfigMap, serviceContainer *libpod.Container) (*entities.PlayKubeReport, []*notifyproxy.NotifyProxy, error) {
func (ic *ContainerEngine) playKubeDeployment(ctx context.Context, deploymentYAML *v1apps.Deployment, options entities.PlayKubeOptions, ipIndex *int, configMaps []v1.ConfigMap, serviceContainer *libpod.Container, podName string) (*entities.PlayKubeReport, []*notifyproxy.NotifyProxy, error) {
var (
deploymentName string
podSpec v1.PodTemplateSpec
numReplicas int32
report entities.PlayKubeReport
)

deploymentName = deploymentYAML.ObjectMeta.Name
if deploymentName == "" {
return nil, nil, errors.New("deployment does not have a name")
}
numReplicas = 1
if deploymentYAML.Spec.Replicas != nil {
numReplicas = *deploymentYAML.Spec.Replicas
}
if numReplicas > 1 {
logrus.Warnf("Limiting replica count to 1, more than one replica is not supported by Podman")
}

podSpec = deploymentYAML.Spec.Template

podName := fmt.Sprintf("%s-pod", deploymentName)
podReport, proxies, err := ic.playKubePod(ctx, podName, &podSpec, options, ipIndex, deploymentYAML.Annotations, configMaps, serviceContainer)
if err != nil {
return nil, nil, fmt.Errorf("encountered while bringing up pod %s: %w", podName, err)
Expand Down