Add deploy: mode: global support
Adds support for deploy: mode.
For example:
```yaml
version: "3"
services:
foo:
deploy:
resources:
mode: global
replicas: 6
image: redis
```
Will only generate replicas: 1 in Kubernetes pods as "global" limits
replicas to only one.
This commit is contained in:
@@ -61,14 +61,13 @@ type ConvertOptions struct {
|
||||
// ServiceConfig holds the basic struct of a container
|
||||
type ServiceConfig struct {
|
||||
// use tags to mark from what element this value comes
|
||||
ContainerName string
|
||||
Image string `compose:"image"`
|
||||
Environment []EnvVar `compose:"environment"`
|
||||
Port []Ports `compose:"ports"`
|
||||
Command []string `compose:"command"`
|
||||
WorkingDir string `compose:""`
|
||||
Args []string `compose:"args"`
|
||||
// VolList is list of volumes extracted from docker-compose file
|
||||
ContainerName string
|
||||
Image string `compose:"image"`
|
||||
Environment []EnvVar `compose:"environment"`
|
||||
Port []Ports `compose:"ports"`
|
||||
Command []string `compose:"command"`
|
||||
WorkingDir string `compose:""`
|
||||
Args []string `compose:"args"`
|
||||
VolList []string `compose:"volumes"`
|
||||
Network []string `compose:"network"`
|
||||
Labels map[string]string `compose:"labels"`
|
||||
@@ -95,6 +94,7 @@ type ServiceConfig struct {
|
||||
Tty bool `compose:"tty"`
|
||||
MemLimit yaml.MemStringorInt `compose:"mem_limit"`
|
||||
MemReservation yaml.MemStringorInt `compose:""`
|
||||
DeployMode string `compose:""`
|
||||
TmpFs []string `compose:"tmpfs"`
|
||||
Dockerfile string `compose:"dockerfile"`
|
||||
Replicas int `compose:"replicas"`
|
||||
|
||||
@@ -198,6 +198,8 @@ func dockerComposeToKomposeMapping(composeObject *types.Config) (kobject.Kompose
|
||||
// Deploy keys
|
||||
//
|
||||
|
||||
serviceConfig.DeployMode = composeServiceConfig.Deploy.Mode
|
||||
|
||||
if (composeServiceConfig.Deploy.Resources != types.Resources{}) {
|
||||
|
||||
// memory:
|
||||
|
||||
@@ -490,12 +490,19 @@ func (k *Kubernetes) ConfigEnvs(name string, service kobject.ServiceConfig) []ap
|
||||
func (k *Kubernetes) CreateKubernetesObjects(name string, service kobject.ServiceConfig, opt kobject.ConvertOptions) []runtime.Object {
|
||||
var objects []runtime.Object
|
||||
var replica int
|
||||
|
||||
if opt.IsReplicaSetFlag || service.Replicas == 0 {
|
||||
replica = opt.Replicas
|
||||
} else {
|
||||
replica = service.Replicas
|
||||
}
|
||||
|
||||
// Check to see if Docker Compose v3 Deploy.Mode has been set to "global"
|
||||
if service.DeployMode == "global" {
|
||||
log.Warning("Global mode not yet supported, containers will only be replicated once throughout the cluster. DaemonSet support will be added in the future.")
|
||||
replica = 1
|
||||
}
|
||||
|
||||
if opt.CreateD {
|
||||
objects = append(objects, k.InitD(name, service, replica))
|
||||
}
|
||||
|
||||
@@ -272,6 +272,7 @@ func (o *OpenShift) Transform(komposeObject kobject.KomposeObject, opt kobject.C
|
||||
for _, name := range sortedKeys {
|
||||
service := komposeObject.ServiceConfigs[name]
|
||||
var objects []runtime.Object
|
||||
|
||||
//replicas
|
||||
var replica int
|
||||
if opt.IsReplicaSetFlag || service.Replicas == 0 {
|
||||
@@ -279,6 +280,12 @@ func (o *OpenShift) Transform(komposeObject kobject.KomposeObject, opt kobject.C
|
||||
} else {
|
||||
replica = service.Replicas
|
||||
}
|
||||
|
||||
// If Deploy.Mode = Global has been set, make replica = 1 when generating DeploymentConfig
|
||||
if service.DeployMode == "global" {
|
||||
replica = 1
|
||||
}
|
||||
|
||||
// Must build the images before conversion (got to add service.Image in case 'image' key isn't provided
|
||||
// Check to see if there is an InputFile (required!) before we build the container
|
||||
// Check that there's actually a Build key
|
||||
|
||||
Reference in New Issue
Block a user