Choosing the API group¶
The NarwhalFleet resource is served as version v1alpha1 of the API group narwhal-inference.com, a domain the project holds. This page is for a maintainer who changes the group, and for an operator whose cluster holds fleets of the earlier group narwhal.example.com.
Why the group needs a domain¶
Kubernetes tells custom resources apart by group and resource name, and a cluster holds one CRD of each name, <plural>.<group>. Only DNS ownership keeps two projects from picking the same group. RFC 2606 reserves example.com, so any project may use a name under it and none can claim one. Two projects could then collide on the CRD name, the label and annotation keys, and the RBAC rules and admission policy that the chart writes for the group.
What to register¶
Kubernetes never resolves the group. The API server compares it as a string, so the name needs no DNS record, web server or certificate. It only has to sit under a domain the project holds, for as long as the API exists. Any one of these works:
- A domain registered for the project.
- A subdomain of a domain the maintainer already owns.
- A subdomain of
<account>.github.io, which GitHub assigns to an account. It costs nothing, but it changes if the account is renamed.
Choose the group itself by these rules:
- Under a domain that holds more than the project, use a subdomain for the API,
<product>.<domain>, such asnarwhal.<domain>. A domain registered for the project alone can be the group itself. The API server refuses a group without a dot (CRD validation). - Write it in lower case letters, digits,
-and., as a DNS subdomain of at most 253 characters with labels of at most 63. - Keep it short. It prefixes every label and annotation key, and operators type it in
kubectlcommands. - Stay out of
k8s.ioandkubernetes.io. The API server refuses a CRD in those groups unless it carries theapi-approved.kubernetes.ioannotation, which is for Kubernetes projects. - Keep it for the life of the API, through
v1beta1andv1. A cluster cannot move to another group in place, as Moving a cluster to the new group shows.
What derives from the group¶
Every Kubernetes name that Narwhal defines derives from the group:
- the CRD
narwhalfleets.<group>and the apiVersion<group>/v1alpha1 - each label and annotation key, such as
<group>/gateon a gate Job,<group>/placementas the engine pods' scheduling gate, and<group>/requested-aton the fleet - the annotations
<group>/held-enginesand<group>/released-byon the routers' Lease - the controller's Lease
controller.<group>and the stage conditionsstage.<group>/<stage> - the chart's RBAC rules, the ClusterRole's grant on the CRD by name, the admission policy's annotation and label checks, and the PodMonitor's relabelling of the attestation port annotation
The fleet has no finalizer. One added later takes the name <group>/<name>. The API server warns about a finalizer name without a / (custom resource validation).
Changing the group in this repository¶
API_GROUP in src/narwhal/contracts.py is the one definition. deployment/fleet_resource.py, the engine pod launch and the routers' Lease derive their names from it, and the chart reads it from generated templates. tests/deployment/test_api_group.py fails while any code, test or chart file writes the group itself.
- Set
API_GROUPto the new group, and update its comment. Rewrite the opening of this page, and the group paragraph of the NarwhalFleet reference, whichtest_the_page_states_the_group_and_that_the_version_will_changeintests/maintenance/test_fleet_reference_doc.pyreads. -
Regenerate the files that hold the group:
-
Replace the group where a page or example file states it for a reader to type. Escape each
.of the old group in the expression:git grep -l -F '<old group>' -- docs README.md CONTRIBUTING.md config deploy \ | xargs sed -i 's/<old group>/<new group>/g'test_api_groupfails on a page line that still states the old group. -
Run the checks:
The change breaks every installed fleet. Give the PR title a !, and put the steps of the next section in the release notes.
Moving a cluster to the new group¶
No release shipped the controller or its CRD under narwhal.example.com. Only a cluster installed from a development build holds fleets of that group, and it moves by these steps.
The API server cannot change a CRD's group in place. The group is part of the CRD's name, and an object's name never changes. A release with the new group therefore installs a second CRD beside the old one. Its controller reconciles only fleets of the new group. A fleet in the new group is a new object with a new uid, so it starts a new run directory and runs every stage again. The fleet serves nothing from the moment its old copy stops until router-start passes again.
The old CRD serves the namespaces still on the old release, so you can move one namespace at a time. In each namespace:
-
Keep the fleet file you applied, from your GitOps repository or the workstation. Without one, save the live fleet:
Then remove its
status, the server's metadata fields (uid,resourceVersion,generation,creationTimestampandmanagedFields) and its annotations under the old group. -
While the old release still runs, stop the fleet and delete it. Its controller stops the routers, HAProxy, the engines and the Jobs in order, then sets
Stopped:kubectl patch narwhalfleets.<old group> fleet --namespace <namespace> \ --type merge -p '{"spec":{"stopped":true}}' kubectl wait narwhalfleets.<old group>/fleet --namespace <namespace> \ --for=condition=Stopped --timeout=30m kubectl delete narwhalfleets.<old group> fleet --namespace <namespace>For a fleet that Helm or a GitOps tool owns, set
spec.stoppedand remove the fleet there. The garbage collector deletes what the fleet owned, including the Secrets the controller generated. The state claim keeps the old run directory. -
Delete the old controller's Lease,
controller.<old group>, which has no owner. Delete the routers' Leasenarwhal-routertoo, so that no annotation under the old group stays on it. The upgrade makes it again: -
Apply the new release's CRD, then upgrade the release, as in Upgrading the chart and its CRD. The upgrade replaces the controller, its RBAC and the admission policy with ones for the new group. From then on nothing in the namespace reconciles a fleet of the old group.
- Set
apiVersionin the fleet file to<new group>/v1alpha1, leave outspec.stopped, and apply the file as before. A workstation needs a new--rundirectory, because the old one names the old fleet's uid.
Roles that you wrote yourself and that name the old group need the new one. The chart's own Roles change with the upgrade.
Once no namespace holds a fleet of the old group, delete the old CRD. Deleting a CRD deletes every object of it, so check that the list is empty first: