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
19 changes: 18 additions & 1 deletion config/base/crd/metal.datumapis.com.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ spec:
metadata: {type: object}
spec:
type: object
required: [consumerRef, machineRef, machineCapacityRef, deviceRef, accepted, hardware, authority, cleaningPolicy, bootInterface, targetDisks]
required: [consumerRef, machineRef, machineCapacityRef, deviceRef, accepted, hardware, authority, cleaningPolicy, drives, bootInterface, targetDisks]
x-kubernetes-validations:
- {rule: 'self == oldSelf', message: MachineAllocation identity and endpoints are immutable}
properties:
Expand Down Expand Up @@ -512,6 +512,23 @@ spec:
x-kubernetes-list-type: set
items: {type: string, enum: [CryptographicErase, BlockErase, SanitizeOverwrite, Format, SecureErase, Overwrite]}
alwaysEncrypts: {type: boolean}
drives:
type: array
maxItems: 16
x-kubernetes-list-type: map
x-kubernetes-list-map-keys: [name]
items:
type: object
required: [name, serialNumber, model, firmware, protocol, mediaType, capacityBytes, rule]
properties:
name: {type: string, pattern: '^disk-[0-9]+$', maxLength: 12}
serialNumber: {type: string, maxLength: 253}
model: {type: string, maxLength: 253}
firmware: {type: string, maxLength: 63}
protocol: {type: string, maxLength: 31}
mediaType: {type: string, maxLength: 31}
capacityBytes: {type: integer, minimum: 0}
rule: {type: string, maxLength: 63}
bootInterface: {type: string, minLength: 1, maxLength: 63}
targetDisks:
type: array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -852,15 +852,40 @@ spec:
- name
- generation
- digest
targetDisks:
assurance:
type: string
enum: [Clear, Purge]
drives:
type: array
minItems: 1
maxItems: 16
x-kubernetes-list-type: map
x-kubernetes-list-map-keys: [name]
items:
type: string
minLength: 1
maxLength: 63
x-kubernetes-list-type: set
type: object
required: [name, serialNumber, model, firmware, protocol, mediaType, capacityBytes]
properties:
name: {type: string, pattern: '^disk-[0-9]+$', maxLength: 12}
serialNumber: {type: string, maxLength: 253}
model: {type: string, maxLength: 253}
firmware: {type: string, maxLength: 63}
protocol: {type: string, maxLength: 31}
mediaType: {type: string, maxLength: 31}
capacityBytes: {type: integer, minimum: 0}
rule: {type: string, maxLength: 63}
methods:
type: array
maxItems: 6
x-kubernetes-list-type: set
items: {type: string, enum: [CryptographicErase, BlockErase, SanitizeOverwrite, Format, SecureErase, Overwrite]}
verify:
type: object
required: [mode]
properties:
mode: {type: string, enum: [Full, Canary]}
samples: {type: integer, format: int32, minimum: 0, maximum: 1024}
timePerTiB: {type: string, maxLength: 32, pattern: '^([0-9]+(\.[0-9]+)?(ns|us|µs|μs|ms|s|m|h))+$'}
state: {type: string, enum: [Missing, Uncovered]}
# Optional in the schema so wipes stored before it existed stay
# valid; admission refuses a wipe whose boot interface the
# Device does not record with a MAC address.
Expand Down Expand Up @@ -906,7 +931,8 @@ spec:
- authority
- step
- policy
- targetDisks
- assurance
- drives
x-kubernetes-validations:
- rule: self == oldSelf
message: an operation spec is immutable after create
Expand Down
39 changes: 33 additions & 6 deletions docs/development/device-custody.md
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,7 @@ guarded, and a test fails if its guard is removed:
| Consumer project, against quota | Quota resolves the project and requires the incarnation the Machine was admitted in | `TestQuotaServesOnlyTheMachinesProjectIncarnation` |
| Device | Custody's `device-uid` label must match the Device, or custody stays `Unverified` until a `Resolve` | `TestARecreatedDeviceLeavesCustodyUnverified` |
| Device, against free capacity | Custody for another Device incarnation is never free | `TestCustodyForAnotherDeviceIncarnationIsNotFree` |
| Device, against a release wipe | The release controller plans a wipe only if the Device's UID is the allocation's `device-uid` label | `TestAWipeIsNeverPlannedForARecreatedDevice` |
| Device, against a claim | `Claim` takes the Device incarnation the allocation names, and refuses unless both the live Device and custody's label match it | `TestCustodyForAnotherDeviceIncarnationIsNeverClaimed`, `TestARecreatedDeviceIsNeverClaimedUnderItsStaleLabel`, `TestARecreatedDeviceIsNeverClaimedForTheEarlierIncarnation` |
| Device, against an operation | An operation's `device-uid` label must match the Device at admission | `TestAdmissionPreconditions` |
| Device, against an existing operation | The Metal provider and release controller require an existing same-name operation to carry the same labels | `TestAnOperationForAnotherDeviceIncarnationIsAConflict` |
Expand Down Expand Up @@ -853,12 +854,38 @@ real API server. The rest of #183 is **proposed**.

BMC discovery records each System's drives from Redfish in Device status, and
fixture discovery reports one simulated drive per enrolled disk. The Redfish
lab serves a Storage collection for its targets. These are observations only.

Not implemented yet: drive inventory from commissioning, the media
manifest and pinned drive names, the per-drive plan in `DeviceWipe`, the
in-band methods and their evidence, the evidence check and its reasons, and
`DisposeDrive`. Until then, every site still wipes its one enrolled disk.
lab's targets each have one emulated NVMe drive.

- **Manifest.** The allocator pins every drive the server reports, named
`disk-0`, `disk-1` and so on by protocol and serial number, with the rule
that covers it. A server whose drives are unknown, back a RAID volume, lack
a serial number, or have no planned method is skipped as uncovered.
Installation target disks must be names in the manifest.
- **Plan.** One shared planner turns the pin and current discovery into one
step per drive. It matches a pinned drive by serial number and requires
the same model, protocol, media type and capacity; firmware may change but
must still be qualified. A drive that shares its serial number with another,
or reports none, is `Uncovered`. The release controller writes the plan into
each `DeviceWipe`, and admission plans again and refuses a wipe whose plan
differs, with reason `PlanMismatch`. Such a refusal does not count toward
the release's three failed steps, but a release stops after 16 steps. A
retried create that finds a wipe with another plan keeps it, because
admission plans it again.
- **Missing and uncovered drives (interim).** While a planned drive is
`Missing` or `Uncovered`, the release controller creates no wipe. It sets
the allocation's `Cleaning` condition to `False` with reason `DriveMissing`
or `DriveUncovered`, and plans again when discovery changes. Admission also
refuses such a wipe. #183 instead ends it `OutcomeUnknown` under a recovery
hold that `DisposeDrive` settles; that comes with `DisposeDrive`.
- **Sites.** Every site cleans only by overwriting each planned drive and
reading it back, and refuses any other plan before sending anything. Sites
match planned drives to their enrolled disks by name, and fixture drives'
serial numbers sort in enrollment order so the names agree. Matching by
serial number on the server comes with the wipe environment.

Not implemented yet: drive inventory from commissioning, the in-band methods
other than overwrite and their evidence, the evidence check and its reasons,
the plan-derived deadline, and `DisposeDrive`.

### Cutover decisions

Expand Down
2 changes: 1 addition & 1 deletion hack/standalone-smoke.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ for crd in installations machineallocations machinecapacities machineclasses mac
exit 1
fi
done
for crd in devices devicecustodies deviceinstallations devicewipes devicepoweroperations devicerecoveries devicecommissionings devicecommissioningplans devicecommissioningplanapprovals sealedpayloads; do
for crd in devices devicecustodies deviceinstallations devicewipes devicepoweroperations devicerecoveries devicecommissionings devicecommissioningplans devicecommissioningplanapprovals cleaningpolicies sealedpayloads; do
if kubectl --context "$context" get crd "$crd.fleet.datumapis.com" >/dev/null 2>&1; then
echo "fixed Fleet CRD $crd already exists; use a fresh dedicated kind cluster" >&2
exit 1
Expand Down
13 changes: 13 additions & 0 deletions internal/allocation/allocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,18 @@ func (a *Allocator) newAllocation(ctx context.Context, request Request, capacity
if err != nil {
return nil, err
}
// The manifest pins every drive the server has now. A server with a drive
// the policy cannot clean, or storage discovery has not reported, is not
// covered.
drives, err := cleaning.Manifest(policy.Spec, cleaning.StorageOf(device))
if err != nil {
return nil, fmt.Errorf("%w: capacity %s: %v", ErrCleaningUncovered, capacity.Name, err)
}
for _, disk := range a.TargetDisks {
if !slices.ContainsFunc(drives, func(d ops.ManifestDrive) bool { return d.Name == disk }) {
return nil, fmt.Errorf("%w: capacity %s has no drive %s to install on", ErrCleaningUncovered, capacity.Name, disk)
}
}
classDigest, err := custody.SpecDigest(request.Class.Spec)
if err != nil {
return nil, err
Expand All @@ -508,6 +520,7 @@ func (a *Allocator) newAllocation(ctx context.Context, request Request, capacity
Hardware: hardware,
Authority: request.Authority,
CleaningPolicy: policy,
Drives: drives,
BootInterface: a.BootInterface,
TargetDisks: slices.Clone(a.TargetDisks),
},
Expand Down
172 changes: 170 additions & 2 deletions internal/allocation/cleaning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ package allocation

import (
"errors"
"strings"
"testing"

apierrors "k8s.io/apimachinery/pkg/api/errors"
apiMeta "k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"

inventory "go.datum.net/fleet/internal/api/inventory/v1alpha1"
ops "go.datum.net/fleet/internal/api/operations/v1alpha1"
fleetv1 "go.datum.net/fleet/internal/api/v1alpha1"
"go.datum.net/fleet/internal/cleaning"
"go.datum.net/fleet/internal/custody"
)
Expand Down Expand Up @@ -58,13 +63,23 @@ func TestAllocationPinsItsCleaningPolicy(t *testing.T) {
if err := e.admin.Get(e.ctx, client.ObjectKey{Namespace: namespace, Name: custody.WipeName(allocation.Name, 1)}, wipe); err != nil {
t.Fatal(err)
}
if wipe.Spec.Policy != pinned.CleaningPolicyReference {
if wipe.Spec.Policy != pinned.CleaningPolicyReference || wipe.Spec.Assurance != ops.AssuranceClear {
t.Fatalf("wipe policy = %+v, want %+v", wipe.Spec.Policy, pinned.CleaningPolicyReference)
}
// The manifest pinned the server's one drive, and the wipe plans it with
// the pinned rule's method and check.
if len(allocation.Spec.Drives) != 1 || allocation.Spec.Drives[0].Name != "disk-0" || allocation.Spec.Drives[0].SerialNumber == "" {
t.Fatalf("manifest = %+v", allocation.Spec.Drives)
}
if len(wipe.Spec.Drives) != 1 || wipe.Spec.Drives[0].ManifestDrive != allocation.Spec.Drives[0] || wipe.Spec.Drives[0].State != "" ||
wipe.Spec.Drives[0].Verify == nil || wipe.Spec.Drives[0].Verify.Mode != ops.VerifyFull {
t.Fatalf("plan = %+v", wipe.Spec.Drives)
}
}

// TestCapacityWithoutAUsableCleaningPolicyIsNotAllocated skips capacity
// whose policy is missing or invalid, and claims nothing.
// whose policy is missing or invalid, or whose drives the policy does not
// cover, and claims nothing.
func TestCapacityWithoutAUsableCleaningPolicyIsNotAllocated(t *testing.T) {
cases := map[string]func(e *env){
"missing policy": func(e *env) {
Expand All @@ -83,6 +98,20 @@ func TestCapacityWithoutAUsableCleaningPolicyIsNotAllocated(t *testing.T) {
e.create(invalid)
},
}
cases["drives not reported"] = func(e *env) {
device := e.device("server-example-001")
device.Status.Discovery.Inventory.Systems[0].Storage = nil
if err := e.admin.Status().Update(e.ctx, device); err != nil {
e.t.Fatal(err)
}
}
cases["a drive no rule covers"] = func(e *env) {
device := e.device("server-example-001")
device.Status.Discovery.Inventory.Systems[0].Storage.Drives[0].Protocol = "SAS"
if err := e.admin.Status().Update(e.ctx, device); err != nil {
e.t.Fatal(err)
}
}
for name, setup := range cases {
t.Run(name, func(t *testing.T) {
e := startEnv(t)
Expand Down Expand Up @@ -145,3 +174,142 @@ func TestARecreatedPolicyChangesNoPin(t *testing.T) {
t.Fatalf("the release must wipe under the original pin: %+v, want %+v", wipe.Spec.Policy, original.CleaningPolicyReference)
}
}

// TestReleaseWaitsWhileADriveCannotBeCleaned creates no wipe while a pinned
// drive is missing, so a gap in discovery spends no wipe step, and plans
// again when the drive returns.
func TestReleaseWaitsWhileADriveCannotBeCleaned(t *testing.T) {
e := startEnv(t)
device := e.server(1)
allocation, err := e.allocator.Allocate(e.ctx, e.request(1))
if err != nil {
t.Fatal(err)
}
saved := e.device(device.Name).Status.Discovery.Inventory.Systems[0].Storage.Drives
setDrives := func(drives []inventory.ObservedDrive) {
t.Helper()
current := e.device(device.Name)
current.Status.Discovery.Inventory.Systems[0].Storage.Drives = drives
if err := e.admin.Status().Update(e.ctx, current); err != nil {
t.Fatal(err)
}
}
setDrives(nil)
var blocked error
e.until("release reports the missing drive", func() bool {
if err := e.admin.Get(e.ctx, client.ObjectKeyFromObject(allocation), allocation); err != nil {
t.Fatal(err)
}
_, blocked = e.allocator.Release(e.ctx, allocation, machine(1))
return errors.Is(blocked, ErrCleaningBlocked)
})
if err := e.admin.Get(e.ctx, client.ObjectKeyFromObject(allocation), allocation); err != nil {
t.Fatal(err)
}
condition := apiMeta.FindStatusCondition(allocation.Status.Conditions, ConditionCleaning)
if condition == nil || condition.Status != metav1.ConditionFalse || condition.Reason != custody.ReasonDriveMissing || allocation.Status.Wipe != nil {
t.Fatalf("condition = %+v, wipe = %+v", condition, allocation.Status.Wipe)
}
wipes := &ops.DeviceWipeList{}
if err := e.admin.List(e.ctx, wipes); err != nil || len(wipes.Items) != 0 {
t.Fatalf("no wipe may exist while a drive cannot be cleaned: %d, %v", len(wipes.Items), err)
}
setDrives(saved)
e.release(allocation, machine(1))
if apiMeta.FindStatusCondition(allocation.Status.Conditions, ConditionCleaning) != nil {
t.Fatal("the Cleaning condition must clear once a wipe is planned")
}
}

// TestPlanMismatchSpendsNoWipeStep counts only failures that are not plan
// mismatches toward the release's limit.
func TestPlanMismatchSpendsNoWipeStep(t *testing.T) {
e := startEnv(t)
device := e.server(1)
for step, reason := range map[int32]string{1: custody.ReasonPlanMismatch, 2: custody.ReasonPlanMismatch, 3: "TargetDisksUnknown"} {
wipe := &ops.DeviceWipe{ObjectMeta: metav1.ObjectMeta{Name: custody.WipeName("alloc-steps", step), Namespace: namespace}, Spec: ops.DeviceWipeSpec{
OperationEnvelope: ops.OperationEnvelope{Creator: ops.Creator{Username: releaseUser, UID: uid(802)}, DeviceRef: ops.DeviceReference{Name: device.Name},
Authority: ops.Authority{AllocationRef: &ops.LocalReference{Name: "alloc-steps"}}},
Step: step, Policy: ops.CleaningPolicyReference{Name: "p", Generation: 1, Digest: "sha256:" + strings.Repeat("a", 64)}, Assurance: ops.AssuranceClear,
Drives: []ops.PlannedDrive{{ManifestDrive: ops.ManifestDrive{Name: "disk-0", SerialNumber: "SN", Model: "M", Firmware: "F", Protocol: ops.ProtocolNVMe, MediaType: ops.MediaSSD, CapacityBytes: 1}, State: ops.DriveMissing}}}}
e.create(wipe)
wipe.Status = ops.OperationStatus{Phase: ops.PhaseFailed, Reason: reason}
if err := e.admin.Status().Update(e.ctx, wipe); err != nil {
t.Fatal(err)
}
}
failed, err := e.allocator.failedSteps(e.ctx, "alloc-steps", 3)
if err != nil || failed != 1 {
t.Fatalf("failed steps = %d, %v; want 1", failed, err)
}
}

// TestInstallTargetMustBeAPinnedDrive skips capacity whose drives do not
// include the disk installations target.
func TestInstallTargetMustBeAPinnedDrive(t *testing.T) {
e := startEnv(t)
e.server(1)
e.allocator.TargetDisks = []string{"disk-1"}
if _, err := e.allocator.Allocate(e.ctx, e.request(1)); !errors.Is(err, ErrInsufficientCapacity) || !errors.Is(err, ErrCleaningUncovered) {
t.Fatalf("allocate = %v", err)
}
}

// TestARetriedWipeAdoptsTheExistingOne keeps a wipe whose create response was
// lost even when discovery changed before the retry: admission plans it again.
func TestARetriedWipeAdoptsTheExistingOne(t *testing.T) {
e := startEnv(t)
e.server(1)
allocation, err := e.allocator.Allocate(e.ctx, e.request(1))
if err != nil {
t.Fatal(err)
}
reference := fleetv1.WipeReference{Name: custody.WipeName(allocation.Name, 1), Step: 1}
existing := &ops.DeviceWipe{ObjectMeta: metav1.ObjectMeta{Name: reference.Name, Namespace: namespace, Labels: operationLabels(allocation)}, Spec: ops.DeviceWipeSpec{
OperationEnvelope: e.allocator.envelope(allocation, e.allocator.ReleaseCreator), Step: 1,
Policy: allocation.Spec.CleaningPolicy.CleaningPolicyReference, Assurance: ops.AssuranceClear, BootInterface: allocation.Spec.BootInterface,
Drives: []ops.PlannedDrive{{ManifestDrive: allocation.Spec.Drives[0], State: ops.DriveMissing}}}}
e.create(existing)
if err := e.allocator.wipe(e.ctx, allocation, reference); err != nil {
t.Fatalf("wipe = %v, want the existing wipe adopted", err)
}
got := &ops.DeviceWipe{}
if err := e.admin.Get(e.ctx, client.ObjectKeyFromObject(existing), got); err != nil || got.Spec.Drives[0].State != ops.DriveMissing {
t.Fatalf("the existing wipe must stand: %+v, %v", got.Spec.Drives, err)
}
}

// TestAWipeIsNeverPlannedForARecreatedDevice deletes the allocated Device and
// creates another under its name. The release controller must not plan a
// wipe from the new Device's drives: the allocation's device-uid label names
// the server it pinned.
func TestAWipeIsNeverPlannedForARecreatedDevice(t *testing.T) {
e := startEnv(t)
e.server(1)
allocation, err := e.allocator.Allocate(e.ctx, e.request(1))
if err != nil {
t.Fatal(err)
}
device := e.device("server-example-001")
if err := e.admin.Delete(e.ctx, device); err != nil {
t.Fatal(err)
}
replacement := &inventory.Device{ObjectMeta: metav1.ObjectMeta{Name: device.Name, Namespace: namespace}, Spec: device.Spec}
e.until("the Device is recreated", func() bool { return e.admin.Create(e.ctx, replacement) == nil })
if replacement.UID == device.UID {
t.Fatal("the recreated Device has the old UID")
}
// The new Device reports the same drives, so only the incarnation check
// stands between it and a wipe.
replacement.Status = device.Status
if err := e.admin.Status().Update(e.ctx, replacement); err != nil {
t.Fatal(err)
}
reference := fleetv1.WipeReference{Name: custody.WipeName(allocation.Name, 1), Step: 1}
if err := e.allocator.wipe(e.ctx, allocation, reference); !errors.Is(err, ErrCustodyLost) {
t.Fatalf("wipe = %v, want ErrCustodyLost", err)
}
if err := e.admin.Get(e.ctx, client.ObjectKey{Namespace: namespace, Name: reference.Name}, &ops.DeviceWipe{}); !apierrors.IsNotFound(err) {
t.Fatalf("no wipe may be created for a recreated Device: %v", err)
}
}
Loading
Loading