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

feat(deploy): support ephemeral storage requests limits labels #1936

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 16 additions & 2 deletions pkg/transformer/kubernetes/k8sutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ func KomposeObjectToServiceConfigGroupMapping(komposeObject *kobject.KomposeObje
// TranslatePodResource config pod resources
func TranslatePodResource(service *kobject.ServiceConfig, template *api.PodTemplateSpec) {
// Configure the resource limits
if service.MemLimit != 0 || service.CPULimit != 0 {
if service.MemLimit != 0 || service.CPULimit != 0 || service.DeployLabels["limits.ephemeral-storage"] != "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should follow https://kompose.io/user-guide/#labels convention.

Maybe instead let's do kompose.ephemeral-storage.limit and kompose.ephemeral-storage.request

?

resourceLimit := api.ResourceList{}

if service.MemLimit != 0 {
Expand All @@ -822,11 +822,18 @@ func TranslatePodResource(service *kobject.ServiceConfig, template *api.PodTempl
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
}

// 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{}

if service.MemReservation != 0 {
Expand All @@ -837,6 +844,13 @@ func TranslatePodResource(service *kobject.ServiceConfig, template *api.PodTempl
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
}
}
Expand Down
5 changes: 5 additions & 0 deletions script/test/cmd/tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -390,4 +390,9 @@ convert::expect_success "$os_cmd" "$os_output" || exit 1
# 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_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
9 changes: 9 additions & 0 deletions script/test/fixtures/deploy/labels/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
services:
app:
image: node:18-alpine
ports:
- 3000:3000
deploy:
labels:
requests.ephemeral-storage: 1Gi
limits.ephemeral-storage: 1Gi
47 changes: 47 additions & 0 deletions script/test/fixtures/deploy/labels/output-k8s.yaml
Original file line number Diff line number Diff line change
@@ -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