Skip to content

api/profiles: Change a profile in place - #142

Merged
l-nmch merged 3 commits into
mainfrom
feat/edit-profile
Nov 14, 2026
Merged

l-nmch merged 3 commits into
mainfrom
feat/edit-profile

Conversation

@l-nmch

@l-nmch l-nmch commented Nov 14, 2026

Copy link
Copy Markdown
Member

What

PATCH /v1/tenants/{t}/profiles/{name} changes a profile a user made, in place (the Profile kind and its composition already allow it): description, cpu, memoryMiB, diskGiB, secureBoot and sshPublicKeys, with the bounds and the checks of the creation. What the body leaves out is left alone; s, m and l are 403, an unknown profile 404, an empty body 422. The instances that have the profile follow the change, the ones that say their own value do not (phorge-fr/Hangar#434).

  • description: "" goes back to the one made from the size, secureBoot: null removes the setting (so a profile that said true or false can go back to saying nothing), sshPublicKeys: [] removes the keys. These three are removed from the object rather than written empty. A small Setting[T] type tells an absent field from a null, which a pointer cannot.
  • A change never starts, stops or restarts an instance.
  • Allowed to operator and profiles:write, as the creation. The API's service account already has patch on profiles.

What Incus does, measured

On a throwaway tenant (apitest-135-*, removed afterwards, Incus projects back to what they were), a profile used by a running VM, patched on the Profile object:

Change Incus Guest
memory 1024 to 2048 MiB applied in 12 s 1858 MiB seen at once
memory 2048 to 1024, and to 512 (below the boot value) accepted 816, then 304 MiB
disk 12 to 14 GiB applied still 12 G (14 G after a restart is not measured)
cpu 1 to 2 applied nproc stays 1
cpu 2 to 1 (below the boot value) accepted nproc 1
cpu 2 to 4 with a tenant limit of 2 vCPU refused, Reached maximum aggregate value "2" for "limits.cpu" unchanged; the Profile stays Ready=False with the raw error until put back
disk 14 to 12 GiB, below the real disk profile saved, the instance fails: Block volumes cannot be shrunk unchanged (profile and VM now differ)

So three things are refused by the API with a 409 and a sentence, before anything is sent:

  • a smaller disk while an instance has the profile, whatever its state (in_use, names the instances; make another profile and create the instances again with it);
  • less memory while an instance that has the profile is running (running; stop it, change the profile, start it again), the rule of an instance (Refuse to lower the memory of a running VM, and say what to do #119);
  • a size that takes the tenant over its limits (quota_exceeded): every instance that has the profile counts what it comes to, so the bigger profile is checked against the 2 vCPU, 4 GiB and 128 GiB. Only what the change raises is checked.

Open point. The memory refusal is not what this measurement shows: Incus accepted lowering the memory of a running VM through a profile, even below its boot value, where #119 measured failed to resize memfd on an instance. I keep the rule of the instance (one rule for the memory of a running VM, whatever the path; a wrong refusal costs a stop, a wrong acceptance leaves an Instance in error) and say it here so it can be relaxed. Not measured: a disk lowered on a stopped VM (refused the same, conservatively).

Tests

  • internal/compute: Setting tells absent, null and a value; the validation of a patch.
  • internal/kube: the merge patch writes only what was given and removes an emptied description, a null secure boot and an empty list of keys.
  • internal/api: what is changed and what is not, the settings, every refusal (profiles every tenant has, unknown, invalid, unknown field), the three 409 with the instances named, the limits of the tenant for one and for several instances, who may (roles and key scopes).
  • gofmt -l, go vet ./..., go test -race ./..., yamllint --strict on the OpenAPI and the docs check pass locally. golangci-lint is not installed locally, CI runs it.
  • Live: the measurement above. The route itself is not run against the cluster.

The console side is phorge-fr/phorge-console#82.

Closes #135

PATCH /v1/tenants/{t}/profiles/{name} changes the description, the CPU, the memory, the root disk, the secure boot and the SSH keys of a
profile a user made, with the checks of the creation. What is absent is left alone; s, m and l are refused.

What Incus cannot do in place is refused with a 409 and what to do, before anything is sent: a smaller disk while an instance has the
profile, less memory while an instance that has it is running, and a size that takes the tenant over its limits. A change never starts,
stops or restarts an instance.

Closes #135
@l-nmch l-nmch added this to the 2027-Q1 milestone Nov 14, 2026
@l-nmch l-nmch added the area/api Phorge API and console label Nov 14, 2026
@l-nmch l-nmch self-assigned this Nov 14, 2026
@l-nmch l-nmch added this to Roadmap Nov 14, 2026
@l-nmch
l-nmch merged commit 805df77 into main Nov 14, 2026
11 checks passed
@l-nmch
l-nmch deleted the feat/edit-profile branch November 14, 2026 17:21
@l-nmch l-nmch mentioned this pull request Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/api Phorge API and console

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Edit a profile in the API

1 participant