Skip to content

Commit

Permalink
feat: ext4 quota + refacto
Browse files Browse the repository at this point in the history
  • Loading branch information
devthejo committed Jan 22, 2024
1 parent 456f8fe commit 9d462ef
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 31 deletions.
2 changes: 2 additions & 0 deletions modules/metal-debian/metal-debian.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ packages:
installer: apt
quota:
installer: apt
quotatool:
installer: apt
sshd-config:
installer: install
version: "0.9.1"
Expand Down
11 changes: 10 additions & 1 deletion plugins/linux/plays/services/disks/mount.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ const { createPlay, $ } = require("@foundernetes/blueprint")

module.exports = async () => {
return createPlay(async (disk) => {
const { mountPath, device, auto = true, extraFlags = [] } = disk
const {
mountPath,
device,
auto = true,
extraFlags = [],
ensureUnmount = true,
} = disk
return {
async check() {
const isUUID = device.startsWith("UUID=")
Expand All @@ -18,6 +24,9 @@ module.exports = async () => {
return stdout.split("\n").includes(isUUID ? device.slice(5) : device)
},
async run() {
if (ensureUnmount) {
await $(`umount -l ${mountPath}`, { sudo: true })
}
await $(`mkdir -p ${mountPath}`, { sudo: true })
await $(
`mount ${auto ? "-t auto" : ""} ${extraFlags.join(
Expand Down
26 changes: 1 addition & 25 deletions plugins/linux/plays/services/lxd/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,10 @@ const yaml = require("@foundernetes/std/yaml")
const deepmerge = require("@foundernetes/std/deepmerge")

const { createComposer } = require("@foundernetes/blueprint")
const ctx = require("@foundernetes/ctx")

module.exports = async ({ children, plays }) =>
module.exports = async ({ children }) =>
createComposer(
async (vars = {}) => {
const { storageDirs = ["/storage"] } = vars

const iterator = ctx.require("iterator")

const { instances: userInstances = {} } = vars
const defaultInstancesYaml = await fs.readFile(
path.join(__dirname, "instances.yaml"),
Expand All @@ -21,25 +16,6 @@ module.exports = async ({ children, plays }) =>
const defaultInstances = yaml.load(defaultInstancesYaml)
const instances = deepmerge({}, defaultInstances, userInstances)

await iterator.each(storageDirs, async (storageDir) => {
await plays.std.ensureDir(
{
dir: `${storageDir}/shared`,
sudo: true,
},
{ tags: ["lxd"] }
)
await iterator.eachOf(instances.nodes, async (_, name) => {
await plays.std.ensureDir(
{
dir: `${storageDir}/nodes/${name}`,
sudo: true,
},
{ tags: ["lxd"] }
)
})
})

await children.host({}, { tags: ["lxd"] })
const { preseed } = vars
await children.user({}, { tags: ["lxd"] })
Expand Down
11 changes: 6 additions & 5 deletions plugins/linux/plays/services/lxd/instances.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@ default:
network: lxdbr0
type: nic
config:
# update manually using `lxc config set node1 raw.lxc "<put the config inlined here>"`
raw.lxc: |
lxc.apparmor.profile=unconfined
lxc.cap.drop=
lxc.rootfs.options=quota,prjquota
lxc.cgroup.devices.allow=a
lxc.mount.auto=proc:rw sys:rw cgroup:rw
lxc.seccomp.profile=
lxc.mount.entry=/storage/shared storage/shared none rw,bind,create=dir 0 0
lxc.mount.entry=/storage/nodes/node$${{ index }} storage/node none rw,bind,create=dir 0 0
lxc.mount.entry=/storage2/shared storage2/shared none rw,bind,create=dir 0 0
lxc.mount.entry=/storage2/nodes/node$${{ index }} storage2/node none rw,bind,create=dir 0 0
lxc.mount.entry=/data data none rw,bind,create=dir 0 0
lxc.mount.entry=/var data-basic none rw,bind,create=dir 0 0
# lxc.mount.entry=UID=xxx dev/nvme0n1p3 none bind,create=file 0 0
# linux.kernel_modules: ip_tables,ip6_tables,netlink_diag,nf_nat,overlay,xt_conntrack
linux.kernel_modules: ip_tables,ip6_tables,netlink_diag,nf_nat,overlay
linux.kernel_modules: ip_tables,ip6_tables,netlink_diag,nf_nat,overlay,quota_v1,quota_v2
security.privileged: "true"
security.nesting: "true"
cloud-init.user-data:
Expand Down

0 comments on commit 9d462ef

Please sign in to comment.