forked from LaconicNetwork/kompose
Allow controller flag to override restart policy (#1340)
This commit is contained in:
@@ -21,7 +21,6 @@ require (
|
|||||||
github.com/docker/cli v0.0.0-20190711175710-5b38d82aa076
|
github.com/docker/cli v0.0.0-20190711175710-5b38d82aa076
|
||||||
github.com/docker/libcompose v0.4.0
|
github.com/docker/libcompose v0.4.0
|
||||||
github.com/fatih/structs v1.1.0
|
github.com/fatih/structs v1.1.0
|
||||||
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 // indirect
|
|
||||||
github.com/fsouza/go-dockerclient v1.6.5
|
github.com/fsouza/go-dockerclient v1.6.5
|
||||||
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
|
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
|
||||||
github.com/gotestyourself/gotestyourself v2.2.0+incompatible // indirect
|
github.com/gotestyourself/gotestyourself v2.2.0+incompatible // indirect
|
||||||
|
|||||||
@@ -78,6 +78,11 @@ type ConvertOptions struct {
|
|||||||
WithKomposeAnnotation bool
|
WithKomposeAnnotation bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsPodController indicate if the user want to use a controller
|
||||||
|
func (opt *ConvertOptions) IsPodController() bool {
|
||||||
|
return opt.IsDeploymentFlag || opt.IsDaemonSetFlag || opt.IsReplicationControllerFlag || opt.Controller != ""
|
||||||
|
}
|
||||||
|
|
||||||
// ServiceConfig holds the basic struct of a container
|
// ServiceConfig holds the basic struct of a container
|
||||||
type ServiceConfig struct {
|
type ServiceConfig struct {
|
||||||
ContainerName string
|
ContainerName string
|
||||||
|
|||||||
@@ -1154,11 +1154,8 @@ func (k *Kubernetes) Transform(komposeObject kobject.KomposeObject, opt kobject.
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Generate pod only and nothing more
|
// Generate pod only and nothing more
|
||||||
if service.Restart == "no" || service.Restart == "on-failure" {
|
if (service.Restart == "no" || service.Restart == "on-failure") && !opt.IsPodController() {
|
||||||
// Error out if Controller Object is specified with restart: 'on-failure'
|
log.Infof("Create kubernetes pod instead of pod controller due to restart policy: %s", service.Restart)
|
||||||
if opt.IsDeploymentFlag || opt.IsDaemonSetFlag || opt.IsReplicationControllerFlag {
|
|
||||||
return nil, errors.New("Controller object cannot be specified with restart: 'on-failure'")
|
|
||||||
}
|
|
||||||
pod := k.InitPod(name, service)
|
pod := k.InitPod(name, service)
|
||||||
objects = append(objects, pod)
|
objects = append(objects, pod)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -518,8 +518,8 @@ func TestRestartOnFailure(t *testing.T) {
|
|||||||
t.Log("Test case:", name)
|
t.Log("Test case:", name)
|
||||||
k := Kubernetes{}
|
k := Kubernetes{}
|
||||||
_, err := k.Transform(test.komposeObject, test.opt)
|
_, err := k.Transform(test.komposeObject, test.opt)
|
||||||
if err == nil {
|
if err != nil {
|
||||||
t.Errorf("Expected an error, got %v instead", err)
|
t.Errorf("Expected nil error, got %v instead", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user