Skip to content

Commit

Permalink
fix(trait): add size to emptydir
Browse files Browse the repository at this point in the history
It is good to have a limit for security reasons and it is also a workaround for #5752

Closes #5752
  • Loading branch information
squakez committed Sep 6, 2024
1 parent 9d18286 commit b6bcb2b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/trait/trait_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
appsv1 "k8s.io/api/apps/v1"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

serving "knative.dev/serving/pkg/apis/serving/v1"
Expand Down Expand Up @@ -595,7 +596,13 @@ func getVolume(volName, storageType, storageName, filterKey, filterValue string)
ClaimName: storageName,
}
case emptyDirStorageType:
volume.VolumeSource.EmptyDir = &corev1.EmptyDirVolumeSource{}
size, err := resource.ParseQuantity("1Gi")
if err != nil {
log.WithValues("Function", "trait.getVolume").Errorf(err, "could not parse empty dir quantity, skipping")
}
volume.VolumeSource.EmptyDir = &corev1.EmptyDirVolumeSource{
SizeLimit: &size,
}
}

return &volume
Expand Down

2 comments on commit b6bcb2b

@hernanDatgDev
Copy link
Contributor

Choose a reason for hiding this comment

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

@squakez Does it make sense to allow a user the option to provide a size value and then default to "1G" if it's not provided?

@squakez
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@squakez Does it make sense to allow a user the option to provide a size value and then default to "1G" if it's not provided?

Sure it does. We can work to include the size in the parameter configuration, so we can parse such value as well. Feel free to carry on with the development if you can or alternatively you can log an issue so we can keep track of it and see if we can implement already in 2.5 or in the next 2.6 release.

Please sign in to comment.