Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ metadata:
name: fleet.datumapis.com-boot-address-requester
annotations:
kubernetes.io/display-name: Fleet Boot Address Requester
kubernetes.io/description: The Fleet provider for Metal and the release controller at a site whose DHCP Fleet synchronizes. Claims and releases the boot address of each installation and wipe.
kubernetes.io/description: The Fleet provider for Metal and the release controller at a site whose DHCP Fleet synchronizes. Claims and releases the boot address of each installation and wipe, and reads IPAM's allocations to confirm a release.
spec:
launchStage: Alpha
includedPermissions:
- ipam.miloapis.com/ipclaims.create
- ipam.miloapis.com/ipclaims.get
- ipam.miloapis.com/ipclaims.list
- ipam.miloapis.com/ipclaims.delete
- ipam.miloapis.com/ipallocations.get
- ipam.miloapis.com/ipallocations.list
33 changes: 32 additions & 1 deletion docs/operations/boot-network.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,43 @@ between the claim and the operation still finds it.
The IPAM permissions are in their own roles, in
`config/components/boot-addresses`, which no overlay includes. The
`boot-address-requester` role grants `create`, `get`, `list` and `delete` on
`ipclaims`, and the `boot-address-checker` role grants `get`. An environment
`ipclaims` and `get` and `list` on `ipallocations`, and the `boot-address-checker` role grants `get`. An environment
that enables boot addresses includes that component and binds the requester
role to the installation and wipe requesters and the checker role to the
coordinator. The device operations roles every environment applies grant no
IPAM permission.

### IPAM's claim contract

Fleet follows the contract IPAM implements, not only its documentation:

- IPAM binds a claim, or refuses it, in the create response. A second create
under the same name is a `409 Conflict` with a `ClaimExists` cause, so the
requester reads the existing claim instead.
- A full pool is a `507` with an `Exhausted` cause and, when one pool ran out,
its name. The requester reports `IPAM has no free provisioning address` and
creates no operation. A `400` refusal, such as an unknown class, is reported
as `IPAM refused the boot address claim` with IPAM's message, and also
creates no operation. Neither leaves a claim.
- IPAM rewrites the claim's class and family to the resolved class, keeps its
labels, and stamps its owner as the provider project. Fleet reads only the
labels and the bound address.
- Fleet uses a claim only if IPAM stored it with reclaim policy `Delete`,
which overrides the class's. A retaining claim, or a `409` such as
`AllocationRetained`, is refused: its address would outlive the claim.
- A delete releases the address and removes the claim and its allocation in
one transaction. IPAM ignores delete preconditions, so the claim's name and
labels are the guard. A release counts only when a read finds the claim gone
and no `IPAllocation` names it; because the claim deletes its allocation, a
claim found gone after a lost delete response was released. A failed delete
leaves the claim and its address held until a later call.
- A claim read at admission that fails for any reason but its absence leaves
the operation `Pending` with `BootAddressUnavailable`, never admitted, and
the coordinator checks it again. This holds for every creator: a staff
operation waits the same way and is cancelled only by staff expiry, so a
brief IPAM outage fails no installation or wipe. A missing, rebound or
recreated claim fails the operation.

## Enrollment

The site enrollment (`FLEET_REDFISH_ENROLLMENT`) is the explicit mapping of the
Expand Down
10 changes: 6 additions & 4 deletions hack/multiplane/milo.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,12 @@ def wait(fn,seconds,what):
rules+=[{'apiGroups':['metal.datumapis.com'],'resources':['machineallocations'],'verbs':['get','list','watch','create','delete']},{'apiGroups':['metal.datumapis.com'],'resources':['machineallocations/status'],'verbs':['get','update']},
{'apiGroups':['fleet.datumapis.com'],'resources':['deviceinstallations'],'verbs':['get','list','watch','create']},
{'apiGroups':['fleet.datumapis.com'],'resources':['devices','devicecustodies','devicecommissionings','devicecommissioningplans','devicecommissioningplanapprovals'],'verbs':['get','list','watch']}]
# Each requester claims and releases its own boot addresses; the release
# controller reads custody to keep a held operation's claim.
# Each requester claims and releases its own boot addresses, and reads
# allocations to confirm a release; the release controller reads custody
# to keep a held operation's claim.
claims={'apiGroups':['ipam.miloapis.com'],'resources':['ipclaims'],'verbs':['get','list','create','delete']}
if synced:rules.append(claims)
allocations={'apiGroups':['ipam.miloapis.com'],'resources':['ipallocations'],'verbs':['get','list']}
if synced:rules+=[claims,allocations]
# The coordinator rules mirror config/components/device-operations/roles/
# coordinator.yaml: it lists and settles every registered operation kind.
components={
Expand All @@ -109,7 +111,7 @@ def wait(fn,seconds,what):
{'apiGroups':['fleet.datumapis.com'],'resources':['deviceinstallations/status','devicewipes/status','devicepoweroperations/status','devicerecoveries/status','devicecommissionings/status'],'verbs':['get','update']},
{'apiGroups':['fleet.datumapis.com'],'resources':['devicecommissioningplans','devicecommissioningplanapprovals'],'verbs':['get','list','watch']},
{'apiGroups':['metal.datumapis.com'],'resources':['machineallocations'],'verbs':['get','list','watch']}]+([{'apiGroups':['ipam.miloapis.com'],'resources':['ipclaims'],'verbs':['get']}] if synced else []),
'release':[{'apiGroups':['fleet.datumapis.com'],'resources':['devicewipes'],'verbs':['get','create']}]+([claims,{'apiGroups':['fleet.datumapis.com'],'resources':['devicecustodies'],'verbs':['get']}] if synced else []),
'release':[{'apiGroups':['fleet.datumapis.com'],'resources':['devicewipes'],'verbs':['get','create']}]+([claims,allocations,{'apiGroups':['fleet.datumapis.com'],'resources':['devicecustodies'],'verbs':['get']}] if synced else []),
# The capacity projector is the only writer of capacity status.
'projector':[{'apiGroups':['metal.datumapis.com'],'resources':['machinecapacities'],'verbs':['get','list','watch']},{'apiGroups':['metal.datumapis.com'],'resources':['machinecapacities/status'],'verbs':['get','update']},
{'apiGroups':['fleet.datumapis.com'],'resources':['devices','devicecustodies','devicecommissionings','devicecommissioningplans','devicecommissioningplanapprovals'],'verbs':['get','list','watch']}],
Expand Down
38 changes: 38 additions & 0 deletions internal/allocation/bootaddress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ package allocation
import (
"context"
"encoding/json"
"errors"
"fmt"
"net/http"
"strings"
"sync"
"testing"

apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -248,3 +252,37 @@ func TestBootAddressesFollowTheirOperations(t *testing.T) {
t.Fatalf("phase = %s", allocation.Status.Phase)
}
}

// exhausted refuses every IPAM claim as IPAM does when its pool is full.
type exhausted struct{ client.Client }

func (c exhausted) Create(ctx context.Context, object client.Object, options ...client.CreateOption) error {
if claim, ok := object.(*unstructured.Unstructured); ok && claim.GroupVersionKind() == bootaddress.GVK {
return &apierrors.StatusError{ErrStatus: metav1.Status{
Status: metav1.StatusFailure, Code: http.StatusInsufficientStorage, Reason: "InsufficientStorage",
Details: &metav1.StatusDetails{Name: "lab-provisioning", Causes: []metav1.StatusCause{{Type: "Exhausted"}}},
}}
}
return c.Client.Create(ctx, object, options...)
}

// TestAnExhaustedPoolSendsNothing refuses the installation with IPAM's
// reason and creates no operation, so nothing reaches the site.
func TestAnExhaustedPoolSendsNothing(t *testing.T) {
e := startEnv(t)
e.allocator.Provider = exhausted{e.admin}
e.allocator.BootAddresses = &bootaddress.Claimer{Class: "provisioning"}
e.server(1)
allocation, err := e.allocator.Allocate(e.ctx, e.request(1))
if err != nil {
t.Fatal(err)
}
installation := e.installation(1, "debian-12", "")
if _, err := e.allocator.Install(e.ctx, allocation, Installation{Installation: installation}); !errors.Is(err, bootaddress.ErrExhausted) || !strings.Contains(err.Error(), "lab-provisioning") {
t.Fatalf("install with a full pool: %v", err)
}
operations := &ops.DeviceInstallationList{}
if err := e.admin.List(e.ctx, operations, client.InNamespace(e.allocator.Namespace)); err != nil || len(operations.Items) != 0 {
t.Fatalf("operations = %d, %v", len(operations.Items), err)
}
}
8 changes: 5 additions & 3 deletions internal/api/operations/v1alpha1/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,17 +514,19 @@ func TestBootAddressRolesAreOptIn(t *testing.T) {
return out
}
want := map[string][]string{
"fleet.datumapis.com-boot-address-requester": claims("create", "delete", "get", "list"),
// Requesters also read IPAM's allocations to confirm a release.
"fleet.datumapis.com-boot-address-requester": append(claims("create", "delete", "get", "list"), "ipam.miloapis.com/ipallocations.get", "ipam.miloapis.com/ipallocations.list"),
"fleet.datumapis.com-boot-address-checker": claims("get"),
}
roles := decodeDir[role](t, root)
if len(roles) != len(want) {
t.Fatalf("boot address roles = %d, want %d", len(roles), len(want))
}
for _, r := range roles {
actual := slices.Clone(r.Spec.Included)
actual, expected := slices.Clone(r.Spec.Included), slices.Clone(want[r.Metadata.Name])
slices.Sort(actual)
if !slices.Equal(actual, want[r.Metadata.Name]) || len(r.Spec.Inherited) != 0 {
slices.Sort(expected)
if !slices.Equal(actual, expected) || len(r.Spec.Inherited) != 0 {
t.Fatalf("%s = %v, want %v", r.Metadata.Name, actual, want[r.Metadata.Name])
}
}
Expand Down
Loading
Loading