feat(deploy): support ephemeral storage requests limits labels

This commit is contained in:
João Vitor Paes de Barros do Carmo 2024-09-27 01:02:46 +01:00
parent eab2c0119e
commit 3ec739017d
4 changed files with 77 additions and 2 deletions

View File

@ -811,7 +811,7 @@ func KomposeObjectToServiceConfigGroupMapping(komposeObject *kobject.KomposeObje
// TranslatePodResource config pod resources // TranslatePodResource config pod resources
func TranslatePodResource(service *kobject.ServiceConfig, template *api.PodTemplateSpec) { func TranslatePodResource(service *kobject.ServiceConfig, template *api.PodTemplateSpec) {
// Configure the resource limits // Configure the resource limits
if service.MemLimit != 0 || service.CPULimit != 0 { if service.MemLimit != 0 || service.CPULimit != 0 || service.DeployLabels["limits.ephemeral-storage"] != "" {
resourceLimit := api.ResourceList{} resourceLimit := api.ResourceList{}
if service.MemLimit != 0 { if service.MemLimit != 0 {
@ -822,11 +822,18 @@ func TranslatePodResource(service *kobject.ServiceConfig, template *api.PodTempl
resourceLimit[api.ResourceCPU] = *resource.NewMilliQuantity(service.CPULimit, resource.DecimalSI) resourceLimit[api.ResourceCPU] = *resource.NewMilliQuantity(service.CPULimit, resource.DecimalSI)
} }
// Check for ephemeral-storage in deploy labels
if val, ok := service.DeployLabels["limits.ephemeral-storage"]; ok {
if quantity, err := resource.ParseQuantity(val); err == nil {
resourceLimit[api.ResourceEphemeralStorage] = quantity
}
}
template.Spec.Containers[0].Resources.Limits = resourceLimit template.Spec.Containers[0].Resources.Limits = resourceLimit
} }
// Configure the resource requests // Configure the resource requests
if service.MemReservation != 0 || service.CPUReservation != 0 { if service.MemReservation != 0 || service.CPUReservation != 0 || service.DeployLabels["requests.ephemeral-storage"] != "" {
resourceRequests := api.ResourceList{} resourceRequests := api.ResourceList{}
if service.MemReservation != 0 { if service.MemReservation != 0 {
@ -837,6 +844,13 @@ func TranslatePodResource(service *kobject.ServiceConfig, template *api.PodTempl
resourceRequests[api.ResourceCPU] = *resource.NewMilliQuantity(service.CPUReservation, resource.DecimalSI) resourceRequests[api.ResourceCPU] = *resource.NewMilliQuantity(service.CPUReservation, resource.DecimalSI)
} }
// Check for ephemeral-storage in deploy labels
if val, ok := service.DeployLabels["requests.ephemeral-storage"]; ok {
if quantity, err := resource.ParseQuantity(val); err == nil {
resourceRequests[api.ResourceEphemeralStorage] = quantity
}
}
template.Spec.Containers[0].Resources.Requests = resourceRequests template.Spec.Containers[0].Resources.Requests = resourceRequests
} }
} }

View File

@ -391,3 +391,8 @@ convert::expect_success "$os_cmd" "$os_output" || exit 1
k8s_cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/label/compose.yaml convert --stdout --with-kompose-annotation=false" k8s_cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/label/compose.yaml convert --stdout --with-kompose-annotation=false"
k8s_output="$KOMPOSE_ROOT/script/test/fixtures/label/output-k8s.yaml" k8s_output="$KOMPOSE_ROOT/script/test/fixtures/label/output-k8s.yaml"
convert::expect_success "$k8s_cmd" "$k8s_output" || exit 1 convert::expect_success "$k8s_cmd" "$k8s_output" || exit 1
# Test deploy.labels in compose.yaml appears in the output
k8s_cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/deploy/labels/compose.yaml convert --stdout --with-kompose-annotation=false"
k8s_output="$KOMPOSE_ROOT/script/test/fixtures/deploy/labels/output-k8s.yaml"
convert::expect_success "$k8s_cmd" "$k8s_output" || exit 1

View File

@ -0,0 +1,9 @@
services:
app:
image: node:18-alpine
ports:
- 3000:3000
deploy:
labels:
requests.ephemeral-storage: 1Gi
limits.ephemeral-storage: 1Gi

View File

@ -0,0 +1,47 @@
---
apiVersion: v1
kind: Service
metadata:
labels:
io.kompose.service: app
name: app
spec:
ports:
- name: "3000"
port: 3000
targetPort: 3000
selector:
io.kompose.service: app
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
io.kompose.service: app
limits.ephemeral-storage: 1Gi
requests.ephemeral-storage: 1Gi
name: app
spec:
replicas: 1
selector:
matchLabels:
io.kompose.service: app
template:
metadata:
labels:
io.kompose.service: app
spec:
containers:
- image: node:18-alpine
name: app
ports:
- containerPort: 3000
protocol: TCP
resources:
limits:
ephemeral-storage: 1Gi
requests:
ephemeral-storage: 1Gi
restartPolicy: Always