forked from LaconicNetwork/kompose
Merge pull request #378 from containscafeine/deployment_strategy
change strategy to recreate if volumes present, fix #264
This commit is contained in:
commit
786f5c4f99
@ -394,3 +394,6 @@ services:
|
||||
command: ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"]
|
||||
restart: "on-failure"
|
||||
```
|
||||
|
||||
#### Notes:
|
||||
- If the Docker Compose file has a volume specified for a service, the Deployment (Kubernetes) or DeploymentConfig (OpenShift) strategy is changed to "Recreate" instead of "RollingUpdate" (default). This is done to avoid multiple instances of a service from accessing a volume at the same time.
|
||||
@ -384,6 +384,15 @@ func (k *Kubernetes) UpdateKubernetesObjects(name string, service kobject.Servic
|
||||
// update supported controller
|
||||
for _, obj := range *objects {
|
||||
k.UpdateController(obj, fillTemplate, fillObjectMeta)
|
||||
|
||||
if len(service.Volumes) > 0 {
|
||||
switch objType := obj.(type) {
|
||||
case *extensions.Deployment:
|
||||
objType.Spec.Strategy.Type = extensions.RecreateDeploymentStrategyType
|
||||
case *deployapi.DeploymentConfig:
|
||||
objType.Spec.Strategy.Type = deployapi.DeploymentStrategyTypeRecreate
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -182,3 +182,29 @@ func TestServiceWithoutPort(t *testing.T) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Tests if deployment strategy is being set to Recreate when volumes are
|
||||
// present
|
||||
func TestRecreateStrategyWithVolumesPresent(t *testing.T) {
|
||||
service := kobject.ServiceConfig{
|
||||
ContainerName: "name",
|
||||
Image: "image",
|
||||
Volumes: []string{"/tmp/volume"},
|
||||
}
|
||||
|
||||
komposeObject := kobject.KomposeObject{
|
||||
ServiceConfigs: map[string]kobject.ServiceConfig{"app": service},
|
||||
}
|
||||
k := Kubernetes{}
|
||||
|
||||
objects := k.Transform(komposeObject, kobject.ConvertOptions{CreateD: true, Replicas: 1})
|
||||
for _, obj := range objects {
|
||||
if deployment, ok := obj.(*extensions.Deployment); ok {
|
||||
if deployment.Spec.Strategy.Type != extensions.RecreateDeploymentStrategyType {
|
||||
t.Errorf("Expected %v as Strategy Type, got %v",
|
||||
extensions.RecreateDeploymentStrategyType,
|
||||
deployment.Spec.Strategy.Type)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -380,3 +380,29 @@ func TestRestartOnFailure(t *testing.T) {
|
||||
}
|
||||
t.Fatalf("Process ran with err %v, want exit status 1", err)
|
||||
}
|
||||
|
||||
// Tests if deployment strategy is being set to Recreate when volumes are
|
||||
// present
|
||||
func TestRecreateStrategyWithVolumesPresent(t *testing.T) {
|
||||
service := kobject.ServiceConfig{
|
||||
ContainerName: "name",
|
||||
Image: "image",
|
||||
Volumes: []string{"/tmp/volume"},
|
||||
}
|
||||
komposeObject := kobject.KomposeObject{
|
||||
ServiceConfigs: map[string]kobject.ServiceConfig{"app": service},
|
||||
}
|
||||
|
||||
o := OpenShift{Kubernetes: kubernetes.Kubernetes{}}
|
||||
|
||||
objects := o.Transform(komposeObject, kobject.ConvertOptions{CreateDeploymentConfig: true, Replicas: 1})
|
||||
for _, obj := range objects {
|
||||
if deploymentConfig, ok := obj.(*deployapi.DeploymentConfig); ok {
|
||||
if deploymentConfig.Spec.Strategy.Type != deployapi.DeploymentStrategyTypeRecreate {
|
||||
t.Errorf("Expected %v as Strategy Type, got %v",
|
||||
deployapi.DeploymentStrategyTypeRecreate,
|
||||
deploymentConfig.Spec.Strategy.Type)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
1652
script/test/fixtures/envvars-separators/output-k8s.json
vendored
1652
script/test/fixtures/envvars-separators/output-k8s.json
vendored
File diff suppressed because it is too large
Load Diff
@ -177,7 +177,9 @@
|
||||
"restartPolicy": "Always"
|
||||
}
|
||||
},
|
||||
"strategy": {}
|
||||
"strategy": {
|
||||
"type": "Recreate"
|
||||
}
|
||||
},
|
||||
"status": {}
|
||||
},
|
||||
|
||||
3
script/test/fixtures/etherpad/output-os.json
vendored
3
script/test/fixtures/etherpad/output-os.json
vendored
@ -177,7 +177,8 @@
|
||||
},
|
||||
"spec": {
|
||||
"strategy": {
|
||||
"resources": {}
|
||||
"resources": {},
|
||||
"type": "Recreate"
|
||||
},
|
||||
"triggers": [
|
||||
{
|
||||
|
||||
@ -203,7 +203,9 @@
|
||||
"restartPolicy": "Always"
|
||||
}
|
||||
},
|
||||
"strategy": {}
|
||||
"strategy": {
|
||||
"type": "Recreate"
|
||||
}
|
||||
},
|
||||
"status": {}
|
||||
},
|
||||
|
||||
@ -190,6 +190,7 @@
|
||||
},
|
||||
"spec": {
|
||||
"strategy": {
|
||||
"type": "Recreate",
|
||||
"resources": {}
|
||||
},
|
||||
"triggers": [
|
||||
|
||||
@ -75,7 +75,9 @@
|
||||
"restartPolicy": "Always"
|
||||
}
|
||||
},
|
||||
"strategy": {}
|
||||
"strategy": {
|
||||
"type": "Recreate"
|
||||
}
|
||||
},
|
||||
"status": {}
|
||||
},
|
||||
|
||||
@ -41,7 +41,8 @@
|
||||
},
|
||||
"spec": {
|
||||
"strategy": {
|
||||
"resources": {}
|
||||
"resources": {},
|
||||
"type": "Recreate"
|
||||
},
|
||||
"triggers": [
|
||||
{
|
||||
|
||||
@ -106,7 +106,9 @@
|
||||
"restartPolicy": "Always"
|
||||
}
|
||||
},
|
||||
"strategy": {}
|
||||
"strategy": {
|
||||
"type": "Recreate"
|
||||
}
|
||||
},
|
||||
"status": {}
|
||||
},
|
||||
@ -185,7 +187,9 @@
|
||||
"restartPolicy": "Always"
|
||||
}
|
||||
},
|
||||
"strategy": {}
|
||||
"strategy": {
|
||||
"type": "Recreate"
|
||||
}
|
||||
},
|
||||
"status": {}
|
||||
},
|
||||
|
||||
@ -67,7 +67,8 @@
|
||||
},
|
||||
"spec": {
|
||||
"strategy": {
|
||||
"resources": {}
|
||||
"resources": {},
|
||||
"type": "Recreate"
|
||||
},
|
||||
"triggers": [
|
||||
{
|
||||
@ -198,7 +199,8 @@
|
||||
},
|
||||
"spec": {
|
||||
"strategy": {
|
||||
"resources": {}
|
||||
"resources": {},
|
||||
"type": "Recreate"
|
||||
},
|
||||
"triggers": [
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user