Skip to content

feature:Add limit container rootfs dirsize#65

Open
Frank-svg-dev wants to merge 5 commits intokcrow-io:mainfrom
Frank-svg-dev:add-limit-container-rootfs-dirsize
Open

feature:Add limit container rootfs dirsize#65
Frank-svg-dev wants to merge 5 commits intokcrow-io:mainfrom
Frank-svg-dev:add-limit-container-rootfs-dirsize

Conversation

@Frank-svg-dev
Copy link
Copy Markdown
Contributor

This feature uses the NRI interface to configure the kernel's native xfs_ quota command to implement the disk restriction function of container rootfs, which can avoid 100% of the host/var/lib/constaneld caused by writing a large number of files in the container
Installation before We need to add the prjquota attribute to the mounting attribute of the disk where the/var/lib/container directory is located, for xfsquota to set quotas
image
Feature Demo
  1. deployment setting annotation <size.disk.kcorw.io (MB)>
image in container image
  1. namespace setting annotation and in container rootfs disk size
image
  1. kcrow logs
image

@Frank-svg-dev
Copy link
Copy Markdown
Contributor Author

@yylt pls review, tks

Copy link
Copy Markdown
Collaborator

@yylt yylt left a comment

Choose a reason for hiding this comment

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

should git rebase

pkg/disk/disk.go Outdated
return "", fmt.Errorf("overlay path not found in mountinfo for %s", containerRootfs)
}

func generateProjectID(containerID string) uint32 {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hash Conflict? maybe could use snapshot id found by getOverlayPath

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

thk you reply, you are right, However, since xfs_quota projectID is an int type and Container ID is a hash value with a length far exceeding int64, I will introduce the crc32.ChecksumIEEE method to directly convert it

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

actually,snapshot id is u64 type, and it is must unique in different container, so it is perfect used as project id in xfs_quota.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think I understand what you mean. Since the snapshot ID of the container is unique, we can use the getOverlayPath method to further crop the upper directory and synchronize the snapshot ID with it, Like this right?
image
i will be update


klog.V(2).Infof("Target XFS Quota Path: %s", rootfsPath)

if err := applyXFSQuota(container.Id, rootfsPath, limitMB); err != nil {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

should check moutpoint support set quota, otherwise failed always.

Copy link
Copy Markdown
Contributor Author

@Frank-svg-dev Frank-svg-dev Jan 16, 2026

Choose a reason for hiding this comment

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

OK, When the quota parameter is not enabled in the containerd directory, in order to avoid calling the disk plugin's CreateContainer and StartContainer methods every time a container is created, I used an initialization check. If the quota parameter is not enabled, the disk plugin will not be loaded

like this :
image

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

You can refer to this, which use cgroup blkio to limit disk usage, If possible, could you migrate XFS quota to that plugins approach?
In fact, the daemon-based NRI plugin is not the recommended approach, as launching plugins via containerd can reduce the attack surface.

add unit test

add unit test

add unit test

Add  /var/lib/containerd directory for checking prjquota mounting parameters
@Frank-svg-dev Frank-svg-dev force-pushed the add-limit-container-rootfs-dirsize branch from 6805777 to 69a6900 Compare January 16, 2026 04:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants