Allow controller flag to override restart policy (#1340)

This commit is contained in:
Hang Yan
2020-11-02 18:17:12 +08:00
committed by GitHub
parent c1280a4f55
commit 2dc6037cce
4 changed files with 9 additions and 8 deletions
+5
View File
@@ -78,6 +78,11 @@ type ConvertOptions struct {
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
type ServiceConfig struct {
ContainerName string
+2 -5
View File
@@ -1154,11 +1154,8 @@ func (k *Kubernetes) Transform(komposeObject kobject.KomposeObject, opt kobject.
}
// Generate pod only and nothing more
if service.Restart == "no" || service.Restart == "on-failure" {
// Error out if Controller Object is specified with restart: 'on-failure'
if opt.IsDeploymentFlag || opt.IsDaemonSetFlag || opt.IsReplicationControllerFlag {
return nil, errors.New("Controller object cannot be specified with restart: 'on-failure'")
}
if (service.Restart == "no" || service.Restart == "on-failure") && !opt.IsPodController() {
log.Infof("Create kubernetes pod instead of pod controller due to restart policy: %s", service.Restart)
pod := k.InitPod(name, service)
objects = append(objects, pod)
} else {
@@ -518,8 +518,8 @@ func TestRestartOnFailure(t *testing.T) {
t.Log("Test case:", name)
k := Kubernetes{}
_, err := k.Transform(test.komposeObject, test.opt)
if err == nil {
t.Errorf("Expected an error, got %v instead", err)
if err != nil {
t.Errorf("Expected nil error, got %v instead", err)
}
}
}