forked from LaconicNetwork/kompose
feat(deploy): support ephemeral storage requests limits labels
This commit is contained in:
parent
eab2c0119e
commit
3ec739017d
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -390,4 +390,9 @@ convert::expect_success "$os_cmd" "$os_output" || exit 1
|
|||||||
# Test label in compose.yaml appears in the output annotation
|
# Test label in compose.yaml appears in the output annotation
|
||||||
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
|
||||||
|
|
||||||
|
# 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
|
convert::expect_success "$k8s_cmd" "$k8s_output" || exit 1
|
||||||
9
script/test/fixtures/deploy/labels/compose.yaml
vendored
Normal file
9
script/test/fixtures/deploy/labels/compose.yaml
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
services:
|
||||||
|
app:
|
||||||
|
image: node:18-alpine
|
||||||
|
ports:
|
||||||
|
- 3000:3000
|
||||||
|
deploy:
|
||||||
|
labels:
|
||||||
|
requests.ephemeral-storage: 1Gi
|
||||||
|
limits.ephemeral-storage: 1Gi
|
||||||
47
script/test/fixtures/deploy/labels/output-k8s.yaml
vendored
Normal file
47
script/test/fixtures/deploy/labels/output-k8s.yaml
vendored
Normal 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
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user