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

This commit is contained in:
ithaiq 2021-08-07 14:47:02 +08:00 committed by GitHub
parent 33b646c116
commit b605fd986c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 679 additions and 2 deletions

View File

@ -33,6 +33,7 @@ var (
ConvertBuildBranch string
ConvertBuild string
ConvertVolumes string
ConvertPVCRequestSize string
ConvertChart bool
ConvertDeployment bool
ConvertDaemonSet bool
@ -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,
@ -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`)
convertCmd.Flags().BoolVar(&WithKomposeAnnotation, "with-kompose-annotation", true, "Add kompose annotations to generated resource")

View File

@ -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)
For example:

View File

@ -58,6 +58,7 @@ type ConvertOptions struct {
StoreManifest bool
EmptyVols bool
Volumes string
PVCRequestSize string
InsecureRepository bool
Replicas int
InputFiles []string

View File

@ -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 {

View File

@ -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"

View File

@ -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

View File

@ -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": {}
}
]
}

View File

@ -0,0 +1,368 @@
{
"kind": "List",
"apiVersion": "v1",
"metadata": {},
"items": [
{
"kind": "Service",
"apiVersion": "v1",
"metadata": {
"name": "postgresql",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "postgresql"
},
"annotations": {
"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"
}
},
"spec": {
"ports": [
{
"name": "6379",
"port": 6379,
"targetPort": 6379
}
],
"selector": {
"io.kompose.service": "redis"
}
},
"status": {
"loadBalancer": {}
}
},
{
"kind": "DeploymentConfig",
"apiVersion": "v1",
"metadata": {
"name": "postgresql",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "postgresql"
},
"annotations": {
"kompose.volume.size": "200Mi"
}
},
"spec": {
"strategy": {
"type": "Recreate",
"resources": {}
},
"triggers": [
{
"type": "ConfigChange"
},
{
"type": "ImageChange",
"imageChangeParams": {
"automatic": true,
"containerNames": [
"postgresql"
],
"from": {
"kind": "ImageStreamTag",
"name": "postgresql:9.5-3"
}
}
}
],
"replicas": 1,
"test": false,
"selector": {
"io.kompose.service": "postgresql"
},
"template": {
"metadata": {
"creationTimestamp": null,
"labels": {
"io.kompose.service": "postgresql"
}
},
"spec": {
"volumes": [
{
"name": "postgresql-claim0",
"persistentVolumeClaim": {
"claimName": "postgresql-claim0"
}
}
],
"containers": [
{
"name": "postgresql",
"image": " ",
"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"
}
}
},
"status": {
"latestVersion": 0,
"observedGeneration": 0,
"replicas": 0,
"updatedReplicas": 0,
"availableReplicas": 0,
"unavailableReplicas": 0
}
},
{
"kind": "ImageStream",
"apiVersion": "v1",
"metadata": {
"name": "postgresql",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "postgresql"
}
},
"spec": {
"lookupPolicy": {
"local": false
},
"tags": [
{
"name": "",
"annotations": null,
"from": {
"kind": "DockerImage",
"name": "sameersbn/postgresql:9.5-3"
},
"generation": null,
"importPolicy": {},
"referencePolicy": {
"type": ""
}
}
]
},
"status": {
"dockerImageRepository": ""
}
},
{
"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": "DeploymentConfig",
"apiVersion": "v1",
"metadata": {
"name": "redis",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "redis"
}
},
"spec": {
"strategy": {
"type": "Recreate",
"resources": {}
},
"triggers": [
{
"type": "ConfigChange"
},
{
"type": "ImageChange",
"imageChangeParams": {
"automatic": true,
"containerNames": [
"redis"
],
"from": {
"kind": "ImageStreamTag",
"name": "redis:latest"
}
}
}
],
"replicas": 1,
"test": false,
"selector": {
"io.kompose.service": "redis"
},
"template": {
"metadata": {
"creationTimestamp": null,
"labels": {
"io.kompose.service": "redis"
}
},
"spec": {
"volumes": [
{
"name": "redis-claim0",
"persistentVolumeClaim": {
"claimName": "redis-claim0"
}
}
],
"containers": [
{
"name": "redis",
"image": " ",
"args": [
"--loglevel warning"
],
"ports": [
{
"containerPort": 6379
}
],
"resources": {},
"volumeMounts": [
{
"name": "redis-claim0",
"mountPath": "/var/lib/redis"
}
]
}
],
"restartPolicy": "Always"
}
}
},
"status": {
"latestVersion": 0,
"observedGeneration": 0,
"replicas": 0,
"updatedReplicas": 0,
"availableReplicas": 0,
"unavailableReplicas": 0
}
},
{
"kind": "ImageStream",
"apiVersion": "v1",
"metadata": {
"name": "redis",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "redis"
}
},
"spec": {
"lookupPolicy": {
"local": false
},
"tags": [
{
"name": "",
"annotations": null,
"from": {
"kind": "DockerImage",
"name": "sameersbn/redis:latest"
},
"generation": null,
"importPolicy": {},
"referencePolicy": {
"type": ""
}
}
]
},
"status": {
"dockerImageRepository": ""
}
},
{
"kind": "PersistentVolumeClaim",
"apiVersion": "v1",
"metadata": {
"name": "redis-claim0",
"creationTimestamp": null,
"labels": {
"io.kompose.service": "redis-claim0"
}
},
"spec": {
"accessModes": [
"ReadWriteOnce"
],
"resources": {
"requests": {
"storage": "300Mi"
}
}
},
"status": {}
}
]
}