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 @@ -645,6 +645,7 @@ spec:
type: array
maxItems: 16
items: {type: string, minLength: 1, maxLength: 63}
resetTypesObserved: {type: boolean}
networkInterfaces:
type: array
maxItems: 32
Expand Down
48 changes: 40 additions & 8 deletions docs/operations/bmc-discovery.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ status:
sku: TAG0001
powerState: "On"
resetTypes: ["On", ForceOff, ForceRestart]
resetTypesObserved: true
networkInterfaces:
- {id: NIC.1, macAddress: "00:00:5e:00:53:01", linkStatus: LinkUp, speedMbps: 25000}
conditions: [...]
Expand All @@ -296,6 +297,7 @@ lowercase canonical. Power state is an observation; discovery never changes it.
| `Discovered` | `InventoryRead`; False for a definite refusal (the reason above); Unknown `Unreachable`, `ReadFailed` |
| `IdentityMatched` | `Matched`; False `SystemUUIDMismatch`, `SerialMismatch`, `ModelMismatch`; Unknown `NotObserved`, `StaleObservation`, `AmbiguousSystem` |
| `PublicKeyUnique` | `Unique`; False `SharedPublicKey`; Unknown `NotObserved` |
| `ResetTypesRead` | `ResetTypesRead`; False `ResetActionMalformed`, `ActionInfoNotFound`, `ActionInfoUnreadable`, `ActionInfoMalformed`, `TooManyResetTypes`. Set with each recorded inventory; see [What is read](#what-is-read) |

Messages never carry a URL, credential, header or response body.

Expand Down Expand Up @@ -329,14 +331,40 @@ Service root, then every Manager and every ComputerSystem (up to 16 of each),
with each one's EthernetInterfaces (up to 32). For each System it records
the `ComputerSystem.Reset` types the BMC advertises, inline or from the
System's own ActionInfo, as `resetTypes`. It reads the action's description
and never invokes it. It keeps at most 16 distinct values. Malformed actions,
a reset target off the System, an ActionInfo off the System or under its
Actions, or an ActionInfo that cannot be read (missing, malformed, a server
error or a timeout) records none and keeps the rest of the inventory. A
rejected credential (401 or 403), a pin mismatch or an unexpected resource
path on the ActionInfo fails the read. Nothing reads `resetTypes` yet: it is
recorded for planned Device power operations, which will refuse an action the
server does not offer.
and never invokes it.

| `resetTypesObserved` | `resetTypes` | Meaning |
| --- | --- | --- |
| `true` | `["On", ForceOff]` | The BMC advertised these types. Any type not listed is not offered. |
| `true` | omitted | The BMC advertised an empty list. It offers no reset type. |
| omitted | omitted | Unknown. The System advertises no list (no reset action, or one without allowable values), or the list could not be read. |

Readers use `resetTypesObserved`, never whether `resetTypes` is empty: an
empty list is not serialized, so it is indistinguishable from an omitted one.
`resetTypesObserved` is per System and true only when this read succeeded.

`ResetTypesRead` explains, for operators, why a System's types are unknown.
It is False when the reset action is malformed or not on the System, or the
list holds only blank values (`ResetActionMalformed`), the ActionInfo is
missing (`ActionInfoNotFound`), a server error or timeout stops the read
(`ActionInfoUnreadable`), the response is not an ActionInfo
(`ActionInfoMalformed`), or the BMC advertises more than 16 distinct types
(`TooManyResetTypes`), since a partial list would refuse a type the BMC
offers. The message names each affected System. True means no read failed,
not that a list was observed. The rest of the inventory is kept and
`Discovered` stays True. A rejected credential (401 or 403), a pin mismatch
or an unexpected resource path on the ActionInfo fails the whole read, as for
any other document.

A separate condition, rather than a reason on `Discovered` or an event, keeps
`Discovered` meaning the inventory was read, and keeps the explanation in
status after events expire. It is per Device, so the per-System field carries
the signal. It changes only when a new inventory is recorded.

Nothing reads these fields yet. Planned Device power operations will refuse
an action with `ResetTypeNotOffered` when `resetTypesObserved` is true and
`resetTypes` lacks it. When `resetTypesObserved` is omitted they will admit
it, and the worker's live BMC check decides.

Collections follow `Members@odata.nextLink` for up to 8 pages. Every member
must sit under its collection. Documents are decoded leniently: only the
Expand Down Expand Up @@ -367,6 +395,10 @@ sessions. Basic authentication is used; no Redfish session is created.
- end to end against an `httptest` TLS service: first contact records the pin
with no credential sent, then approval yields inventory and
`IdentityMatched=True`;
- each reset type outcome as stored through the status patch: observed with a
list, observed with an empty list, or unobserved with the `ResetTypesRead`
reason, and a status round trip of `resetTypesObserved` through a disposable
API server;
- the Device status schema, the discoverer role, and the shipped Deployment's
single unprivileged replica.

Expand Down
138 changes: 138 additions & 0 deletions internal/api/inventory/v1alpha1/reset_types_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
package v1alpha1

import (
"context"
"encoding/json"
"os"
"path/filepath"
"slices"
"testing"

corev1 "k8s.io/api/core/v1"
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
extensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
structuralschema "k8s.io/apiextensions-apiserver/pkg/apiserver/schema"
"k8s.io/apiextensions-apiserver/pkg/apiserver/schema/pruning"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/envtest"
)

// resetFields is the serialized resetTypes and resetTypesObserved of the
// first System, each "" when omitted.
func resetFields(t *testing.T, d *Device) (types, observed string) {
t.Helper()
b, err := json.Marshal(d.Status.Discovery.Inventory.Systems[0])
if err != nil {
t.Fatal(err)
}
var fields map[string]json.RawMessage
if err := json.Unmarshal(b, &fields); err != nil {
t.Fatal(err)
}
return string(fields["resetTypes"]), string(fields["resetTypesObserved"])
}

// resetTypesObserved is admitted as a boolean and kept by pruning and
// DeepCopy, so an observed empty list survives although resetTypes is then
// omitted.
func TestResetTypesObservedIsKept(t *testing.T) {
var schema apiextensions.JSONSchemaProps
if err := extensionsv1.Convert_v1_JSONSchemaProps_To_apiextensions_JSONSchemaProps(loadCRDs(t)["Device"].Spec.Versions[0].Schema.OpenAPIV3Schema, &schema, nil); err != nil {
t.Fatal(err)
}
structural, err := structuralschema.NewStructural(&schema)
if err != nil {
t.Fatal(err)
}
for _, tc := range []struct {
types []string
observed bool
wantTypes, wantSeen string
}{{nil, false, "", ""}, {[]string{}, true, "", "true"}, {[]string{"On"}, true, `["On"]`, "true"}} {
device := discoveredDevice()
device.Status.Discovery.Inventory.Systems[0].ResetTypes = tc.types
device.Status.Discovery.Inventory.Systems[0].ResetTypesObserved = tc.observed
for _, d := range []*Device{&device, device.DeepCopyObject().(*Device)} {
if types, seen := resetFields(t, d); types != tc.wantTypes || seen != tc.wantSeen {
t.Fatalf("%v/%v serialized as %q/%q", tc.types, tc.observed, types, seen)
}
}
if errs := admit(t, "Device", object(t, device), nil); len(errs) > 0 {
t.Fatalf("%v/%v rejected: %v", tc.types, tc.observed, errs)
}
pruned := object(t, device)
pruning.Prune(pruned, structural, true)
system := pruned["status"].(map[string]any)["discovery"].(map[string]any)["inventory"].(map[string]any)["systems"].([]any)[0].(map[string]any)
if got, ok := system["resetTypesObserved"]; ok != tc.observed || ok && got != true {
t.Fatalf("pruned resetTypesObserved %v to %#v", tc.observed, got)
}
}
device := object(t, discoveredDevice())
device["status"].(map[string]any)["discovery"].(map[string]any)["inventory"].(map[string]any)["systems"].([]any)[0].(map[string]any)["resetTypesObserved"] = "true"
if errs := admit(t, "Device", device, nil); len(errs) == 0 {
t.Fatal("string resetTypesObserved accepted")
}
}

// A status merge patch through the API server stores and clears
// resetTypesObserved, with or without a list.
func TestResetTypesObservedRoundTripThroughTheAPIServer(t *testing.T) {
if os.Getenv("KUBEBUILDER_ASSETS") == "" {
t.Skip("KUBEBUILDER_ASSETS required for disposable Device status validation")
}
environment := &envtest.Environment{CRDDirectoryPaths: []string{filepath.Join(inventoryRoot, "crds")}, ErrorIfCRDPathMissing: true}
config, err := environment.Start()
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() {
if err := environment.Stop(); err != nil {
t.Error(err)
}
})
scheme := runtime.NewScheme()
if err := AddToScheme(scheme); err != nil {
t.Fatal(err)
}
if err := corev1.AddToScheme(scheme); err != nil {
t.Fatal(err)
}
api, err := client.New(config, client.Options{Scheme: scheme})
if err != nil {
t.Fatal(err)
}
ctx := context.Background()
if err := api.Create(ctx, &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: "fleet-system"}}); err != nil {
t.Fatal(err)
}
device := syntheticDevice()
if err := api.Create(ctx, &device); err != nil {
t.Fatal(err)
}
status := discoveredDevice().Status
for _, step := range []struct {
types []string
observed bool
}{{[]string{"On", "ForceOff"}, true}, {nil, true}, {nil, false}, {nil, true}, {[]string{"On"}, true}} {
var stored Device
if err := api.Get(ctx, client.ObjectKeyFromObject(&device), &stored); err != nil {
t.Fatal(err)
}
patch := client.MergeFromWithOptions(stored.DeepCopyObject().(*Device), client.MergeFromWithOptimisticLock{})
deepCopy(&status, &stored.Status)
stored.Status.Discovery.Inventory.Systems[0].ResetTypes = step.types
stored.Status.Discovery.Inventory.Systems[0].ResetTypesObserved = step.observed
if err := api.Status().Patch(ctx, &stored, patch); err != nil {
t.Fatalf("patch %v/%v: %v", step.types, step.observed, err)
}
var read Device
if err := api.Get(ctx, client.ObjectKeyFromObject(&device), &read); err != nil {
t.Fatal(err)
}
if got := read.Status.Discovery.Inventory.Systems[0]; got.ResetTypesObserved != step.observed || !slices.Equal(got.ResetTypes, step.types) {
t.Fatalf("stored %v/%v as %v/%v", step.types, step.observed, got.ResetTypes, got.ResetTypesObserved)
}
}
}
27 changes: 16 additions & 11 deletions internal/api/inventory/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ type DeviceStatus struct {
// Discovery holds the latest observations. A failed attempt never clears
// them: each keeps its own time and endpoint.
Discovery *DeviceDiscovery `json:"discovery,omitempty"`
// Conditions are Reachable, Authenticated, Discovered, IdentityMatched and
// PublicKeyUnique.
// Conditions are Reachable, Authenticated, Discovered, IdentityMatched,
// PublicKeyUnique and ResetTypesRead.
Conditions []metav1.Condition `json:"conditions,omitempty"`
}

Expand All @@ -202,6 +202,7 @@ const (
ConditionDiscovered = "Discovered"
ConditionIdentityMatched = "IdentityMatched"
ConditionPublicKeyUnique = "PublicKeyUnique"
ConditionResetTypesRead = "ResetTypesRead"
)

// DeviceDiscovery is the retained BMC observation of a Device.
Expand Down Expand Up @@ -258,16 +259,20 @@ type ObservedManager struct {
// ObservedSystem is one Redfish ComputerSystem. PowerState is an observation
// only; discovery never changes power. ResetTypes are the ComputerSystem.Reset
// types the BMC advertises for the System, read but never invoked.
// ResetTypesObserved is true only when discovery read an advertised list of
// them, which may be empty; otherwise the offered types are unknown. Readers
// use it rather than whether ResetTypes is empty, which is not serialized.
type ObservedSystem struct {
ID string `json:"id"`
UUID string `json:"uuid,omitempty"`
Manufacturer string `json:"manufacturer,omitempty"`
Model string `json:"model,omitempty"`
SerialNumber string `json:"serialNumber,omitempty"`
SKU string `json:"sku,omitempty"`
PowerState string `json:"powerState,omitempty"`
NetworkInterfaces []ObservedNetworkInterface `json:"networkInterfaces,omitempty"`
ResetTypes []string `json:"resetTypes,omitempty"`
ID string `json:"id"`
UUID string `json:"uuid,omitempty"`
Manufacturer string `json:"manufacturer,omitempty"`
Model string `json:"model,omitempty"`
SerialNumber string `json:"serialNumber,omitempty"`
SKU string `json:"sku,omitempty"`
PowerState string `json:"powerState,omitempty"`
NetworkInterfaces []ObservedNetworkInterface `json:"networkInterfaces,omitempty"`
ResetTypes []string `json:"resetTypes,omitempty"`
ResetTypesObserved bool `json:"resetTypesObserved,omitempty"`
}

// ObservedNetworkInterface is one Redfish EthernetInterface.
Expand Down
Loading
Loading