Compare commits
31
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
282e1c5236 | ||
|
|
339dcdd214 | ||
|
|
9b15ea5d33 | ||
|
|
344f748b84 | ||
|
|
84cf39e7d9 | ||
|
|
afc9fd36d7 | ||
|
|
3e6c8188da | ||
|
|
4c3a2b4226 | ||
|
|
c40fc0caac | ||
|
|
49fd2ba307 | ||
|
|
85ce271fd6 | ||
|
|
7548402542 | ||
|
|
9e0ce35712 | ||
|
|
c1e409780d | ||
|
|
5a2d32ea84 | ||
|
|
e3fab0e151 | ||
|
|
a1867b18c8 | ||
|
|
71b0f3ce7d | ||
|
|
d0600b9153 | ||
|
|
7acf83e68d | ||
|
|
088cb5add1 | ||
|
|
b04ab52fd2 | ||
|
|
ff2b565677 | ||
|
|
4b22f4ad11 | ||
|
|
020b277a04 | ||
|
|
ba53cbc465 | ||
|
|
b4d27c6546 | ||
|
|
481ff9e7ac | ||
|
|
5865c38ea7 | ||
|
|
4f90febc89 | ||
|
|
90c3d37e74 |
No files matched your search
@@ -7,14 +7,18 @@
|
|||||||
#
|
#
|
||||||
# Scope: used for PRs only (list, open, check CI status, merge after your OK).
|
# Scope: used for PRs only (list, open, check CI status, merge after your OK).
|
||||||
# Technically it can call any endpoint; CLAUDE.md limits its use to PRs.
|
# Technically it can call any endpoint; CLAUDE.md limits its use to PRs.
|
||||||
# In .claude/settings.json, GET runs without a prompt; POST, PATCH, PUT and
|
# In .claude/settings.json, GET and POST (e.g. opening a PR) run without a
|
||||||
# DELETE (anything that changes something) always ask first.
|
# prompt. Merging a PR (POST .../merge), PATCH, PUT and DELETE always ask first.
|
||||||
#
|
#
|
||||||
# Usage: gitea.sh METHOD PATH [BODY]
|
# Usage: gitea.sh METHOD PATH [BODY]
|
||||||
# METHOD GET | POST | PATCH | PUT | DELETE
|
# METHOD GET | POST | PATCH | PUT | DELETE
|
||||||
# PATH path below /api/v1, e.g. /repos/kasun/homelab-infrastructure-as-code/pulls?state=open
|
# PATH path below /api/v1, e.g. /repos/kasun/homelab-infrastructure-as-code/pulls?state=open
|
||||||
# BODY JSON string, or @file to send a file
|
# BODY JSON string, or @file to send a file
|
||||||
#
|
#
|
||||||
|
# Read-only CI wait: gitea.sh WAIT /repos/OWNER/REPO/commits/SHA/status
|
||||||
|
# Polls until checks finish. Exit 0: passed or no CI ran. 1: a check failed.
|
||||||
|
# 2: bad usage. 3: timed out after 15 minutes.
|
||||||
|
#
|
||||||
# Config (outside the repo, never committed):
|
# Config (outside the repo, never committed):
|
||||||
# ${XDG_CONFIG_HOME:-~/.config}/homelab-agent/url e.g. http://192.168.1.208:3000
|
# ${XDG_CONFIG_HOME:-~/.config}/homelab-agent/url e.g. http://192.168.1.208:3000
|
||||||
# ${XDG_CONFIG_HOME:-~/.config}/homelab-agent/token chmod 600
|
# ${XDG_CONFIG_HOME:-~/.config}/homelab-agent/token chmod 600
|
||||||
@@ -28,6 +32,29 @@ method=${1:?usage: gitea.sh METHOD PATH [BODY]}
|
|||||||
path=${2:?usage: gitea.sh METHOD PATH [BODY]}
|
path=${2:?usage: gitea.sh METHOD PATH [BODY]}
|
||||||
body=${3:-}
|
body=${3:-}
|
||||||
|
|
||||||
|
if [[ "$method" == "WAIT" ]]; then
|
||||||
|
[[ "$path" =~ ^/repos/[^/]+/[^/]+/commits/[0-9a-f]{40}/status$ ]] \
|
||||||
|
|| { echo "WAIT only accepts /repos/OWNER/REPO/commits/SHA/status" >&2; exit 2; }
|
||||||
|
for ((i = 1; i <= 45; i++)); do
|
||||||
|
status=$("$0" GET "$path") || status='{}'
|
||||||
|
total=$(jq '.statuses // [] | length' <<<"$status")
|
||||||
|
running=$(jq '[.statuses // [] | .[] | select(.status == "pending" or .status == "running")] | length' <<<"$status")
|
||||||
|
# Give checks time to register. Path-filtered workflows may never start any.
|
||||||
|
if (( total == 0 && i >= 7 )); then
|
||||||
|
echo "no CI ran"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
if (( total > 0 && running == 0 && i >= 4 )); then
|
||||||
|
jq -r '.statuses[] | "\(.context): \(.status) \(.target_url)"' <<<"$status"
|
||||||
|
jq -e '[.statuses[].status] | any(. == "failure" or . == "error") | not' <<<"$status" >/dev/null || exit 1
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
sleep 20
|
||||||
|
done
|
||||||
|
echo "timed out waiting for CI" >&2
|
||||||
|
exit 3
|
||||||
|
fi
|
||||||
|
|
||||||
case "$method" in
|
case "$method" in
|
||||||
GET | POST | PATCH | PUT | DELETE) ;;
|
GET | POST | PATCH | PUT | DELETE) ;;
|
||||||
*) echo "unsupported method: $method" >&2; exit 2 ;;
|
*) echo "unsupported method: $method" >&2; exit 2 ;;
|
||||||
|
|||||||
+44
-3
@@ -20,9 +20,52 @@
|
|||||||
"Bash(kubectl logs *)",
|
"Bash(kubectl logs *)",
|
||||||
"Bash(kubectl top *)",
|
"Bash(kubectl top *)",
|
||||||
"Bash(kubectl config get-contexts *)",
|
"Bash(kubectl config get-contexts *)",
|
||||||
|
"Bash(git log *)",
|
||||||
|
"Bash(git status *)",
|
||||||
|
"Bash(git diff *)",
|
||||||
|
"Bash(git show *)",
|
||||||
|
"Bash(git grep *)",
|
||||||
|
"Bash(git blame *)",
|
||||||
|
"Bash(git ls-files *)",
|
||||||
|
"Bash(git ls-tree *)",
|
||||||
|
"Bash(git rev-parse *)",
|
||||||
|
"Bash(git describe *)",
|
||||||
|
"Bash(git shortlog *)",
|
||||||
|
"Bash(git merge-base *)",
|
||||||
|
"Bash(git reflog show *)",
|
||||||
|
"Bash(git stash list *)",
|
||||||
|
"Bash(git branch --list *)",
|
||||||
|
"Bash(git branch -a *)",
|
||||||
|
"Bash(git branch -v *)",
|
||||||
|
"Bash(git tag --list *)",
|
||||||
|
"Bash(git remote -v)",
|
||||||
|
"Bash(git fetch *)",
|
||||||
|
"Bash(pulumi about *)",
|
||||||
|
"Bash(pulumi plugin ls *)",
|
||||||
|
"Bash(kubectl api-resources *)",
|
||||||
|
"Bash(kubectl api-versions *)",
|
||||||
|
"Bash(kubectl explain *)",
|
||||||
|
"Bash(kubectl version *)",
|
||||||
|
"Bash(kubectl events *)",
|
||||||
|
"Bash(kubectl cluster-info)",
|
||||||
|
"Bash(kubectl auth can-i *)",
|
||||||
|
"Bash(kubectl rollout status *)",
|
||||||
|
"Bash(kubectl rollout history *)",
|
||||||
|
"Bash(kubectl config current-context *)",
|
||||||
|
"Bash(npm ls *)",
|
||||||
|
"Bash(npm outdated *)",
|
||||||
|
"Bash(ls *)",
|
||||||
|
"Bash(pwd)",
|
||||||
|
"Bash(wc *)",
|
||||||
|
"Bash(which *)",
|
||||||
|
"Bash(jq *)",
|
||||||
"Bash(git add *)",
|
"Bash(git add *)",
|
||||||
"Bash(git switch *)",
|
"Bash(git switch *)",
|
||||||
"Bash(.claude/scripts/gitea.sh GET *)",
|
"Bash(.claude/scripts/gitea.sh GET *)",
|
||||||
|
"Bash(.claude/scripts/gitea.sh WAIT *)",
|
||||||
|
"Bash(.claude/scripts/gitea.sh POST *)",
|
||||||
|
"Bash(git commit *)",
|
||||||
|
"Bash(git push *)",
|
||||||
"WebFetch(domain:www.pulumi.com)",
|
"WebFetch(domain:www.pulumi.com)",
|
||||||
"WebFetch(domain:github.com)",
|
"WebFetch(domain:github.com)",
|
||||||
"WebFetch(domain:raw.githubusercontent.com)",
|
"WebFetch(domain:raw.githubusercontent.com)",
|
||||||
@@ -51,9 +94,7 @@
|
|||||||
"Bash(ssh *)",
|
"Bash(ssh *)",
|
||||||
"Bash(scp *)",
|
"Bash(scp *)",
|
||||||
"Bash(curl *)",
|
"Bash(curl *)",
|
||||||
"Bash(git commit *)",
|
"Bash(.claude/scripts/gitea.sh POST */merge*)",
|
||||||
"Bash(git push *)",
|
|
||||||
"Bash(.claude/scripts/gitea.sh POST *)",
|
|
||||||
"Bash(.claude/scripts/gitea.sh PATCH *)",
|
"Bash(.claude/scripts/gitea.sh PATCH *)",
|
||||||
"Bash(.claude/scripts/gitea.sh PUT *)",
|
"Bash(.claude/scripts/gitea.sh PUT *)",
|
||||||
"Bash(.claude/scripts/gitea.sh DELETE *)"
|
"Bash(.claude/scripts/gitea.sh DELETE *)"
|
||||||
|
|||||||
@@ -0,0 +1,96 @@
|
|||||||
|
---
|
||||||
|
name: merge
|
||||||
|
description: Commit the staged and unstaged changes that fit the branch with meaningful messages, push a branch, open a Gitea PR, wait for CI, and merge it, without stopping for confirmation.
|
||||||
|
argument-hint: [optional note on intent, or paths to limit the merge to]
|
||||||
|
disable-model-invocation: true
|
||||||
|
---
|
||||||
|
|
||||||
|
Take the working tree changes through commit, push, PR and merge in one run. If `$ARGUMENTS` names paths, include only those. If it describes intent, use it for the commit messages and PR.
|
||||||
|
|
||||||
|
Typing `/merge` is the user's explicit instruction to commit, push, open a PR and merge these changes. It satisfies the "commit" and "ask before opening or merging" rules in `CLAUDE.md` for this run. Do not ask for confirmation, and do not pause to show drafts. Stop only for a condition under "Stop conditions".
|
||||||
|
|
||||||
|
## Rules
|
||||||
|
|
||||||
|
- Follow `CONVENTIONS.md` for branch names, commit messages and PR titles.
|
||||||
|
- Add no AI attribution to commits or PRs.
|
||||||
|
- Never use `--no-verify`, force push, or commit directly to `main`.
|
||||||
|
- Use `.claude/scripts/gitea.sh` for PR calls, because `gh` does not work here. `$REPO` below means `/repos/kasun/homelab-infrastructure-as-code`, and must be written out in full in each command.
|
||||||
|
- Never stage `Pulumi.dev.yaml`, `.env` files, keys, credentials, `.claude/settings.local.json`, or anything in `sdks/`. Leave them out, carry on, and mention them in the report.
|
||||||
|
- Write commit messages and JSON bodies to files in the scratchpad directory with the Write tool.
|
||||||
|
- Run each command on its own, in the exact forms below, from the repo root. `cd` prefixes, pipes, loops and redirects cause permission prompts.
|
||||||
|
|
||||||
|
## Stop conditions
|
||||||
|
|
||||||
|
Stop and report only if:
|
||||||
|
|
||||||
|
- HEAD is detached, or a merge or rebase is in progress.
|
||||||
|
- There are no changes and no unpushed commits.
|
||||||
|
- Typecheck or `pulumi preview` fails.
|
||||||
|
- The preview shows a replace or delete of a VM, a PVC, or an imported resource.
|
||||||
|
- A file that looks like a secret is the only change.
|
||||||
|
- A commit hook, push or API call fails after one corrected retry of a message-format error.
|
||||||
|
- CI fails, or the PR is not mergeable.
|
||||||
|
|
||||||
|
Leave the branch and PR in place when stopping after they exist, and say what is needed to continue.
|
||||||
|
|
||||||
|
## 1. Inspect
|
||||||
|
|
||||||
|
1. Run `git status`, `git diff --staged`, `git diff`, and `git log --oneline -5`. Read any untracked files that would be included.
|
||||||
|
2. Run `git fetch origin main`.
|
||||||
|
3. On a non-`main` branch, run `.claude/scripts/gitea.sh GET $REPO/pulls?state=open`. If this branch has an open PR, reuse it only for changes that serve its purpose. If all remaining changes are unrelated to it, take that PR through steps 6 and 7 first, which returns you to `main`, then continue with the remaining changes as new work.
|
||||||
|
|
||||||
|
## 2. Group into commits
|
||||||
|
|
||||||
|
Split by reason for the change, and decide without asking. Each commit should make sense and be revertable alone.
|
||||||
|
|
||||||
|
- First decide the PR's purpose from `$ARGUMENTS`, the conversation, the branch name, or else the largest change.
|
||||||
|
- On the first `/merge`, leave out any change that does not serve that purpose, such as an unrelated `.claude/settings.json` edit. Keep it uncommitted and untouched, do not ask, and list it in the report.
|
||||||
|
- On a repeat `/merge`, meaning an earlier run this session left changes out or its PR is still open, handle all remaining changes in this run. Give each separate purpose its own branch and PR, and take them one at a time through steps 3 to 7, so each is merged and you are back on `main` before the next starts. If `$ARGUMENTS` names paths, handle only those.
|
||||||
|
- Use one commit when the remaining changes serve one purpose, and several when they are distinct steps toward it.
|
||||||
|
- Group whole files. If one file mixes purposes, put it in the commit for its main change.
|
||||||
|
- Scope is the stack (`01-proxmox-infra/` is `proxmox-infra`), or `ci` for `.gitea/workflows/`. Omit the scope for repo-wide or `.claude/` changes.
|
||||||
|
- Add a body only when the diff shows a reason that is not obvious. Never invent a reason.
|
||||||
|
|
||||||
|
## 3. Verify
|
||||||
|
|
||||||
|
For each stack with changed code, run:
|
||||||
|
|
||||||
|
- `npm run typecheck --prefix <stack-dir>`
|
||||||
|
- `pulumi preview --cwd <stack-dir> --stack dev`
|
||||||
|
|
||||||
|
## 4. Commit and push
|
||||||
|
|
||||||
|
1. If on `main`, run `git switch -c <type>/<short-kebab-description>`. This carries the changes across.
|
||||||
|
2. For each commit, run `git add -- <paths>`, then `git commit -F <message file> -- <paths>`. Naming the paths commits only those files, whatever else is staged.
|
||||||
|
3. Run `git status` to confirm only intentionally excluded files remain.
|
||||||
|
4. Run `git push -u origin <branch>`.
|
||||||
|
|
||||||
|
## 5. Open the PR
|
||||||
|
|
||||||
|
Unless one exists, run `.claude/scripts/gitea.sh POST $REPO/pulls @<json file>` with `title`, `body`, `head` and `base: "main"`. The body says what changed, why, and the preview result for each stack.
|
||||||
|
|
||||||
|
## 6. Wait for CI
|
||||||
|
|
||||||
|
Get the SHA with `git rev-parse HEAD`, then run `.claude/scripts/gitea.sh WAIT $REPO/commits/<sha>/status` as a background command. Do not write a polling loop, because that causes a permission prompt.
|
||||||
|
|
||||||
|
- Exit 0: checks passed, or it printed `no CI ran` because workflows are path-filtered. Continue.
|
||||||
|
- Exit 1: stop, and report the failing check and its `target_url`.
|
||||||
|
- Exit 3: CI timed out. Stop and report it.
|
||||||
|
|
||||||
|
Then run `.claude/scripts/gitea.sh GET $REPO/pulls/<number>` and confirm `mergeable` is true.
|
||||||
|
|
||||||
|
## 7. Merge
|
||||||
|
|
||||||
|
1. Run `.claude/scripts/gitea.sh POST $REPO/pulls/<number>/merge @<json file>` with `{"Do":"merge","head_commit_id":"<sha>"}`, so only the commit CI checked can merge.
|
||||||
|
2. Run `git fetch origin main:main`, then `git switch main`.
|
||||||
|
|
||||||
|
## 8. Report
|
||||||
|
|
||||||
|
Keep it short:
|
||||||
|
|
||||||
|
- PR link and commits.
|
||||||
|
- What the merge deploys, from the `on.push.paths` in `.gitea/workflows/`. `03`, `04` and `05` deploy on merge, and a change under `.gitea/workflows/` can deploy all three.
|
||||||
|
- For `01` or `02` changes, say that they are not live until someone runs the manual workflow.
|
||||||
|
- Anything left uncommitted, and a reminder to update `<STACK>_PULUMI_DEV_YAML` if local Pulumi config changed.
|
||||||
|
|
||||||
|
Do not delete the branch, dispatch a workflow, or change a live system.
|
||||||
@@ -3,6 +3,13 @@ name: Deploy Proxmox Infra
|
|||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
paths:
|
||||||
|
- "01-proxmox-infra/**"
|
||||||
|
- ".gitea/workflows/01-deploy-proxmox-infra.yaml"
|
||||||
|
|
||||||
pull_request:
|
pull_request:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
@@ -51,7 +58,7 @@ jobs:
|
|||||||
deploy:
|
deploy:
|
||||||
name: Pulumi Deploy
|
name: Pulumi Deploy
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
if: github.event_name == 'workflow_dispatch'
|
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Code
|
- name: Checkout Code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
@@ -75,7 +82,10 @@ jobs:
|
|||||||
run: pulumi package add terraform-provider marshallford/pfsense 0.22.0
|
run: pulumi package add terraform-provider marshallford/pfsense 0.22.0
|
||||||
working-directory: 01-proxmox-infra
|
working-directory: 01-proxmox-infra
|
||||||
|
|
||||||
|
# Manual runs only: a refresh that finds a VM missing drops it from state,
|
||||||
|
# and `up` would then create a blank replacement without review.
|
||||||
- name: Refresh State
|
- name: Refresh State
|
||||||
|
if: github.event_name == 'workflow_dispatch'
|
||||||
run: |
|
run: |
|
||||||
pulumi login "$PULUMI_BACKEND_URL"
|
pulumi login "$PULUMI_BACKEND_URL"
|
||||||
pulumi refresh --yes --stack dev \
|
pulumi refresh --yes --stack dev \
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ const worker1Ip = config.requireSecret("worker1Ip");
|
|||||||
const worker2Ip = config.requireSecret("worker2Ip");
|
const worker2Ip = config.requireSecret("worker2Ip");
|
||||||
const worker3Ip = config.requireSecret("worker3Ip");
|
const worker3Ip = config.requireSecret("worker3Ip");
|
||||||
|
|
||||||
|
const ansibleIp = config.requireSecret("ansibleIp");
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// VM templates — one per node, cloned from the downloaded cloud image.
|
// VM templates — one per node, cloned from the downloaded cloud image.
|
||||||
// Templates are not started and have no cloud-init config; that is applied
|
// Templates are not started and have no cloud-init config; that is applied
|
||||||
@@ -33,7 +35,9 @@ const worker3Ip = config.requireSecret("worker3Ip");
|
|||||||
|
|
||||||
const templateSettings = {
|
const templateSettings = {
|
||||||
template: true,
|
template: true,
|
||||||
|
protection: true,
|
||||||
started: false,
|
started: false,
|
||||||
|
operatingSystem: { type: "l26" },
|
||||||
stopOnDestroy: true,
|
stopOnDestroy: true,
|
||||||
scsiHardware: "virtio-scsi-pci",
|
scsiHardware: "virtio-scsi-pci",
|
||||||
cdrom: { fileId: "none" },
|
cdrom: { fileId: "none" },
|
||||||
@@ -137,7 +141,7 @@ const pveNodes = pveNodeSeeds
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{ provider: n.provider, ignoreChanges: ["disks"] },
|
{ provider: n.provider, protect: true, ignoreChanges: ["disks"] },
|
||||||
),
|
),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@@ -287,12 +291,20 @@ const k3sVms = nodeConfigs.map(
|
|||||||
agent: { enabled: true, timeout: "30s" },
|
agent: { enabled: true, timeout: "30s" },
|
||||||
cdrom: { fileId: "none" },
|
cdrom: { fileId: "none" },
|
||||||
started: false,
|
started: false,
|
||||||
stopOnDestroy: true,
|
rebootAfterUpdate: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
provider: node.host.provider,
|
provider: node.host.provider,
|
||||||
retainOnDelete: true,
|
retainOnDelete: true,
|
||||||
ignoreChanges: ["clone", "started"],
|
protect: true,
|
||||||
|
ignoreChanges: [
|
||||||
|
"clone",
|
||||||
|
"started",
|
||||||
|
// Pulumi bridge bug: unset disk speed always shows a diff.
|
||||||
|
// https://github.com/muhlba91/pulumi-proxmoxve/issues/664
|
||||||
|
"disks[0].speed",
|
||||||
|
...(node.longhornDiskSize == null ? [] : ["disks[1].speed"]),
|
||||||
|
],
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -310,10 +322,84 @@ k3sVms.forEach((vmResource, i) => {
|
|||||||
ipAddress: nodeConfigs[i].ip,
|
ipAddress: nodeConfigs[i].ip,
|
||||||
hostname: nodeConfigs[i].name,
|
hostname: nodeConfigs[i].name,
|
||||||
},
|
},
|
||||||
{ dependsOn: vmResource, provider: pfSenseProvider },
|
{ dependsOn: vmResource, provider: pfSenseProvider, protect: true },
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Ansible control node — unprivileged LXC with a pfSense DHCP reservation.
|
||||||
|
// The MAC is fixed so the reservation can exist before the container's first
|
||||||
|
// boot; otherwise its first DHCP lease could come from the dynamic pool.
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
const ansibleHost = hostFor("pve-b550");
|
||||||
|
const ansibleMac = "02:A5:1B:00:01:54";
|
||||||
|
|
||||||
|
const ansibleTemplate = new proxmox.download.File(
|
||||||
|
"ubuntu-resolute-lxc-pve-b550",
|
||||||
|
{
|
||||||
|
nodeName: ansibleHost.nodeName,
|
||||||
|
datastoreId: ansibleHost.isoStore,
|
||||||
|
contentType: "vztmpl",
|
||||||
|
fileName: "ubuntu-26.04-standard_26.04-1_amd64.tar.zst",
|
||||||
|
url: "https://download.proxmox.com/images/system/ubuntu-26.04-standard_26.04-1_amd64.tar.zst",
|
||||||
|
overwrite: false,
|
||||||
|
overwriteUnmanaged: true,
|
||||||
|
},
|
||||||
|
{ provider: ansibleHost.provider },
|
||||||
|
);
|
||||||
|
|
||||||
|
const ansibleDhcp = new pfsense.Dhcpv4Staticmapping(
|
||||||
|
"ansible-dhcp",
|
||||||
|
{
|
||||||
|
interface: "lan",
|
||||||
|
macAddress: ansibleMac,
|
||||||
|
ipAddress: ansibleIp,
|
||||||
|
hostname: "ansible",
|
||||||
|
},
|
||||||
|
{ provider: pfSenseProvider, protect: true },
|
||||||
|
);
|
||||||
|
|
||||||
|
new proxmox.ContainerLegacy( // NOSONAR typescript:S1848
|
||||||
|
"ansible",
|
||||||
|
{
|
||||||
|
nodeName: ansibleHost.nodeName,
|
||||||
|
description: "Ansible control node — managed by Pulumi",
|
||||||
|
tags: ["ansible"],
|
||||||
|
unprivileged: true,
|
||||||
|
features: { nesting: true },
|
||||||
|
operatingSystem: {
|
||||||
|
templateFileId: ansibleTemplate.id,
|
||||||
|
type: "ubuntu",
|
||||||
|
},
|
||||||
|
cpu: { cores: 1 },
|
||||||
|
memory: { dedicated: 1024, swap: 0 },
|
||||||
|
disk: { datastoreId: ansibleHost.dataStore, size: 8 },
|
||||||
|
networkInterfaces: [
|
||||||
|
{ name: "eth0", bridge: "vmbr0", macAddress: ansibleMac },
|
||||||
|
],
|
||||||
|
initialization: {
|
||||||
|
hostname: "ansible",
|
||||||
|
ipConfigs: [{ ipv4: { address: "dhcp" } }],
|
||||||
|
userAccount: {
|
||||||
|
keys: [
|
||||||
|
pve1SshPublicKey.apply((k) => k.trim()),
|
||||||
|
pve2SshPublicKey.apply((k) => k.trim()),
|
||||||
|
pve3SshPublicKey.apply((k) => k.trim()),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
started: true,
|
||||||
|
startOnBoot: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
provider: ansibleHost.provider,
|
||||||
|
dependsOn: ansibleDhcp,
|
||||||
|
retainOnDelete: true,
|
||||||
|
protect: true,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
export const vmIds = {
|
export const vmIds = {
|
||||||
master1: k3sVms[0].vmId,
|
master1: k3sVms[0].vmId,
|
||||||
master2: k3sVms[1].vmId,
|
master2: k3sVms[1].vmId,
|
||||||
|
|||||||
@@ -3,6 +3,20 @@ import * as command from "@pulumi/command";
|
|||||||
|
|
||||||
const config = new pulumi.Config();
|
const config = new pulumi.Config();
|
||||||
|
|
||||||
|
// Bootstrap commands run once, on a fresh install. Without this, a changed VM
|
||||||
|
// ID or command would re-run the k3s installer on the live cluster. After
|
||||||
|
// recreating a VM, re-run its commands explicitly with --target-replace.
|
||||||
|
pulumi.runtime.registerResourceTransform((args) =>
|
||||||
|
args.type.startsWith("command:")
|
||||||
|
? {
|
||||||
|
props: args.props,
|
||||||
|
opts: pulumi.mergeOptions(args.opts, {
|
||||||
|
ignoreChanges: ["create", "triggers"],
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
: undefined,
|
||||||
|
);
|
||||||
|
|
||||||
const infraRef = new pulumi.StackReference(
|
const infraRef = new pulumi.StackReference(
|
||||||
`${pulumi.getOrganization()}/proxmox-infra/dev`,
|
`${pulumi.getOrganization()}/proxmox-infra/dev`,
|
||||||
);
|
);
|
||||||
@@ -77,7 +91,7 @@ const startMaster1 = new command.local.Command("start-master-1", {
|
|||||||
interpreter: ["/bin/bash", "-c"],
|
interpreter: ["/bin/bash", "-c"],
|
||||||
});
|
});
|
||||||
const startMaster2 = new command.local.Command("start-master-2", {
|
const startMaster2 = new command.local.Command("start-master-2", {
|
||||||
create: pulumi.interpolate`curl -sf -k -X POST -H "Authorization: PVEAPIToken=${pve1ApiToken}" "${pve1Endpoint}/api2/json/nodes/pve/qemu/${master2VmId}/status/start" 2>/dev/null || true`,
|
create: pulumi.interpolate`curl -sf -k -X POST -H "Authorization: PVEAPIToken=${pve3ApiToken}" "${pve3Endpoint}/api2/json/nodes/pve/qemu/${master2VmId}/status/start" 2>/dev/null || true`,
|
||||||
triggers: [master2VmId],
|
triggers: [master2VmId],
|
||||||
interpreter: ["/bin/bash", "-c"],
|
interpreter: ["/bin/bash", "-c"],
|
||||||
});
|
});
|
||||||
|
|||||||
+116
-1
@@ -19,6 +19,10 @@ const letsencryptEmail = config.requireSecret("letsencryptEmail");
|
|||||||
const kubeVipAddress = config.requireSecret("kubeVipAddress");
|
const kubeVipAddress = config.requireSecret("kubeVipAddress");
|
||||||
const kubeVipInterface = config.require("kubeVipInterface");
|
const kubeVipInterface = config.require("kubeVipInterface");
|
||||||
|
|
||||||
|
const domain = config.requireSecret("domain");
|
||||||
|
const longhornUiUser = config.requireSecret("longhornUiUser");
|
||||||
|
const longhornUiPassword = config.requireSecret("longhornUiPassword");
|
||||||
|
|
||||||
const k8sProvider = new k8s.Provider("k3s", { kubeconfig });
|
const k8sProvider = new k8s.Provider("k3s", { kubeconfig });
|
||||||
const opts = (extras?: pulumi.ResourceOptions): pulumi.ResourceOptions => ({
|
const opts = (extras?: pulumi.ResourceOptions): pulumi.ResourceOptions => ({
|
||||||
provider: k8sProvider,
|
provider: k8sProvider,
|
||||||
@@ -69,6 +73,7 @@ const certManager = new k8s.helm.v3.Release(
|
|||||||
{
|
{
|
||||||
name: "cert-manager",
|
name: "cert-manager",
|
||||||
chart: "cert-manager",
|
chart: "cert-manager",
|
||||||
|
version: "v1.21.1",
|
||||||
repositoryOpts: { repo: "https://charts.jetstack.io" },
|
repositoryOpts: { repo: "https://charts.jetstack.io" },
|
||||||
namespace: "cert-manager",
|
namespace: "cert-manager",
|
||||||
createNamespace: true,
|
createNamespace: true,
|
||||||
@@ -133,15 +138,61 @@ const longhorn = new k8s.helm.v3.Release(
|
|||||||
version: "1.12.0",
|
version: "1.12.0",
|
||||||
values: {
|
values: {
|
||||||
defaultSettings: {
|
defaultSettings: {
|
||||||
defaultReplicaCount: 2,
|
defaultReplicaCount: 3,
|
||||||
nodeDownPodDeletionPolicy: "delete-both-statefulset-and-deployment-pod",
|
nodeDownPodDeletionPolicy: "delete-both-statefulset-and-deployment-pod",
|
||||||
createDefaultDiskLabeledNodes: true,
|
createDefaultDiskLabeledNodes: true,
|
||||||
|
orphanResourceAutoDeletion: "replica-data;instance",
|
||||||
|
// Longhorn's recommendation for dedicated disks (longhorn-extra).
|
||||||
|
// Docs: https://longhorn.io/docs/1.12.0/best-practices/
|
||||||
|
storageMinimalAvailablePercentage: 10,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
opts(),
|
opts(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Purges system snapshots, which can otherwise grow to a full volume's size
|
||||||
|
// on every replica. Docs:
|
||||||
|
// https://longhorn.io/docs/1.12.0/snapshots-and-backups/scheduling-backups-and-snapshots/
|
||||||
|
new k8s.apiextensions.CustomResource(
|
||||||
|
"longhorn-snapshot-cleanup",
|
||||||
|
{
|
||||||
|
apiVersion: "longhorn.io/v1beta2",
|
||||||
|
kind: "RecurringJob",
|
||||||
|
metadata: { name: "snapshot-cleanup", namespace: "longhorn-system" },
|
||||||
|
spec: {
|
||||||
|
name: "snapshot-cleanup",
|
||||||
|
task: "snapshot-cleanup",
|
||||||
|
cron: "30 3 * * *",
|
||||||
|
groups: ["default"],
|
||||||
|
retain: 0,
|
||||||
|
concurrency: 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
opts({ dependsOn: [longhorn] }),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Returns blocks deleted inside a volume (e.g. expired Prometheus data) to the
|
||||||
|
// disk. Runs after snapshot-cleanup, since trim can't reclaim valid snapshots.
|
||||||
|
// Docs: https://longhorn.io/docs/1.12.0/nodes-and-volumes/volumes/trim-filesystem/
|
||||||
|
new k8s.apiextensions.CustomResource(
|
||||||
|
"longhorn-filesystem-trim",
|
||||||
|
{
|
||||||
|
apiVersion: "longhorn.io/v1beta2",
|
||||||
|
kind: "RecurringJob",
|
||||||
|
metadata: { name: "filesystem-trim", namespace: "longhorn-system" },
|
||||||
|
spec: {
|
||||||
|
name: "filesystem-trim",
|
||||||
|
task: "filesystem-trim",
|
||||||
|
cron: "30 4 * * *",
|
||||||
|
groups: ["default"],
|
||||||
|
retain: 0,
|
||||||
|
concurrency: 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
opts({ dependsOn: [longhorn] }),
|
||||||
|
);
|
||||||
|
|
||||||
// Patches Longhorn instances to use the mountend Longhorn storage on the worker nodes.
|
// Patches Longhorn instances to use the mountend Longhorn storage on the worker nodes.
|
||||||
["k3s-worker-1", "k3s-worker-2", "k3s-worker-3"].forEach(
|
["k3s-worker-1", "k3s-worker-2", "k3s-worker-3"].forEach(
|
||||||
(nodeName) =>
|
(nodeName) =>
|
||||||
@@ -173,6 +224,70 @@ const longhorn = new k8s.helm.v3.Release(
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// ── Longhorn UI ───────────────────────────────────────────────────────────
|
||||||
|
// Docs: https://longhorn.io/docs/1.12.0/deploy/accessing-the-ui/longhorn-ingress-traefik/
|
||||||
|
// https://doc.traefik.io/traefik/reference/routing-configuration/http/middlewares/basicauth/
|
||||||
|
|
||||||
|
const longhornUiAuthSecret = new k8s.core.v1.Secret(
|
||||||
|
"longhorn-ui-basic-auth",
|
||||||
|
{
|
||||||
|
metadata: { name: "longhorn-ui-basic-auth", namespace: "longhorn-system" },
|
||||||
|
type: "kubernetes.io/basic-auth",
|
||||||
|
stringData: { username: longhornUiUser, password: longhornUiPassword },
|
||||||
|
},
|
||||||
|
opts({ dependsOn: [longhorn] }),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Fixed name: the Ingress references it as <namespace>-<name>@kubernetescrd.
|
||||||
|
const longhornUiAuth = new k8s.apiextensions.CustomResource(
|
||||||
|
"longhorn-ui-auth",
|
||||||
|
{
|
||||||
|
apiVersion: "traefik.io/v1alpha1",
|
||||||
|
kind: "Middleware",
|
||||||
|
metadata: { name: "longhorn-ui-auth", namespace: "longhorn-system" },
|
||||||
|
spec: { basicAuth: { secret: longhornUiAuthSecret.metadata.name } },
|
||||||
|
},
|
||||||
|
opts(),
|
||||||
|
);
|
||||||
|
|
||||||
|
const longhornUiHost = pulumi.interpolate`longhorn.${domain}`;
|
||||||
|
|
||||||
|
new k8s.networking.v1.Ingress(
|
||||||
|
"longhorn-ui",
|
||||||
|
{
|
||||||
|
metadata: {
|
||||||
|
name: "longhorn-ui",
|
||||||
|
namespace: "longhorn-system",
|
||||||
|
annotations: {
|
||||||
|
"cert-manager.io/cluster-issuer": "letsencrypt-prod",
|
||||||
|
"traefik.ingress.kubernetes.io/router.middlewares":
|
||||||
|
"longhorn-system-longhorn-ui-auth@kubernetescrd",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
spec: {
|
||||||
|
ingressClassName: "traefik",
|
||||||
|
tls: [{ hosts: [longhornUiHost], secretName: "longhorn-ui-tls" }],
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
host: longhornUiHost,
|
||||||
|
http: {
|
||||||
|
paths: [
|
||||||
|
{
|
||||||
|
path: "/",
|
||||||
|
pathType: "Prefix",
|
||||||
|
backend: {
|
||||||
|
service: { name: "longhorn-frontend", port: { number: 80 } },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
opts({ dependsOn: [longhorn, longhornUiAuth] }),
|
||||||
|
);
|
||||||
|
|
||||||
// ── kube-vip ────────────
|
// ── kube-vip ────────────
|
||||||
|
|
||||||
const kubeVipNamespace = "kube-system";
|
const kubeVipNamespace = "kube-system";
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ new k8s.apps.v1.Deployment(
|
|||||||
},
|
},
|
||||||
spec: {
|
spec: {
|
||||||
replicas: 1,
|
replicas: 1,
|
||||||
|
strategy: { type: "Recreate" },
|
||||||
selector: { matchLabels: labels },
|
selector: { matchLabels: labels },
|
||||||
template: {
|
template: {
|
||||||
metadata: { labels },
|
metadata: { labels },
|
||||||
@@ -70,6 +71,20 @@ new k8s.apps.v1.Deployment(
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
terminationGracePeriodSeconds: 5,
|
terminationGracePeriodSeconds: 5,
|
||||||
|
tolerations: [
|
||||||
|
{
|
||||||
|
key: "node.kubernetes.io/unreachable",
|
||||||
|
operator: "Exists",
|
||||||
|
effect: "NoExecute",
|
||||||
|
tolerationSeconds: 30,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "node.kubernetes.io/not-ready",
|
||||||
|
operator: "Exists",
|
||||||
|
effect: "NoExecute",
|
||||||
|
tolerationSeconds: 30,
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in new issue
Block a user