forked from LaconicNetwork/kompose
Merge pull request #373 from procrypt/error_should_be_displayed
error out if controller object is specified with "restart: on-failure"
This commit is contained in:
commit
2f05ecdcf0
@ -55,21 +55,25 @@ var convertCmd = &cobra.Command{
|
||||
|
||||
// Create the Convert Options.
|
||||
ConvertOpt = kobject.ConvertOptions{
|
||||
ToStdout: ConvertStdout,
|
||||
CreateChart: ConvertChart,
|
||||
GenerateYaml: ConvertYaml,
|
||||
GenerateJSON: ConvertJSON,
|
||||
Replicas: ConvertReplicas,
|
||||
InputFiles: GlobalFiles,
|
||||
OutFile: ConvertOut,
|
||||
Provider: strings.ToLower(GlobalProvider),
|
||||
CreateD: ConvertDeployment,
|
||||
CreateDS: ConvertDaemonSet,
|
||||
CreateRC: ConvertReplicationController,
|
||||
BuildRepo: ConvertBuildRepo,
|
||||
BuildBranch: ConvertBuildBranch,
|
||||
CreateDeploymentConfig: ConvertDeploymentConfig,
|
||||
EmptyVols: ConvertEmptyVols,
|
||||
ToStdout: ConvertStdout,
|
||||
CreateChart: ConvertChart,
|
||||
GenerateYaml: ConvertYaml,
|
||||
GenerateJSON: ConvertJSON,
|
||||
Replicas: ConvertReplicas,
|
||||
InputFiles: GlobalFiles,
|
||||
OutFile: ConvertOut,
|
||||
Provider: strings.ToLower(GlobalProvider),
|
||||
CreateD: ConvertDeployment,
|
||||
CreateDS: ConvertDaemonSet,
|
||||
CreateRC: ConvertReplicationController,
|
||||
BuildRepo: ConvertBuildRepo,
|
||||
BuildBranch: ConvertBuildBranch,
|
||||
CreateDeploymentConfig: ConvertDeploymentConfig,
|
||||
EmptyVols: ConvertEmptyVols,
|
||||
IsDeploymentFlag: cmd.Flags().Lookup("deployment").Changed,
|
||||
IsDaemonSetFlag: cmd.Flags().Lookup("daemon-set").Changed,
|
||||
IsReplicationControllerFlag: cmd.Flags().Lookup("replication-controller").Changed,
|
||||
IsDeploymentConfigFlag: cmd.Flags().Lookup("deployment-config").Changed,
|
||||
}
|
||||
|
||||
// Validate before doing anything else. Use "bundle" if passed in.
|
||||
|
||||
@ -29,21 +29,25 @@ type KomposeObject struct {
|
||||
|
||||
// ConvertOptions holds all options that controls transformation process
|
||||
type ConvertOptions struct {
|
||||
ToStdout bool
|
||||
CreateD bool
|
||||
CreateRC bool
|
||||
CreateDS bool
|
||||
CreateDeploymentConfig bool
|
||||
BuildRepo string
|
||||
BuildBranch string
|
||||
CreateChart bool
|
||||
GenerateYaml bool
|
||||
GenerateJSON bool
|
||||
EmptyVols bool
|
||||
Replicas int
|
||||
InputFiles []string
|
||||
OutFile string
|
||||
Provider string
|
||||
ToStdout bool
|
||||
CreateD bool
|
||||
CreateRC bool
|
||||
CreateDS bool
|
||||
CreateDeploymentConfig bool
|
||||
BuildRepo string
|
||||
BuildBranch string
|
||||
CreateChart bool
|
||||
GenerateYaml bool
|
||||
GenerateJSON bool
|
||||
EmptyVols bool
|
||||
Replicas int
|
||||
InputFiles []string
|
||||
OutFile string
|
||||
Provider string
|
||||
IsDeploymentFlag bool
|
||||
IsDaemonSetFlag bool
|
||||
IsReplicationControllerFlag bool
|
||||
IsDeploymentConfigFlag bool
|
||||
}
|
||||
|
||||
// ServiceConfig holds the basic struct of a container
|
||||
|
||||
@ -468,6 +468,10 @@ 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 {
|
||||
logrus.Fatalf("Controller object cannot be specified with restart: 'on-failure'")
|
||||
}
|
||||
pod := k.InitPod(name, service)
|
||||
objects = append(objects, pod)
|
||||
} else {
|
||||
|
||||
@ -321,6 +321,10 @@ func (o *OpenShift) Transform(komposeObject kobject.KomposeObject, opt kobject.C
|
||||
|
||||
// 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.IsDeploymentConfigFlag {
|
||||
logrus.Fatalf("Controller object cannot be specified with restart: 'on-failure'")
|
||||
}
|
||||
pod := o.InitPod(name, service)
|
||||
objects = append(objects, pod)
|
||||
} else {
|
||||
|
||||
@ -110,10 +110,10 @@ convert::expect_success_and_warning "kompose --bundle $KOMPOSE_ROOT/script/test/
|
||||
# Test related to restart options in docker-compose
|
||||
# kubernetes test
|
||||
convert::expect_success "kompose -f $KOMPOSE_ROOT/script/test/fixtures/restart-options/docker-compose-restart-no.yml convert --stdout -j" "$KOMPOSE_ROOT/script/test/fixtures/restart-options/output-k8s-restart-no.json"
|
||||
convert::expect_success "kompose -f $KOMPOSE_ROOT/script/test/fixtures/restart-options/docker-compose-restart-onfail.yml convert --stdout -j" "$KOMPOSE_ROOT/script/test/fixtures/restart-options/output-k8s-restart-onfail.json"
|
||||
convert::failure "kompose -f $KOMPOSE_ROOT/script/test/fixtures/restart-options/docker-compose-restart-onfail.yml convert --stdout -j" "Controller object cannot be specified with restart: 'on-failure'"
|
||||
# openshift test
|
||||
convert::expect_success "kompose -f $KOMPOSE_ROOT/script/test/fixtures/restart-options/docker-compose-restart-no.yml --provider openshift convert --stdout -j" "$KOMPOSE_ROOT/script/test/fixtures/restart-options/output-os-restart-no.json"
|
||||
convert::expect_success "kompose -f $KOMPOSE_ROOT/script/test/fixtures/restart-options/docker-compose-restart-onfail.yml --provider openshift convert --stdout -j" "$KOMPOSE_ROOT/script/test/fixtures/restart-options/output-os-restart-onfail.json"
|
||||
convert::failure "kompose -f $KOMPOSE_ROOT/script/test/fixtures/restart-options/docker-compose-restart-onfail.yml --provider openshift convert --stdout -j" "Controller object cannot be specified with restart: 'on-failure'"
|
||||
|
||||
|
||||
######
|
||||
|
||||
@ -1,35 +0,0 @@
|
||||
{
|
||||
"kind": "List",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {},
|
||||
"items": [
|
||||
{
|
||||
"kind": "Pod",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "foo",
|
||||
"creationTimestamp": null,
|
||||
"labels": {
|
||||
"service": "foo"
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
"containers": [
|
||||
{
|
||||
"name": "foo",
|
||||
"image": "foobar",
|
||||
"env": [
|
||||
{
|
||||
"name": "GITHUB",
|
||||
"value": "surajssd"
|
||||
}
|
||||
],
|
||||
"resources": {}
|
||||
}
|
||||
],
|
||||
"restartPolicy": "OnFailure"
|
||||
},
|
||||
"status": {}
|
||||
}
|
||||
]
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user