Skip to content
Open
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
7 changes: 2 additions & 5 deletions cmd/fleet-manager/synthetic.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,7 @@ func syntheticCustody(ctx context.Context, scheme *runtime.Scheme, providerConfi
return nil, nil, nil, err
}
namespace := flags.syntheticDeviceNamespace
// The simulator's installs and wipes are simulated, so its declaration
// keeps the lifecycle it always had: it starts no DHCP, claims no boot
// address and attaches no boot NIC, and offers no virtual media.
sites := &delivery.Sites{Sites: map[string]delivery.Site{syntheticSite: remote}, Devices: map[string][]string{}, Methods: map[string][]custody.OfferedMethod{syntheticSite: custody.NetworkBootOnly}}
sites := &delivery.Sites{Sites: map[string]delivery.Site{syntheticSite: remote}, Devices: map[string][]string{}}
for device := range enrollment {
deviceNamespace, name, _ := strings.Cut(device, "/")
if deviceNamespace != namespace {
Expand Down Expand Up @@ -112,7 +109,7 @@ func syntheticCustody(ctx context.Context, scheme *runtime.Scheme, providerConfi
Capacity: &capacity.Projector{Reader: provider, Namespace: namespace, Cleaning: cleaning},
// The synthetic site enrolls one boot NIC and one disk per Device.
BootInterface: "primary", TargetDisks: []string{"disk-0"},
DeliveryMethods: custody.NetworkBootOnly,
Sites: sites,
}
// Synthetic staging has no BMC discovery. The manager writes fixture
// discovery for the synthetic site's Devices instead.
Expand Down
18 changes: 14 additions & 4 deletions cmd/fleet-multiplane/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"k8s.io/client-go/tools/clientcmd"

"go.datum.net/fleet/internal/coordination"
"go.datum.net/fleet/internal/custody"
"go.datum.net/fleet/internal/multiplane"
"go.datum.net/fleet/internal/redfish"
"go.datum.net/fleet/internal/site"
Expand All @@ -40,6 +41,7 @@ func run() error {
handoff := fs.String("handoff", "", "exact delivered handoff name (site-worker)")
origin := fs.String("origin", "", "boot listener origin to probe, http://IPv4:port (boot-denials; required)")
interval := fs.Duration("interval", 10*time.Second, "observation refresh interval (site-observer)")
deliveryFile := fs.String("delivery-methods", "", "the site enrollment's delivery declaration, a JSON list of offers (site-observer, dhcp-feed)")
configPath := fs.String("config", "", "private acceptance config JSON")
kubeconfig := fs.String("kubeconfig", "", "cell-local kubeconfig; default in-cluster ServiceAccount")
cell := fs.String("cell", "", "exact Karmada member name")
Expand Down Expand Up @@ -79,7 +81,7 @@ func run() error {
return multiplane.Coordinate(ctx, config, multiplane.CoordinatorOptions{InstallationDeadline: *installationDeadline, SkewMargin: *skewMargin}, func(err error) {
fmt.Fprintf(os.Stderr, "%s coordinator: pass incomplete: %v\n", time.Now().UTC().Format(time.RFC3339), err)
})
case "seed", "commission", "allocate", "install", "admit-install", "admit-install-b", "release", "release-b", "reuse", "recovery-mismatch", "probe-unallocatable", "tenant-isolation", "media-not-offered", "media-unpinned", "media-install-held", "media-install-download", "media-install-lost", "media-install":
case "seed", "commission", "allocate", "install", "admit-install", "admit-install-b", "release", "release-b", "reuse", "recovery-mismatch", "probe-unallocatable", "tenant-isolation", "media-not-offered", "media-offered", "media-unpinned", "media-install-held", "media-install-download", "media-install-lost", "media-install":
return phase(os.Args[1], *configPath, *once)
case "redfish-probe":
return probe(*endpoint, *credentials, *system, *uuid, *pin, *clientID)
Expand All @@ -91,7 +93,7 @@ func run() error {
fmt.Println(image)
return nil
case "boot-service", "boot-denials", "dhcp-feed":
return boot(os.Args[1], *origin, *extraMAC, *syncToken, *tlsCert, *tlsKey)
return boot(os.Args[1], *origin, *extraMAC, *syncToken, *tlsCert, *tlsKey, *deliveryFile)
case "boot-withhold":
return armWithhold(fs.Arg(0))
case "media-stale":
Expand Down Expand Up @@ -165,7 +167,15 @@ func run() error {
}
cellView := &coordination.Cell{API: api, Namespace: coordinationNamespace, Name: *cell}
if os.Args[1] == "site-observer" {
// The observer never runs work: it reports what the store holds.
// The observer never runs work: it reports what the store holds and
// the enrollment's delivery declaration, read again on every pass.
cellView.Delivery = func() ([]custody.OfferedMethod, error) {
data, err := os.ReadFile(*deliveryFile)
if err != nil {
return nil, err
}
return custody.ParseOffered(data)
}
return cellView.Observe(ctx, *interval, store, site.NewResults(store), func(name string, err error) {
fmt.Fprintf(os.Stderr, "observer: handoff %s not published: %s\n", name, classify(err))
})
Expand Down Expand Up @@ -210,7 +220,7 @@ func phase(name, configPath string, once bool) error {
"commission": r.Commission, "allocate": r.Allocate, "admit-install": r.AdmitInstall, "install": r.Install,
"release": r.Release, "release-b": r.ReleaseSecond, "reuse": r.Reuse,
"admit-install-b": r.AdmitInstallSecond, "recovery-mismatch": r.RecoveryMismatch, "probe-unallocatable": r.ProbeUnallocatable, "tenant-isolation": r.TenantIsolation,
"media-not-offered": r.MediaNotOffered, "media-unpinned": r.MediaUnpinned, "media-install-held": r.MediaInstallHeld, "media-install-download": r.MediaInstallDownload, "media-install-lost": r.MediaInstallLost, "media-install": r.MediaInstall,
"media-not-offered": r.MediaNotOffered, "media-offered": r.MediaOffered, "media-unpinned": r.MediaUnpinned, "media-install-held": r.MediaInstallHeld, "media-install-download": r.MediaInstallDownload, "media-install-lost": r.MediaInstallLost, "media-install": r.MediaInstall,
}[name]
last := ""
for {
Expand Down
24 changes: 19 additions & 5 deletions cmd/fleet-multiplane/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/client"

"go.datum.net/fleet/internal/custody"
"go.datum.net/fleet/internal/redfish"
"go.datum.net/fleet/internal/site"
"go.datum.net/fleet/internal/site/fixture"
Expand Down Expand Up @@ -267,7 +268,7 @@ func redfishKinds(work redfishwork.Config, burnIn string) map[string]site.Kind {

// boot serves network boots, the DHCP reservation feed, or probes that
// every closed admission is denied.
func boot(command, origin, extraMAC, syncToken, tlsCert, tlsKey string) error {
func boot(command, origin, extraMAC, syncToken, tlsCert, tlsKey, deliveryFile string) error {
store, err := openStore()
if err != nil {
return err
Expand Down Expand Up @@ -305,7 +306,11 @@ func boot(command, origin, extraMAC, syncToken, tlsCert, tlsKey string) error {
if err != nil {
return err
}
enrollment, err := feedEnrollment([]byte(os.Getenv("FLEET_REDFISH_ENROLLMENT")))
declaration, err := os.ReadFile(deliveryFile)
if err != nil {
return fmt.Errorf("the site enrollment's delivery declaration: %w", err)
}
enrollment, err := feedEnrollment([]byte(os.Getenv("FLEET_REDFISH_ENROLLMENT")), declaration)
if err != nil {
return err
}
Expand Down Expand Up @@ -334,16 +339,25 @@ func boot(command, origin, extraMAC, syncToken, tlsCert, tlsKey string) error {
}

// feedEnrollment is the enrollment the DHCP reservation feed serves. Only a
// site whose enrollment has synced DHCP has a feed; the default, static,
// leaves DHCP to the site and starts no feed.
func feedEnrollment(raw []byte) (redfish.Enrollment, error) {
// site whose enrollment has synced DHCP and declares network boot has a
// feed. The defaults, static DHCP and no declaration, leave DHCP to the site
// and start no feed, and a site that declares only virtual media never
// network-boots, so it starts none either.
func feedEnrollment(raw, declaration []byte) (redfish.Enrollment, error) {
enrollment, err := redfish.ParseEnrollment(raw)
if err != nil {
return redfish.Enrollment{}, err
}
if enrollment.DHCP != redfish.DHCPSynced {
return redfish.Enrollment{}, errors.New("the DHCP reservation feed serves only a site whose enrollment has synced DHCP")
}
offered, err := custody.ParseOffered(declaration)
if err != nil {
return redfish.Enrollment{}, fmt.Errorf("the site enrollment's delivery declaration: %w", err)
}
if !custody.NetworkBootOffered(offered) {
return redfish.Enrollment{}, errors.New("the DHCP reservation feed serves only a site whose enrollment declares network boot")
}
return enrollment, nil
}

Expand Down
35 changes: 32 additions & 3 deletions cmd/fleet-multiplane/site_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,43 @@ func syntheticEnrollment(dhcp string) []byte {
// feed for an enrollment that leaves DHCP to the site, or names no DHCP
// mode.
func TestTheDHCPFeedStartsOnlyForSyncedDHCP(t *testing.T) {
if _, err := feedEnrollment(syntheticEnrollment(`"dhcp":"static",`)); err == nil || !strings.Contains(err.Error(), "synced DHCP") {
networkBoot := []byte(`[{"method":"NetworkBoot"}]`)
if _, err := feedEnrollment(syntheticEnrollment(`"dhcp":"static",`), networkBoot); err == nil || !strings.Contains(err.Error(), "synced DHCP") {
t.Errorf("static DHCP: the feed started: %v", err)
}
if _, err := feedEnrollment(syntheticEnrollment(``)); err == nil {
if _, err := feedEnrollment(syntheticEnrollment(``), networkBoot); err == nil {
t.Error("no DHCP mode: the feed started")
}
enrollment, err := feedEnrollment(syntheticEnrollment(`"dhcp":"synced","dhcpInstances":["fleet-site-dhcp-0"],`))
enrollment, err := feedEnrollment(syntheticEnrollment(synced), networkBoot)
if err != nil || len(enrollment.DHCPInstances) != 1 {
t.Fatalf("synced DHCP: %+v, %v", enrollment, err)
}
}

// synced is the DHCP fields of a synced enrollment with one instance.
const synced = `"dhcp":"synced","dhcpInstances":["fleet-site-dhcp-0"],`

// TestTheDHCPFeedStartsOnlyWhereTheEnrollmentDeclaresNetworkBoot refuses
// to start the feed, even with synced DHCP, for a site whose enrollment
// declares only virtual media, declares nothing, or names no valid
// declaration.
func TestTheDHCPFeedStartsOnlyWhereTheEnrollmentDeclaresNetworkBoot(t *testing.T) {
for name, declaration := range map[string]string{
"only virtual media": `[{"method":"VirtualMedia","addresses":"DataNetwork","mediaService":"https://192.0.2.10:8443"}]`,
"nothing": `[]`,
"no declaration": ``,
"not a declaration": `{"method":"NetworkBoot"}`,
} {
if _, err := feedEnrollment(syntheticEnrollment(synced), []byte(declaration)); err == nil {
t.Errorf("%s: the feed started", name)
}
}
for name, declaration := range map[string]string{
"network boot": `[{"method":"NetworkBoot"}]`,
"virtual media then network boot": `[{"method":"VirtualMedia","addresses":"DataNetwork","mediaService":"https://192.0.2.10:8443"},{"method":"NetworkBoot"}]`,
} {
if _, err := feedEnrollment(syntheticEnrollment(synced), []byte(declaration)); err != nil {
t.Errorf("%s: the feed did not start: %v", name, err)
}
}
}
6 changes: 5 additions & 1 deletion cmd/fleet-simulator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"

inventory "go.datum.net/fleet/internal/api/inventory/v1alpha1"
"go.datum.net/fleet/internal/custody"
"go.datum.net/fleet/internal/site"
"go.datum.net/fleet/internal/site/fixture"
"go.datum.net/fleet/internal/site/simwork"
Expand Down Expand Up @@ -76,7 +77,10 @@ func main() {
Kinds: map[string]site.Kind{"DeviceInstallation": simwork.Installation{}, "DeviceWipe": simwork.Wipe{}, "DeviceCommissioning": simwork.Commissioning{}}}
runner.Kinds["DevicePowerOperation"] = simwork.Power{}
dispatcher := &siteapi.Dispatcher{Runner: runner, Context: ctx, Logger: logger}
server := newServer(address, siteapi.Handler(dispatcher, store, results, func() (string, error) { return readToken(tokenPath) }), logger)
// The simulator's installs and wipes are simulated, so its declaration
// keeps the lifecycle it always had: it starts no DHCP, claims no boot
// address and attaches no boot NIC, and offers no virtual media.
server := newServer(address, siteapi.Handler(dispatcher, store, results, custody.NetworkBootOnly, func() (string, error) { return readToken(tokenPath) }), logger)
if discover {
api, err := discoveryClient()
if err != nil {
Expand Down
21 changes: 18 additions & 3 deletions cmd/fleet-standalone-smoke/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ func main() {
Capacity: offers,
// The fixture Device's boot NIC and the simulator's one enrolled disk.
BootInterface: "primary", TargetDisks: []string{"disk-0"},
// The simulator site offers only network boot.
DeliveryMethods: custody.NetworkBootOnly,
Sites: simulatorOffer{site: siteName},
}
runner := standalone.Runner{Client: provider, Allocator: allocator, Options: options}
if phase == standalone.PhaseCommission {
Expand All @@ -103,6 +102,22 @@ func main() {
fmt.Printf("standalone synthetic smoke phase %s completed\n", phase)
}

// simulatorOffer is the phases' view of the simulator site, which declares
// only network boot. The phases hold no site credential, so they do not
// read the declaration; the coordinator reads it from the site's API and
// refuses an installation recording any other method.
type simulatorOffer struct{ site string }

func (s simulatorOffer) Serving(*inventory.Device) []string { return []string{s.site} }

func (s simulatorOffer) Fence(context.Context, string, *inventory.Device) (custody.SiteFence, bool, error) {
return custody.SiteFence{}, false, nil
}

func (s simulatorOffer) DeliveryMethods(context.Context, string, *inventory.Device) ([]custody.OfferedMethod, bool, error) {
return custody.NetworkBootOnly, true, nil
}

// coordinate is the coordinator process: the custody loop with the simulator
// as the only site.
func coordinate(ctx context.Context, config *rest.Config, registry *custody.Registry, namespace, siteName, siteURL, tokenFile, projectorToken string, devices []string) error {
Expand All @@ -121,7 +136,7 @@ func coordinate(ctx context.Context, config *rest.Config, registry *custody.Regi
if err != nil {
return err
}
sites := &delivery.Sites{Sites: map[string]delivery.Site{siteName: remote}, Devices: map[string][]string{}, Methods: map[string][]custody.OfferedMethod{siteName: custody.NetworkBootOnly}}
sites := &delivery.Sites{Sites: map[string]delivery.Site{siteName: remote}, Devices: map[string][]string{}}
for _, device := range devices {
if device = strings.TrimSpace(device); device != "" {
sites.Devices[device] = []string{siteName}
Expand Down
24 changes: 16 additions & 8 deletions config/site/dhcp/feed/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# The reservation feed: a container beside the boot service, which reads the
# site store and writes the applied reports beside the boot evidence, and a
# Service. The site's central DHCP instances reach it over TLS only. The environment supplies
# the Secrets fleet-site-dhcp-sync (key token) and fleet-site-dhcp-feed-tls
# (tls.crt, tls.key, ca.crt), never in Git, and the ConfigMap
# fleet-site-redfish-enrollment (key enrollment): the same synced Redfish
# enrollment the site's workers get. The feed serves, and takes reports from,
# only the enrollment's dhcpInstances. The Kea component and the Redfish
# lab's synchronized DHCP both use it.
# Service. The site's central DHCP instances reach it over TLS only. The
# environment supplies the Secrets fleet-site-dhcp-sync (key token) and
# fleet-site-dhcp-feed-tls (tls.crt, tls.key, ca.crt), never in Git, and the
# ConfigMap fleet-site-redfish-enrollment (key enrollment): the same synced
# Redfish enrollment the site's workers get. The feed serves, and takes
# reports from, only the enrollment's dhcpInstances, and starts only while
# the site's delivery declaration, the fleet-site-delivery ConfigMap, offers
# network boot. The Kea component and the Redfish lab's synchronized DHCP
# both use it.
apiVersion: kustomize.config.k8s.io/v1alpha1
kind: Component
resources:
Expand All @@ -22,7 +24,7 @@ patches:
name: dhcp-feed
image: "${FLEET_SITE_IMAGE}"
imagePullPolicy: IfNotPresent
command: [fleet-multiplane, dhcp-feed, -sync-token-file, /etc/fleet-dhcp/token, -tls-cert, /etc/fleet-dhcp-tls/tls.crt, -tls-key, /etc/fleet-dhcp-tls/tls.key]
command: [fleet-multiplane, dhcp-feed, -sync-token-file, /etc/fleet-dhcp/token, -tls-cert, /etc/fleet-dhcp-tls/tls.crt, -tls-key, /etc/fleet-dhcp-tls/tls.key, -delivery-methods, /etc/fleet-site-delivery/methods]
env:
- {name: FLEET_SITE_PROVIDER, value: redfish}
- {name: FLEET_BOOT_EVIDENCE, value: /var/lib/fleet-boot}
Expand All @@ -46,9 +48,15 @@ patches:
- {name: state, mountPath: /var/lib/fleet-boot, subPath: boot-evidence}
- {name: dhcp-sync-token, mountPath: /etc/fleet-dhcp, readOnly: true}
- {name: dhcp-feed-tls, mountPath: /etc/fleet-dhcp-tls, readOnly: true}
- {name: dhcp-feed-delivery, mountPath: /etc/fleet-site-delivery, readOnly: true}
- op: add
path: /spec/template/spec/volumes/-
value: {name: dhcp-sync-token, secret: {secretName: fleet-site-dhcp-sync, defaultMode: 0400}}
- op: add
path: /spec/template/spec/volumes/-
value: {name: dhcp-feed-tls, secret: {secretName: fleet-site-dhcp-feed-tls, defaultMode: 0400}}
# The site enrollment's delivery declaration: the feed starts only
# while it declares network boot.
- op: add
path: /spec/template/spec/volumes/-
value: {name: dhcp-feed-delivery, configMap: {name: fleet-site-delivery}}
19 changes: 18 additions & 1 deletion config/site/services/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@ spec:
ports:
- {name: http, port: 8080, targetPort: 8080, protocol: TCP}
---
# The site enrollment's boot delivery declaration: the methods this site
# offers, in its order of preference. The observer publishes it on every
# report handoff; the coordinator and the Metal provider read it there and
# keep no copy. The environment gives the JSON list base64-encoded, because
# Flux's substitution would drop the quotes around JSON text; the mounted
# file holds the JSON.
apiVersion: v1
kind: ConfigMap
metadata:
name: fleet-site-delivery
namespace: fleet-site
binaryData:
methods: ${FLEET_SITE_DELIVERY_METHODS}
---
# Admission parameter for kro-created worker Jobs: they must run the same
# digest-pinned image as these services.
apiVersion: v1
Expand Down Expand Up @@ -148,7 +162,7 @@ spec:
- name: observer
image: "${FLEET_SITE_IMAGE}"
imagePullPolicy: IfNotPresent
command: [fleet-multiplane, site-observer, --cell, "${FLEET_CELL}", --interval, 10s]
command: [fleet-multiplane, site-observer, --cell, "${FLEET_CELL}", --interval, 10s, --delivery-methods, /etc/fleet-site-delivery/methods]
env:
- {name: FLEET_LOCAL_VM_ACCEL, value: "${FLEET_LOCAL_VM_ACCEL}"}
securityContext:
Expand All @@ -161,6 +175,9 @@ spec:
limits: {memory: 128Mi}
volumeMounts:
- {name: state, mountPath: /var/lib/fleet-local, subPath: journal}
- {name: delivery, mountPath: /etc/fleet-site-delivery, readOnly: true}
volumes:
- name: state
persistentVolumeClaim: {claimName: fleet-site-state}
- name: delivery
configMap: {name: fleet-site-delivery}
12 changes: 8 additions & 4 deletions docs/development/device-custody.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,14 @@ operations guide describes how it runs in the [Redfish lab](../operations/redfis
it is still bound to the operation's own claim. The media service takes the
first-boot report only from it. A virtual
media installation's deadline is the sum of its windows.
- **Sites declare their methods.** `custody.Sites` gains `DeliveryMethods`,
the site's methods in its order of preference. Admission sees the methods
every serving site offers. The Metal provider selects from the same
declaration.
- **Sites declare their methods in their enrollment.** Each site's
enrollment lists its methods in its order of preference. The site reports
that declaration with its fence report, and `custody.Sites` returns it
through `DeliveryMethods`. The coordinator keeps no copy. Admission sees
the methods every serving site offers, and the Metal provider selects from
the same report. A site that has not reported a current, valid
declaration decides nothing: admission leaves the operation `Pending`, and
the provider creates no installation until the site reports one.
- **Admission checks the method** under the custody update: offered,
qualified, consistent with the other inputs, and every installer download
pinned by digest. The admission snapshot records the method, so a
Expand Down
Loading
Loading