Add --volumes parameter, deprecate emptyvols

This adds the --volumes paramater with a "generate" and "empty"

By default, "generate" will be used as a place-holder for "true".
Although not used in the code, we will eventually add "none"

This uses CLI paramater naming processes (no emptyVols as that is Go /
Kubernetes specific) and thus we use dashes.
This commit is contained in:
Charlie Drage 2017-09-05 11:39:57 -04:00
parent faa844a733
commit cc1671aaa9
7 changed files with 195 additions and 6 deletions

View File

@ -32,6 +32,7 @@ var (
ConvertBuildRepo string ConvertBuildRepo string
ConvertBuildBranch string ConvertBuildBranch string
ConvertBuild string ConvertBuild string
ConvertVolumes string
ConvertChart bool ConvertChart bool
ConvertDeployment bool ConvertDeployment bool
ConvertDaemonSet bool ConvertDaemonSet bool
@ -78,6 +79,7 @@ var convertCmd = &cobra.Command{
BuildBranch: ConvertBuildBranch, BuildBranch: ConvertBuildBranch,
CreateDeploymentConfig: ConvertDeploymentConfig, CreateDeploymentConfig: ConvertDeploymentConfig,
EmptyVols: ConvertEmptyVols, EmptyVols: ConvertEmptyVols,
Volumes: ConvertVolumes,
InsecureRepository: ConvertInsecureRepo, InsecureRepository: ConvertInsecureRepo,
IsDeploymentFlag: cmd.Flags().Lookup("deployment").Changed, IsDeploymentFlag: cmd.Flags().Lookup("deployment").Changed,
IsDaemonSetFlag: cmd.Flags().Lookup("daemon-set").Changed, IsDaemonSetFlag: cmd.Flags().Lookup("daemon-set").Changed,
@ -128,9 +130,13 @@ func init() {
convertCmd.Flags().MarkShorthandDeprecated("y", "YAML is the default format now.") convertCmd.Flags().MarkShorthandDeprecated("y", "YAML is the default format now.")
convertCmd.Flags().BoolVarP(&ConvertJSON, "json", "j", false, "Generate resource files into JSON format") convertCmd.Flags().BoolVarP(&ConvertJSON, "json", "j", false, "Generate resource files into JSON format")
convertCmd.Flags().BoolVar(&ConvertStdout, "stdout", false, "Print converted objects to stdout") convertCmd.Flags().BoolVar(&ConvertStdout, "stdout", false, "Print converted objects to stdout")
convertCmd.Flags().BoolVar(&ConvertEmptyVols, "emptyvols", false, "Use Empty Volumes. Do not generate PVCs")
convertCmd.Flags().StringVarP(&ConvertOut, "out", "o", "", "Specify a file name to save objects to") convertCmd.Flags().StringVarP(&ConvertOut, "out", "o", "", "Specify a file name to save objects to")
convertCmd.Flags().IntVar(&ConvertReplicas, "replicas", 1, "Specify the number of repliaces in the generate resource spec") convertCmd.Flags().IntVar(&ConvertReplicas, "replicas", 1, "Specify the number of repliaces in the generate resource spec")
convertCmd.Flags().StringVar(&ConvertVolumes, "volumes", "persistentVolumeClaim", `Volumes to be generated ("persistentVolumeClaim"|"emptyDir")`)
// Deprecated commands
convertCmd.Flags().BoolVar(&ConvertEmptyVols, "emptyvols", false, "Use Empty Volumes. Do not generate PVCs")
convertCmd.Flags().MarkDeprecated("emptyvols", "emptyvols has been marked as deprecated. Use --volumes empty")
// In order to 'separate' both OpenShift and Kubernetes only flags. A custom help page is created // In order to 'separate' both OpenShift and Kubernetes only flags. A custom help page is created
customHelp := `Usage:{{if .Runnable}} customHelp := `Usage:{{if .Runnable}}

View File

@ -29,6 +29,7 @@ import (
var ( var (
UpReplicas int UpReplicas int
UpEmptyVols bool UpEmptyVols bool
UpVolumes string
UpInsecureRepo bool UpInsecureRepo bool
UpNamespace string UpNamespace string
UpOpt kobject.ConvertOptions UpOpt kobject.ConvertOptions
@ -54,6 +55,7 @@ var upCmd = &cobra.Command{
InputFiles: GlobalFiles, InputFiles: GlobalFiles,
Provider: strings.ToLower(GlobalProvider), Provider: strings.ToLower(GlobalProvider),
EmptyVols: UpEmptyVols, EmptyVols: UpEmptyVols,
Volumes: UpVolumes,
Namespace: UpNamespace, Namespace: UpNamespace,
InsecureRepository: UpInsecureRepo, InsecureRepository: UpInsecureRepo,
IsNamespaceFlag: cmd.Flags().Lookup("namespace").Changed, IsNamespaceFlag: cmd.Flags().Lookup("namespace").Changed,
@ -68,10 +70,15 @@ var upCmd = &cobra.Command{
} }
func init() { func init() {
upCmd.Flags().BoolVar(&UpEmptyVols, "emptyvols", false, "Use empty volumes. Do not generate PersistentVolumeClaim")
upCmd.Flags().IntVar(&UpReplicas, "replicas", 1, "Specify the number of replicas generated") upCmd.Flags().IntVar(&UpReplicas, "replicas", 1, "Specify the number of replicas generated")
upCmd.Flags().StringVar(&UpVolumes, "volumes", "persistentVolumeClaim", `Volumes to be generated ("persistentVolumeClaim"|"emptyDir")`)
upCmd.Flags().BoolVar(&UpInsecureRepo, "insecure-repository", false, "Use an insecure Docker repository for OpenShift ImageStream") upCmd.Flags().BoolVar(&UpInsecureRepo, "insecure-repository", false, "Use an insecure Docker repository for OpenShift ImageStream")
upCmd.Flags().StringVar(&UpNamespace, "namespace", "default", "Specify Namespace to deploy your application") upCmd.Flags().StringVar(&UpNamespace, "namespace", "default", "Specify Namespace to deploy your application")
upCmd.Flags().StringVar(&UpBuild, "build", "local", `Set the type of build ("local"|"build-config" (OpenShift only)|"none")`) upCmd.Flags().StringVar(&UpBuild, "build", "local", `Set the type of build ("local"|"build-config" (OpenShift only)|"none")`)
// Deprecated
upCmd.Flags().BoolVar(&UpEmptyVols, "emptyvols", false, "Use empty volumes. Do not generate PersistentVolumeClaim")
upCmd.Flags().MarkDeprecated("emptyvols", "emptyvols has been marked as deprecated. Use --volumes empty")
RootCmd.AddCommand(upCmd) RootCmd.AddCommand(upCmd)
} }

View File

@ -44,6 +44,7 @@ type ConvertOptions struct {
GenerateYaml bool GenerateYaml bool
GenerateJSON bool GenerateJSON bool
EmptyVols bool EmptyVols bool
Volumes string
InsecureRepository bool InsecureRepository bool
Replicas int Replicas int
InputFiles []string InputFiles []string

View File

@ -383,6 +383,10 @@ func (k *Kubernetes) ConfigVolumes(name string, service kobject.ServiceConfig) (
// as opposed to persistent volumes and volume claims // as opposed to persistent volumes and volume claims
useEmptyVolumes := k.Opt.EmptyVols useEmptyVolumes := k.Opt.EmptyVols
if k.Opt.Volumes == "emptyDir" {
useEmptyVolumes = true
}
var count int var count int
//interating over array of `Vols` struct as it contains all necessary information about volumes //interating over array of `Vols` struct as it contains all necessary information about volumes
for _, volume := range service.Volumes { for _, volume := range service.Volumes {
@ -684,7 +688,7 @@ func (k *Kubernetes) Deploy(komposeObject kobject.KomposeObject, opt kobject.Con
} }
pvcStr := " " pvcStr := " "
if !opt.EmptyVols { if !opt.EmptyVols || opt.Volumes != "emptyDir" {
pvcStr = " and PersistentVolumeClaims " pvcStr = " and PersistentVolumeClaims "
} }
log.Info("We are going to create Kubernetes Deployments, Services" + pvcStr + "for your Dockerized application. " + log.Info("We are going to create Kubernetes Deployments, Services" + pvcStr + "for your Dockerized application. " +
@ -736,7 +740,7 @@ func (k *Kubernetes) Deploy(komposeObject kobject.KomposeObject, opt kobject.Con
} }
} }
if !opt.EmptyVols { if !opt.EmptyVols || opt.Volumes != "emptyDir" {
pvcStr = ",pvc" pvcStr = ",pvc"
} else { } else {
pvcStr = "" pvcStr = ""

View File

@ -425,7 +425,7 @@ func (o *OpenShift) Deploy(komposeObject kobject.KomposeObject, opt kobject.Conv
} }
pvcStr := " " pvcStr := " "
if !opt.EmptyVols { if !opt.EmptyVols || opt.Volumes != "emptyDir" {
pvcStr = " and PersistentVolumeClaims " pvcStr = " and PersistentVolumeClaims "
} }
log.Info("We are going to create OpenShift DeploymentConfigs, Services" + pvcStr + "for your Dockerized application. \n" + log.Info("We are going to create OpenShift DeploymentConfigs, Services" + pvcStr + "for your Dockerized application. \n" +
@ -493,7 +493,7 @@ func (o *OpenShift) Deploy(komposeObject kobject.KomposeObject, opt kobject.Conv
} }
} }
if !opt.EmptyVols { if !opt.EmptyVols || opt.Volumes != "emptyDir" {
pvcStr = ",pvc" pvcStr = ",pvc"
} else { } else {
pvcStr = "" pvcStr = ""

View File

@ -369,6 +369,10 @@ cmd="kompose convert --provider=openshift -f $KOMPOSE_ROOT/script/test/fixtures/
sed -e "s;%VERSION%;$version;g" -e "s;%CMD%;$cmd;g" $KOMPOSE_ROOT/script/test/fixtures/change-in-volume/output-os-template.json > /tmp/output-os.json sed -e "s;%VERSION%;$version;g" -e "s;%CMD%;$cmd;g" $KOMPOSE_ROOT/script/test/fixtures/change-in-volume/output-os-template.json > /tmp/output-os.json
convert::expect_success_and_warning "kompose convert --provider=openshift -f $KOMPOSE_ROOT/script/test/fixtures/change-in-volume/docker-compose.yml --stdout -j" "/tmp/output-os.json" "Volume mount on the host "\"."\" isn't supported - ignoring path on the host" convert::expect_success_and_warning "kompose convert --provider=openshift -f $KOMPOSE_ROOT/script/test/fixtures/change-in-volume/docker-compose.yml --stdout -j" "/tmp/output-os.json" "Volume mount on the host "\"."\" isn't supported - ignoring path on the host"
# Test that empty-vols works
cmd="kompose convert -f $KOMPOSE_ROOT/script/test/fixtures/change-in-volume/docker-compose.yml --stdout -j --volumes emptyDir"
sed -e "s;%VERSION%;$version;g" -e "s;%CMD%;$cmd;g" $KOMPOSE_ROOT/script/test/fixtures/change-in-volume/output-k8s-empty-vols-template.json > /tmp/output-k8s.json
convert::expect_success_and_warning "kompose convert -f $KOMPOSE_ROOT/script/test/fixtures/change-in-volume/docker-compose.yml --stdout -j --volumes emptyDir" "/tmp/output-k8s.json" "Volume mount on the host "\"."\" isn't supported - ignoring path on the host"
# Test related to support docker-compose.yaml beside docker-compose.yml # Test related to support docker-compose.yaml beside docker-compose.yml
# Store the original path # Store the original path

View File

@ -0,0 +1,167 @@
{
"kind": "List",
"apiVersion": "v1",
"metadata": {},
"items": [
{
"kind": "Service",
"apiVersion": "v1",
"metadata": {
"name": "redis",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "redis"
},
"annotations": {
"kompose.cmd": "%CMD%",
"kompose.version": "%VERSION%"
}
},
"spec": {
"ports": [
{
"name": "headless",
"port": 55555,
"targetPort": 0
}
],
"selector": {
"io.kompose.service": "redis"
},
"clusterIP": "None"
},
"status": {
"loadBalancer": {}
}
},
{
"kind": "Service",
"apiVersion": "v1",
"metadata": {
"name": "web",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "web"
},
"annotations": {
"kompose.cmd": "%CMD%",
"kompose.version": "%VERSION%"
}
},
"spec": {
"ports": [
{
"name": "5000",
"port": 5000,
"targetPort": 5000
}
],
"selector": {
"io.kompose.service": "web"
}
},
"status": {
"loadBalancer": {}
}
},
{
"kind": "Deployment",
"apiVersion": "extensions/v1beta1",
"metadata": {
"name": "redis",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "redis"
},
"annotations": {
"kompose.cmd": "%CMD%",
"kompose.version": "%VERSION%"
}
},
"spec": {
"replicas": 1,
"template": {
"metadata": {
"creationTimestamp": null,
"labels": {
"io.kompose.service": "redis"
}
},
"spec": {
"containers": [
{
"name": "redis",
"image": "redis",
"resources": {}
}
],
"restartPolicy": "Always"
}
},
"strategy": {}
},
"status": {}
},
{
"kind": "Deployment",
"apiVersion": "extensions/v1beta1",
"metadata": {
"name": "web",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "web"
},
"annotations": {
"kompose.cmd": "%CMD%",
"kompose.version": "%VERSION%"
}
},
"spec": {
"replicas": 1,
"template": {
"metadata": {
"creationTimestamp": null,
"labels": {
"io.kompose.service": "web"
}
},
"spec": {
"volumes": [
{
"name": "web-empty0",
"emptyDir": {}
}
],
"containers": [
{
"name": "web",
"image": "flask_web",
"args": [
"python",
"app.py"
],
"ports": [
{
"containerPort": 5000
}
],
"resources": {},
"volumeMounts": [
{
"name": "web-empty0",
"mountPath": "/code"
}
]
}
],
"restartPolicy": "Always"
}
},
"strategy": {
"type": "Recreate"
}
},
"status": {}
}
]
}