Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "--pvc-request-size" new command line parameter #1406

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cmd/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var (
ConvertBuildBranch string
ConvertBuild string
ConvertVolumes string
ConvertPVCRequestSize string
ConvertChart bool
ConvertDeployment bool
ConvertDaemonSet bool
Expand Down Expand Up @@ -90,6 +91,7 @@ var convertCmd = &cobra.Command{
CreateDeploymentConfig: ConvertDeploymentConfig,
EmptyVols: ConvertEmptyVols,
Volumes: ConvertVolumes,
PVCRequestSize: ConvertPVCRequestSize,
InsecureRepository: ConvertInsecureRepo,
IsDeploymentFlag: cmd.Flags().Lookup("deployment").Changed,
IsDaemonSetFlag: cmd.Flags().Lookup("daemon-set").Changed,
Expand Down Expand Up @@ -153,6 +155,7 @@ func init() {
convertCmd.Flags().StringVarP(&ConvertOut, "out", "o", "", "Specify a file name or directory to save objects to (if path does not exist, a file will be created)")
convertCmd.Flags().IntVar(&ConvertReplicas, "replicas", 1, "Specify the number of replicas in the generated resource spec")
convertCmd.Flags().StringVar(&ConvertVolumes, "volumes", "persistentVolumeClaim", `Volumes to be generated ("persistentVolumeClaim"|"emptyDir"|"hostPath" | "configMap")`)
convertCmd.Flags().StringVar(&ConvertPVCRequestSize, "pvc-request-size", "", `Specify the size of pvc storage requests in the generated resource spec`)
hangyan marked this conversation as resolved.
Show resolved Hide resolved

convertCmd.Flags().BoolVar(&WithKomposeAnnotation, "with-kompose-annotation", true, "Add kompose annotations to generated resource")

Expand Down
3 changes: 2 additions & 1 deletion docs/user-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@ services:
kompose.image-pull-secret: "example-kubernetes-secret"
```

- `kompose.volume.size` defines the requests storage's size in the PersistentVolumeClaim
- `kompose.volume.size` defines the requests storage's size in the PersistentVolumeClaim, or you can use command line parameter `--pvc-request-size`.
The priority follow label (kompose.volume.size) > command parameter(--pvc-request-size) > defaultSize (100Mi)

hangyan marked this conversation as resolved.
Show resolved Hide resolved
For example:

Expand Down
1 change: 1 addition & 0 deletions pkg/kobject/kobject.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type ConvertOptions struct {
StoreManifest bool
EmptyVols bool
Volumes string
PVCRequestSize string
InsecureRepository bool
Replicas int
InputFiles []string
Expand Down
4 changes: 3 additions & 1 deletion pkg/transformer/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,9 @@ func (k *Kubernetes) ConfigVolumes(name string, service kobject.ServiceConfig) (
volsource = k.ConfigPVCVolumeSource(volumeName, readonly)
if volume.VFrom == "" {
defaultSize := PVCRequestSize

if k.Opt.PVCRequestSize != "" {
defaultSize = k.Opt.PVCRequestSize
}
if len(volume.PVCSize) > 0 {
defaultSize = volume.PVCSize
} else {
Expand Down
4 changes: 4 additions & 0 deletions script/test/cmd/tests_new.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,7 @@ dst=$TEMP_DIR/output_dir/
convert::check_artifacts_generated "kompose -f $KOMPOSE_ROOT/script/test/fixtures/redis-example/docker-compose.yml convert -o $dst -j" "${dst}redis-deployment.json" "${dst}redis-service.json" "${dst}web-deployment.json" "${dst}web-service.json"
# Behavior with -o <non-existent-dirname>/<filename>
convert::check_artifacts_generated "kompose -f $KOMPOSE_ROOT/script/test/fixtures/redis-example/docker-compose.yml convert -o $TEMP_DIR/output_dir2/output_file -j" "$TEMP_DIR/output_dir2/output_file"

#TEST the pvc-request-size command parameter
convert::check_artifacts_generated "kompose -f $KOMPOSE_ROOT/script/test/fixtures/pvc-request-size/docker-compose.yml convert -o $TEMP_DIR/output_dir2/output-k8s.json -j --pvc-request-size=300Mi" "$TEMP_DIR/output_dir2/output-k8s.json"
convert::check_artifacts_generated "kompose --provider=openshift -f $KOMPOSE_ROOT/script/test/fixtures/pvc-request-size/docker-compose.yml convert -o $TEMP_DIR/output_dir2/output-os.json -j --pvc-request-size=300Mi" "$TEMP_DIR/output_dir2/output-os.json"
27 changes: 27 additions & 0 deletions script/test/fixtures/pvc-request-size/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: '2'

services:
redis:
restart: always
image: sameersbn/redis:latest
command:
- --loglevel warning
volumes:
- /srv/docker/gitlab/redis:/var/lib/redis
ports:
- "6379"

postgresql:
restart: always
image: sameersbn/postgresql:9.5-3
volumes:
- /srv/docker/gitlab/postgresql:/var/lib/postgresql
environment:
- DB_USER=gitlab
- DB_PASS=password
- DB_NAME=gitlabhq_production
- DB_EXTENSION=pg_trgm
ports:
- "5432"
labels:
kompose.volume.size: 200Mi
271 changes: 271 additions & 0 deletions script/test/fixtures/pvc-request-size/output-k8s.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,271 @@
{
"kind": "List",
"apiVersion": "v1",
"metadata": {},
"items": [
{
"kind": "Service",
"apiVersion": "v1",
"metadata": {
"name": "postgresql",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "postgresql"
},
"annotations": {
"kompose.cmd": "%CMD%",
"kompose.version": "%VERSION%",
"kompose.volume.size": "200Mi"
}
},
"spec": {
"ports": [
{
"name": "5432",
"port": 5432,
"targetPort": 5432
}
],
"selector": {
"io.kompose.service": "postgresql"
}
},
"status": {
"loadBalancer": {}
}
},
{
"kind": "Service",
"apiVersion": "v1",
"metadata": {
"name": "redis",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "redis"
},
"annotations": {
"kompose.cmd": "%CMD%",
"kompose.version": "%VERSION%"
}
},
"spec": {
"ports": [
{
"name": "6379",
"port": 6379,
"targetPort": 6379
}
],
"selector": {
"io.kompose.service": "redis"
}
},
"status": {
"loadBalancer": {}
}
},
{
"kind": "Deployment",
"apiVersion": "apps/v1",
"metadata": {
"name": "postgresql",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "postgresql"
},
"annotations": {
"kompose.cmd": "%CMD%",
"kompose.version": "%VERSION%",
"kompose.volume.size": "200Mi"
}
},
"spec": {
"replicas": 1,
"selector": {
"matchLabels": {
"io.kompose.service": "postgresql"
}
},
"template": {
"metadata": {
"creationTimestamp": null,
"labels": {
"io.kompose.service": "postgresql"
},
"annotations": {
"kompose.cmd": "%CMD%",
"kompose.version": "%VERSION%",
"kompose.volume.size": "200Mi"
}
},
"spec": {
"volumes": [
{
"name": "postgresql-claim0",
"persistentVolumeClaim": {
"claimName": "postgresql-claim0"
}
}
],
"containers": [
{
"name": "postgresql",
"image": "sameersbn/postgresql:9.5-3",
"ports": [
{
"containerPort": 5432
}
],
"env": [
{
"name": "DB_EXTENSION",
"value": "pg_trgm"
},
{
"name": "DB_NAME",
"value": "gitlabhq_production"
},
{
"name": "DB_PASS",
"value": "password"
},
{
"name": "DB_USER",
"value": "gitlab"
}
],
"resources": {},
"volumeMounts": [
{
"name": "postgresql-claim0",
"mountPath": "/var/lib/postgresql"
}
]
}
],
"restartPolicy": "Always"
}
},
"strategy": {
"type": "Recreate"
}
},
"status": {}
},
{
"kind": "PersistentVolumeClaim",
"apiVersion": "v1",
"metadata": {
"name": "postgresql-claim0",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "postgresql-claim0"
}
},
"spec": {
"accessModes": [
"ReadWriteOnce"
],
"resources": {
"requests": {
"storage": "200Mi"
}
}
},
"status": {}
},
{
"kind": "Deployment",
"apiVersion": "apps/v1",
"metadata": {
"name": "redis",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "redis"
},
"annotations": {
"kompose.cmd": "%CMD%",
"kompose.version": "%VERSION%"
}
},
"spec": {
"replicas": 1,
"selector": {
"matchLabels": {
"io.kompose.service": "redis"
}
},
"template": {
"metadata": {
"creationTimestamp": null,
"labels": {
"io.kompose.service": "redis"
},
"annotations": {
"kompose.cmd": "%CMD%",
"kompose.version": "%VERSION%"
}
},
"spec": {
"volumes": [
{
"name": "redis-claim0",
"persistentVolumeClaim": {
"claimName": "redis-claim0"
}
}
],
"containers": [
{
"name": "redis",
"image": "sameersbn/redis:latest",
"args": [
"--loglevel warning"
],
"ports": [
{
"containerPort": 6379
}
],
"resources": {},
"volumeMounts": [
{
"name": "redis-claim0",
"mountPath": "/var/lib/redis"
}
]
}
],
"restartPolicy": "Always"
}
},
"strategy": {
"type": "Recreate"
}
},
"status": {}
},
{
"kind": "PersistentVolumeClaim",
"apiVersion": "v1",
"metadata": {
"name": "redis-claim0",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "redis-claim0"
}
},
"spec": {
"accessModes": [
"ReadWriteOnce"
],
"resources": {
"requests": {
"storage": "300Mi"
}
}
},
"status": {}
}
]
}
Loading