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
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/base/registration, name: ghcr.io/datum-cloud/fleet, tag: "${{ needs.publish-container-image.outputs.tag }}" }
- { path: config/base/bmc-discovery, 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/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 }}" }
Expand Down
4 changes: 3 additions & 1 deletion build/manager.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ 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-registration ./cmd/fleet-registration \
&& 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-bmc-discovery ./cmd/fleet-bmc-discovery

FROM gcr.io/distroless/static-debian12:nonroot@sha256:afa5c872c891853ca7fcf1f12c3edb23f7eeef36189728842dd51042ff57f7ab
COPY --from=build /out/fleet-manager /fleet-manager
COPY --from=build /out/fleet-registration /fleet-registration
COPY --from=build /out/fleet-simulator /fleet-simulator
COPY --from=build /out/fleet-dhcp-sync /fleet-dhcp-sync
COPY --from=build /out/fleet-bmc-discovery /fleet-bmc-discovery
ENTRYPOINT ["/fleet-manager"]
79 changes: 79 additions & 0 deletions cmd/fleet-bmc-discovery/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// fleet-bmc-discovery reads what each Device's BMC reports over read-only
// Redfish GETs and writes it into Device status in one Milo project. It runs
// where the BMC network is reachable, as one replica without leader election.
// With --once it contacts each BMC once and prints the statuses it would
// write, writing nothing to Milo.
package main

import (
"context"
"errors"
"flag"
"fmt"
"os"

"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log/zap"

"go.datum.net/fleet/internal/bmcdiscovery"
)

func main() {
var configPath string
var once bool
flag.StringVar(&configPath, "config", "/etc/fleet/bmc-discovery/config.yaml", "discovery configuration file")
flag.BoolVar(&once, "once", false, "contact each BMC once, print the statuses that would be written, and write nothing to Milo")
zapOptions := zap.Options{Development: false}
zapOptions.BindFlags(flag.CommandLine)
flag.Parse()
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&zapOptions)))
if err := run(ctrl.SetupSignalHandler(), configPath, once); err != nil && !errors.Is(err, context.Canceled) {
fmt.Fprintln(os.Stderr, "fleet-bmc-discovery:", err)
os.Exit(1)
}
}

func run(ctx context.Context, configPath string, once bool) error {
config, err := bmcdiscovery.LoadConfig(configPath)
if err != nil {
return err
}
milo, err := clientcmd.BuildConfigFromFlags("", config.MiloKubeconfig)
if err != nil {
return fmt.Errorf("Milo project kubeconfig: %w", err)
}
var local *rest.Config
if config.LocalKubeconfig != "" {
local, err = clientcmd.BuildConfigFromFlags("", config.LocalKubeconfig)
} else {
local, err = rest.InClusterConfig()
}
if err != nil {
return fmt.Errorf("local cluster config: %w", err)
}
scheme, err := bmcdiscovery.NewScheme()
if err != nil {
return err
}
bmc := bmcdiscovery.RedfishBMC{Timeout: config.RequestTimeout.Duration}
if once {
devices, err := client.New(milo, client.Options{Scheme: scheme})
if err != nil {
return err
}
secrets, err := client.New(local, client.Options{Scheme: scheme})
if err != nil {
return err
}
// Reads only: RunOnce takes readers, so no write can reach Milo.
return bmcdiscovery.RunOnce(ctx, config, client.Reader(devices), client.Reader(secrets), bmc, os.Stdout)
}
mgr, err := bmcdiscovery.NewManager(config, milo, local, scheme, bmc)
if err != nil {
return err
}
return mgr.Start(ctx)
}
9 changes: 8 additions & 1 deletion config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,19 @@ A price change is a new `-v2` pricing, since a ServicePricing can't be changed.

`config/components/inventory` registers the operator-written `DeviceClaim` and
`Device` kinds of `fleet.datumapis.com` in Milo: their CRDs, ProtectedResources,
and inventory viewer and editor roles. The production `config/milo` and isolated
and inventory viewer, editor, manager, importer and discoverer roles. The production `config/milo` and isolated
non-production `config/milo-synthetic` roots include it; records
live in the provider project. `config/inventory` renders the CRDs alone for a
legacy management-cluster install and will be removed. See
[Planning and registering physical devices](../docs/operations/physical-inventory.md).

`config/base/bmc-discovery` runs read-only BMC discovery for one Milo project
in a cluster that can reach the BMC network: one replica, no leader election,
unprivileged. It is in no root here; the deploying repository applies it with
its namespace, image digest, Milo kubeconfig Secret and configuration.
`examples/` holds a synthetic credential Secret and a sidecar container
snippet. See [BMC discovery](../docs/operations/bmc-discovery.md).

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

Expand Down
11 changes: 11 additions & 0 deletions config/base/bmc-discovery/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Synthetic values; the deploying repository replaces them.
project: example-provider-project
miloKubeconfig: /var/run/fleet/milo/kubeconfig
deviceNamespaces: [default]
# credentialNamespace defaults to the pod's namespace ($POD_NAMESPACE).
interval: 1h
retryBase: 30s
minContactInterval: 1m
requestTimeout: 20s
concurrency: 4
healthProbeAddress: ":8081"
71 changes: 71 additions & 0 deletions config/base/bmc-discovery/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: fleet-bmc-discovery
spec:
# Exactly one replica and no leader election: two replicas would each
# contact every BMC and race on status. Recreate keeps a rollout from
# briefly running two.
replicas: 1
strategy:
type: Recreate
selector:
matchLabels:
app.kubernetes.io/name: fleet-bmc-discovery
template:
metadata:
labels:
app.kubernetes.io/name: fleet-bmc-discovery
spec:
serviceAccountName: fleet-bmc-discovery
# The token is needed to read credential Secrets in this namespace. Set
# localKubeconfig in the config and turn this off to use a mounted
# kubeconfig instead.
automountServiceAccountToken: true
securityContext:
runAsNonRoot: true
runAsUser: 65532
runAsGroup: 65532
fsGroup: 65532
seccompProfile:
type: RuntimeDefault
containers:
- name: bmc-discovery
image: ghcr.io/datum-cloud/fleet:latest
command: [/fleet-bmc-discovery]
args:
- --config=/etc/fleet/bmc-discovery/config.yaml
env:
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
ports:
- name: probes
containerPort: 8081
livenessProbe:
httpGet: {path: /healthz, port: probes}
readinessProbe:
httpGet: {path: /readyz, port: probes}
resources:
requests: {cpu: 20m, memory: 64Mi}
limits: {memory: 256Mi}
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop: [ALL]
volumeMounts:
- {name: config, mountPath: /etc/fleet/bmc-discovery, readOnly: true}
- {name: milo, mountPath: /var/run/fleet/milo, readOnly: true}
volumes:
- name: config
configMap:
name: fleet-bmc-discovery-config
# A kubeconfig for the one Milo project, bound to the
# fleet.datumapis.com-inventory-discoverer role. Environment-owned.
- name: milo
secret:
secretName: fleet-bmc-discovery-milo-kubeconfig
defaultMode: 0440
items: [{key: kubeconfig, path: kubeconfig}]
20 changes: 20 additions & 0 deletions config/base/bmc-discovery/examples/credential-secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Synthetic example of one BMC credential Secret. Not part of the base: create
# one per Device, in the namespace where discovery runs, outside Git.
apiVersion: v1
kind: Secret
metadata:
name: bmc-example-device-01
labels:
fleet.datumapis.com/bmc-credential: "true"
annotations:
fleet.datumapis.com/device-project: example-provider-project
fleet.datumapis.com/device-namespace: default
fleet.datumapis.com/device-name: example-device-01
type: Opaque
stringData:
username: example-operator
password: example-password
# Leave unset for first contact. Discovery then records the observed key in
# the Device's status.discovery.tls.publicKeySHA256 and sends nothing. Set
# it only after verifying that value out of band.
# tlsPublicKeySHA256: 0000000000000000000000000000000000000000000000000000000000000000
40 changes: 40 additions & 0 deletions config/base/bmc-discovery/examples/sidecar-container.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Synthetic snippet: discovery as one extra container in a pod that already
# reaches the BMC network (for example a VPN gateway pod). Merge it into that
# pod's spec.template.spec. It shares only the network namespace; it needs no
# privilege, capability or other container. The pod's service account needs
# the Role in ../rbac.yaml bound to it, or set localKubeconfig in the config
# and mount a kubeconfig instead.
containers:
- name: bmc-discovery
image: ghcr.io/datum-cloud/fleet@sha256:<digest>
command: [/fleet-bmc-discovery]
args: [--config=/etc/fleet/bmc-discovery/config.yaml]
env:
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
resources:
requests: {cpu: 20m, memory: 64Mi}
limits: {memory: 256Mi}
securityContext:
runAsNonRoot: true
runAsUser: 65532
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop: [ALL]
seccompProfile:
type: RuntimeDefault
volumeMounts:
- {name: bmc-discovery-config, mountPath: /etc/fleet/bmc-discovery, readOnly: true}
- {name: bmc-discovery-milo, mountPath: /var/run/fleet/milo, readOnly: true}
volumes:
- name: bmc-discovery-config
configMap:
name: fleet-bmc-discovery-config
- name: bmc-discovery-milo
secret:
secretName: fleet-bmc-discovery-milo-kubeconfig
defaultMode: 0440
items: [{key: kubeconfig, path: kubeconfig}]
14 changes: 14 additions & 0 deletions config/base/bmc-discovery/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
# Read-only BMC discovery for one Milo project. Apply it to a cluster from
# which the BMC network is reachable, in the namespace that holds the
# credential Secrets; the deploying repository sets that namespace, the
# image digest, the Milo kubeconfig Secret and the config values.
# See docs/operations/bmc-discovery.md.
resources:
- rbac.yaml
- deployment.yaml
configMapGenerator:
- name: fleet-bmc-discovery-config
files:
- config.yaml
28 changes: 28 additions & 0 deletions config/base/bmc-discovery/rbac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: fleet-bmc-discovery
---
# Reads credential Secrets in its own namespace only. Kubernetes RBAC cannot
# narrow this to the labelled Secrets, so keep discovery in a namespace that
# holds nothing else it should not read.
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: fleet-bmc-discovery-credentials
rules:
- apiGroups: [""]
resources: [secrets]
verbs: [get, list, watch]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: fleet-bmc-discovery-credentials
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: fleet-bmc-discovery-credentials
subjects:
- kind: ServiceAccount
name: fleet-bmc-discovery
Loading
Loading