Architecture Overview
The NFS Quota Agent is a daemon that automatically manages filesystem-level (XFS, ext4) project quotas for NFS-based PersistentVolumes (PVs) in Kubernetes. The agent watches the Kubernetes API and applies quota settings to the local filesystem in accordance with the provisioned PV capacity. (You can view the storage configuration of the Narwhal IDP cluster in the storage documentation.)
Operation Mechanism (Reconcile Loop)
The following flowchart illustrates the entire reconcile loop, from watching PV events to applying filesystem quotas.
- Filesystem Detection: Upon startup, the agent automatically identifies the filesystem type as either XFS or ext4.
- PV Watcher: Utilizing
client-go v0.29.0, it watches for NFS PVs in theBoundstate.- It supports both native NFS PVs (
pv.Spec.NFS) and CSI NFS PVs (nfs.csi.k8s.io). - The watch targets can be filtered by a specific provisioner via
--provisioner-name, or configured to target all NFS PVs using the--process-all-nfsflag.
- It supports both native NFS PVs (
- Path Mapping: Converts the NFS server export path into a local mount path within the container.
- Project ID Generation: Uses an FNV hash to generate a unique project ID derived from the PV name.
- Quota Application (Quota Manager):
- XFS: Uses the
xfs_quotacommand to initialize the project and set block capacity limits (bhard). - ext4: Uses
chattrto set project attributes, then uses thesetquotacommand to restrict capacity. - The agent maintains the
/etc/projectsand/etc/projidmapping files.
- XFS: Uses the
- Status Reporting: The quota enforcement status (
pending,applied,failed) is recorded in the PV'snfs.io/quota-statusannotation.
Module and Package Layout
The agent is compiled in a Go 1.25 environment and is modularized under the internal directory for separation of concerns.
cmd/nfs-quota-agent/: The CLI entry point. Responsible for flag parsing and routing for subcommands (run,status,top,report,cleanup,ui,audit,completion,version).internal/agent/: Core agent logic. Contains theQuotaAgentstruct, the PV watch loop (watch.go), quota synchronization, and orphan detection mechanisms.internal/quota/: Filesystem quota command implementation. Encapsulates OS-dependent commands (XFS:xfs.go, ext4:ext4.go) and project ID management (project.go).internal/policy/: Analyzes Kubernetes LimitRange and Namespace resources to apply storage quota policy priorities.internal/audit/: Logs all quota actions, such asCREATE,UPDATE,DELETE, andCLEANUP.internal/history/: Periodically records snapshots of disk usage to track storage trends (store.go).internal/metrics/: Exposes Prometheus-compatible metrics (e.g.,nfs_quota_used_bytes) at the:9090/metricsendpoint.internal/status/,internal/cleanup/,internal/ui/,internal/completion/,internal/util/: Auxiliary modules handling status printing, standalone cleanup, the embedded web dashboard, shell completion script generation, and shared format utilities.
Deployment Shape (Helm Chart)
Because the agent executes local filesystem commands (xfs_quota, setquota), it must be deployed on the node running the NFS server.
- Node Selector: Scheduling is constrained to the NFS server node using
nodeSelector: nfs-server: "true". - Permissions and Volumes:
- Requires access to the host's PID namespace (
hostPID: true). - The container mounts the host's NFS export directory via
hostPath, along with/devfor block device access, and quota mapping files like/etc/projectsand/etc/projid.
- Requires access to the host's PID namespace (
- Provisioning Configuration Support:
- The target provisioner can be specified in the Helm
values.yamlviaconfig.provisionerName(e.g.,nfs.csi.k8s.io). - Individual feature modules are toggled using settings like
webUI.enabled,audit.enabled,cleanup.enabled,history.enabled, andpolicy.enabled.
- The target provisioner can be specified in the Helm