Skip to content
Closed
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
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ jobs:
with: {go-version-file: go.mod, cache: true}
- uses: imranismail/setup-kustomize@v2
with: {kustomize-version: 5.8.1}
# Runs the manager's multi-project end-to-end test against real API
# servers; without these assets it is skipped.
- name: Install envtest assets
run: echo "KUBEBUILDER_ASSETS=$(go run sigs.k8s.io/controller-runtime/tools/setup-envtest@v0.25.2 use 1.37.0 -p path)" >> "$GITHUB_ENV"
- run: go test ./...
- run: go test -race ./...
- run: go vet ./...
Expand All @@ -22,6 +26,7 @@ jobs:
- run: kustomize build config/milo >/dev/null
- run: kustomize build config/overlays/management-plane >/dev/null
- run: kustomize build config/overlays/synthetic-staging >/dev/null
- run: kustomize build config/inventory-observer >/dev/null
- run: ./hack/validate-synthetic-staging-render.sh
- run: ./hack/validate-overlay-isolation.sh
- run: ./hack/test-overlay-isolation.sh
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ jobs:
images: |
- { path: config/base/manager, name: ghcr.io/datum-cloud/fleet, tag: "${{ needs.publish-container-image.outputs.tag }}" }
- { path: config/overlays/synthetic-staging, name: ghcr.io/datum-cloud/fleet, tag: "${{ needs.publish-container-image.outputs.tag }}" }
- { path: config/inventory-observer, name: ghcr.io/datum-cloud/fleet, tag: "${{ needs.publish-container-image.outputs.tag }}" }
- { path: config/components/consumer-ui-plugin, name: ghcr.io/datum-cloud/fleet-consumer-ui-plugin, tag: "${{ needs.publish-consumer-ui-plugin-image.outputs.tag }}" }
- { path: config/components/provider-ui-plugin, name: ghcr.io/datum-cloud/fleet-provider-ui-plugin, tag: "${{ needs.publish-provider-ui-plugin-image.outputs.tag }}" }
secrets: inherit
4 changes: 3 additions & 1 deletion build/manager.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ COPY cmd/ ./cmd/
COPY internal/ ./internal/
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -trimpath -ldflags='-s -w' -o /out/fleet-manager ./cmd/fleet-manager \
&& CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -trimpath -ldflags='-s -w' -o /out/fleet-simulator ./cmd/fleet-simulator \
&& CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -trimpath -ldflags='-s -w' -o /out/fleet-dhcp-sync ./cmd/fleet-dhcp-sync
&& CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -trimpath -ldflags='-s -w' -o /out/fleet-dhcp-sync ./cmd/fleet-dhcp-sync \
&& CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -trimpath -ldflags='-s -w' -o /out/fleet-inventory-observer ./cmd/fleet-inventory-observer

FROM gcr.io/distroless/static-debian12:nonroot@sha256:afa5c872c891853ca7fcf1f12c3edb23f7eeef36189728842dd51042ff57f7ab
COPY --from=build /out/fleet-manager /fleet-manager
COPY --from=build /out/fleet-simulator /fleet-simulator
COPY --from=build /out/fleet-dhcp-sync /fleet-dhcp-sync
COPY --from=build /out/fleet-inventory-observer /fleet-inventory-observer
ENTRYPOINT ["/fleet-manager"]
92 changes: 92 additions & 0 deletions cmd/fleet-inventory-observer/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// fleet-inventory-observer refreshes InventoryObservation status from NetBox
// once and exits. It reads NetBox with GET requests only and writes only the
// status subresource of existing observations in one namespace.
package main

import (
"context"
"errors"
"flag"
"fmt"
"log/slog"
"net/http"
"os"
"os/signal"
"syscall"
"time"

"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"

inventoryv1 "go.datum.net/fleet/internal/api/inventory/v1alpha1"
"go.datum.net/fleet/internal/inventoryobserver"
"go.datum.net/fleet/internal/netbox"
)

func main() {
var namespace, origin, tokenFile string
var timeout time.Duration
flag.StringVar(&namespace, "namespace", os.Getenv("POD_NAMESPACE"), "namespace holding InventoryObservations")
flag.StringVar(&origin, "netbox-url", os.Getenv("NETBOX_URL"), "NetBox origin, https://host[:port]")
flag.StringVar(&tokenFile, "netbox-token-file", "", "file holding a read-only NetBox API token")
flag.DurationVar(&timeout, "timeout", 2*time.Minute, "deadline for the whole refresh")
flag.Parse()
logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop()
ctx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()
if err := run(ctx, logger, namespace, origin, tokenFile); err != nil {
logger.Error("inventory observation refresh incomplete", "error", err)
os.Exit(1)
}
}

func run(ctx context.Context, logger *slog.Logger, namespace, origin, tokenFile string) error {
if namespace == "" || origin == "" || tokenFile == "" {
return errors.New("--namespace, --netbox-url, and --netbox-token-file are required")
}
source, err := netbox.NewClient(origin, func() (string, error) {
data, err := os.ReadFile(tokenFile)
return string(data), err
}, &http.Client{Timeout: 30 * time.Second})
if err != nil {
return err
}
scheme := runtime.NewScheme()
if err := inventoryv1.AddToScheme(scheme); err != nil {
return err
}
config, err := ctrl.GetConfig()
if err != nil {
return err
}
kube, err := client.New(config, client.Options{Scheme: scheme})
if err != nil {
return err
}
observer := &inventoryobserver.Observer{Client: kube, Namespace: namespace, NetBox: source}
results, err := observer.RefreshAll(ctx)
if err != nil {
return err
}
failed := 0
for _, result := range results {
attrs := []any{"observation", result.Name, "reason", result.Reason}
if result.WriteErr != nil {
attrs = append(attrs, "writeError", result.WriteErr.Error())
}
if result.Succeeded() {
logger.Info("observation refreshed", attrs...)
continue
}
failed++
logger.Warn("observation not refreshed", append(attrs, "message", result.Message)...)
}
logger.Info("refresh finished", "observations", len(results), "notRefreshed", failed)
if failed > 0 {
return fmt.Errorf("%d of %d observations were not refreshed", failed, len(results))
}
return nil
}
7 changes: 7 additions & 0 deletions config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ API servers and must be reconciled independently.
| `config/overlays/management-plane` | Fleet management cluster | Fleet CRDs, the manager workload and RBAC, private-record namespaces, and admission fences |
| `config/overlays/synthetic-staging` | Fleet management cluster (non-production only) | Management-plane resources plus an explicit synthetic allocator/provider integration |

`config/inventory-observer` is an opt-in root for the Fleet management cluster.
It holds the observed-only `InventoryObservation` CRD and a NetBox observer
CronJob with namespace-scoped status-only RBAC. The environment supplies the
`fleet-inventory-observer` ConfigMap (`netboxURL`) and the
`fleet-inventory-observer-netbox` Secret (`token`). Neither production root
references it. See [Observational inventory import](../docs/operations/inventory-observation.md).

`config/standalone` remains a synthetic, same-cluster test environment. It must
not be referenced by either production root.

Expand Down
57 changes: 57 additions & 0 deletions config/inventory-observer/crd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: inventoryobservations.fleet.datumapis.com
spec:
group: fleet.datumapis.com
names: {kind: InventoryObservation, listKind: InventoryObservationList, plural: inventoryobservations, singular: inventoryobservation, shortNames: [invobs]}
scope: Namespaced
versions:
- name: v1alpha1
served: true
storage: true
subresources: {status: {}}
additionalPrinterColumns:
- {name: System, type: string, jsonPath: .spec.source.system}
- {name: ID, type: integer, jsonPath: .spec.source.id}
- {name: Name, type: string, jsonPath: .status.facts.name}
- {name: Observed, type: string, jsonPath: '.status.conditions[?(@.type=="Observed")].status'}
- {name: Reason, type: string, jsonPath: '.status.conditions[?(@.type=="Observed")].reason'}
- {name: Observed At, type: date, jsonPath: .status.observedAt}
- {name: Trust, type: string, priority: 1, jsonPath: .status.trustProfile}
schema:
openAPIV3Schema:
type: object
required: [spec]
properties:
apiVersion: {type: string}
kind: {type: string}
metadata: {type: object}
spec:
type: object
required: [source]
x-kubernetes-validations:
- rule: self.source == oldSelf.source
message: the observed source identity is immutable; create a new observation instead
properties:
source:
type: object
required: [system, kind, id]
properties:
system: {type: string, enum: [NetBox]}
kind: {type: string, enum: [Device]}
id: {type: integer, format: int64, minimum: 1}
expectedName: {type: string, minLength: 1, maxLength: 253}
status:
type: object
properties:
observedGeneration: {type: integer, format: int64}
trustProfile: {type: string, enum: [ObservedOnly-v1]}
lastAttemptTime: {type: string, format: date-time}
observedAt: {type: string, format: date-time}
sourceUpdatedAt: {type: string, format: date-time}
factsDigest: {type: string}
facts: {type: object, x-kubernetes-preserve-unknown-fields: true}
conditions:
type: array
items: {type: object, x-kubernetes-preserve-unknown-fields: true}
77 changes: 77 additions & 0 deletions config/inventory-observer/cronjob.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
apiVersion: batch/v1
kind: CronJob
metadata:
name: fleet-inventory-observer
namespace: fleet-system
labels:
app.kubernetes.io/name: fleet-inventory-observer
app.kubernetes.io/component: inventory-observer
spec:
schedule: "*/15 * * * *"
concurrencyPolicy: Forbid
startingDeadlineSeconds: 600
successfulJobsHistoryLimit: 1
failedJobsHistoryLimit: 3
jobTemplate:
spec:
backoffLimit: 0
activeDeadlineSeconds: 300
ttlSecondsAfterFinished: 86400
template:
metadata:
labels:
app.kubernetes.io/name: fleet-inventory-observer
app.kubernetes.io/component: inventory-observer
spec:
serviceAccountName: fleet-inventory-observer
restartPolicy: Never
securityContext:
runAsNonRoot: true
runAsUser: 65532
runAsGroup: 65532
fsGroup: 65532
seccompProfile:
type: RuntimeDefault
containers:
- name: observer
image: ghcr.io/datum-cloud/fleet:latest
imagePullPolicy: IfNotPresent
command: [/fleet-inventory-observer]
args:
- --namespace=$(POD_NAMESPACE)
- --netbox-url=$(NETBOX_URL)
- --netbox-token-file=/var/run/fleet/netbox/token
- --timeout=4m
env:
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: NETBOX_URL
valueFrom:
configMapKeyRef:
name: fleet-inventory-observer
key: netboxURL
resources:
requests:
cpu: 10m
memory: 32Mi
limits:
memory: 128Mi
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop: [ALL]
volumeMounts:
- name: netbox-token
mountPath: /var/run/fleet/netbox
readOnly: true
volumes:
- name: netbox-token
secret:
secretName: fleet-inventory-observer-netbox
defaultMode: 0440
items:
- key: token
path: token
6 changes: 6 additions & 0 deletions config/inventory-observer/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- crd.yaml
- rbac.yaml
- cronjob.yaml
32 changes: 32 additions & 0 deletions config/inventory-observer/rbac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: fleet-inventory-observer
namespace: fleet-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: fleet-inventory-observer
namespace: fleet-system
rules:
- apiGroups: [fleet.datumapis.com]
resources: [inventoryobservations]
verbs: [get, list]
- apiGroups: [fleet.datumapis.com]
resources: [inventoryobservations/status]
verbs: [update]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: fleet-inventory-observer
namespace: fleet-system
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: fleet-inventory-observer
subjects:
- kind: ServiceAccount
name: fleet-inventory-observer
namespace: fleet-system
2 changes: 1 addition & 1 deletion docs/architecture/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ processes or service-catalog entries.
| --- | --- | --- |
| `metal.datumapis.com` | `MachineClass`: offerings and consumer references. `MachineProfile`: hardware requirements. `MachineCapacity`: provider supply. `Machine`: customer allocation and runtime intent. `MachineAllocation`: protected allocation identity. `Installation`: immutable OS installation or reinstall request. | Six alpha CRDs at `v1alpha1`. Production admission and real providers remain incomplete. |
| `provider.metal.datumapis.com` | Proposed `MachineOffering` owns installation/management capability policy; `MachineOfferingAssignment` controls acquisition access. MachineClass becomes only a one-hop published consumer view; MachineProfile remains immutable requirements in Metal. | Proposed target design, not implemented by the six alpha CRDs above. |
| `fleet.datumapis.com` | Physical inventory: `Facility`, `Rack`, `DeviceClaim`, `Device`, `Cable`, and `PowerFeed`. Physical preparation and provider execution remain operator responsibilities. | Proposed inventory APIs; no physical inventory CRDs or real provider executor are implemented here. |
| `fleet.datumapis.com` | Physical inventory: `Facility`, `Rack`, `DeviceClaim`, `Device`, `Cable`, and `PowerFeed`. Physical preparation and provider execution remain operator responsibilities. `InventoryObservation` holds observed-only evidence read from an external inventory system. | Proposed inventory APIs; no physical inventory CRDs or real provider executor are implemented here. `InventoryObservation` is an implemented alpha CRD in the opt-in [observer root](../operations/inventory-observation.md), outside the production roots; nothing consumes it. |
| `coordination.fleet.datumapis.com` | Intended management-to-location execution handoff, retaining exact allocation identity, location, admitted inputs, release intent, and execution evidence. `MachineAllocationHandoff` is a candidate resource. | Architecture decision only on the current main implementation: no coordination CRD or cell controller is packaged. Replaces the earlier prototype name `internal.fleet.datumapis.com`. |

MachineCapacity and MachineAllocation belong to the Metal allocation contract
Expand Down
18 changes: 17 additions & 1 deletion docs/development/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ Milo IAM, service, and quota boundaries; packaging is not runtime readiness.

The allocation APIs now use `metal.datumapis.com/v1alpha1`. Milo registers the
Bare Metal service as `metal`; entitlement and location-availability readers use
that reference. Physical Device references use `fleet.datumapis.com`. The
that reference. Physical Device references use `fleet.datumapis.com`; that group
implements only the observed-only `InventoryObservation` kind today. The
[API architecture](../architecture/README.md) documents the proposed coordination group,
control-plane placement, and rollout constraints. Group renaming does not migrate
stored allocations or establish live acceptance.
Expand Down Expand Up @@ -587,6 +588,21 @@ The persisted schema and HTTP endpoints are internal alpha interfaces. No
compatibility promise exists yet. The process fails closed if retained state is
corrupt or uses an unsupported schema version.

## Inventory observation

`internal/api/inventory/v1alpha1` defines `InventoryObservation`.
`internal/netbox` is a read-only NetBox client, and `internal/inventoryobserver`
refreshes observation status from it. `cmd/fleet-inventory-observer` runs one
refresh and exits. `config/inventory-observer` packages the CRD, a
namespace-scoped Role that grants only `get`/`list` on observations and `update`
on their status, and a CronJob. No production root includes it, and no
controller reads observations. Unit tests cover NetBox decoding and transport
limits, identity guards, retained facts on failure, write conflicts, write
scope, CRD validation, and RBAC scope. With `KUBEBUILDER_ASSETS` set, an
envtest test runs the observer as its packaged service account against a real
API server. No test runs against a live NetBox. See
[Observational inventory import](../operations/inventory-observation.md).

## Build, test, and run

Run the implemented checks from the repository root:
Expand Down
1 change: 1 addition & 0 deletions docs/operations/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ integrations. Real provider support and live Milo acceptance tests are incomplet
| Exercise Milo, Karmada and cell-local PXE end to end with one command | [Multi-plane acceptance](multiplane.md) (`task multiplane:acceptance`) | Native project routing, federation delivery/reflection, partition, [Kubernetes site execution](site-execution.md) (Flux-owned shared services, kro-created per-operation Jobs) with worker Pod/Job interruption, delivery and reflection faults, wrong location, cleanup and reuse; every service [installed by per-cluster Flux](gitops.md) from a source built from the checkout; production authority unqualified |
| Drive the same pipeline through Redfish instead of libvirt | [Redfish-mode acceptance](redfish-lab.md) (`task multiplane:redfish-acceptance`) | Redfish executor discovery, one-time PXE/disk boot overrides, power, lost-response recovery and a booted wipe cleanup, against the unmodified DMTF Redfish Interface Emulator with a lab-only libvirt adapter and two persistent lab VMs; synthetic credentials and networking; not physical BMC or hardware qualification |
| Publish physical-side DHCP reservations for network boot | [Boot network](boot-network.md) | Per-asset BMC endpoints and provisioning attachments, a reservation feed that exists only while a boot is admitted, served and withdrawn evidence from the DHCP owner's Kea synchronizer; unit tested, not exercised at a site |
| Import NetBox device records as observed-only evidence | [Observational inventory import](inventory-observation.md) | Allowlisted NetBox facts in `InventoryObservation` status with retained facts on failure and identity guards; no Device, capacity, or hardware effect; unit tested |
| Render deployment bundles and supply environment inputs | [Deployment manifests](../../config/README.md) | Packaging and security boundaries, not runtime readiness |
| Exercise Milo-routed synthetic staging | [Synthetic staging configuration](../../config/README.md#environment-owned-inputs) | Restricted synthetic publication and lifecycle behavior, not production authority |
| Validate Milo acceptance packaging and evidence | [Milo acceptance harness](../../test/acceptance/milo/README.md) | Fail-closed preflight and sanitized evidence; live acceptance remains blocked |
Expand Down
Loading
Loading