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
8 changes: 5 additions & 3 deletions cmd/fleet-manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type managerFlags struct {
syntheticProviderProjectName, syntheticPublishedClassName string
syntheticPublishedProfileName string
syntheticCoordinatorCertDir, syntheticReleaseCertDir string
syntheticProjectorCertDir string
syntheticEnrollmentFile, syntheticDeviceNamespace string
}

Expand All @@ -55,6 +56,7 @@ func bindFlags(flags *flag.FlagSet) *managerFlags {
flags.StringVar(&f.syntheticTokenFile, "synthetic-provider-token-file", "", "file containing the synthetic provider site's bearer token")
flags.StringVar(&f.syntheticCoordinatorCertDir, "synthetic-coordinator-client-cert-dir", "", "directory holding the custody coordinator's Milo client certificate as tls.crt and tls.key")
flags.StringVar(&f.syntheticReleaseCertDir, "synthetic-release-client-cert-dir", "", "directory holding the release controller's Milo client certificate as tls.crt and tls.key")
flags.StringVar(&f.syntheticProjectorCertDir, "synthetic-projector-client-cert-dir", "", "directory holding the capacity projector's Milo client certificate as tls.crt and tls.key")
flags.StringVar(&f.syntheticEnrollmentFile, "synthetic-site-enrollment-file", "", "JSON enrollment of the Devices the synthetic provider site serves")
flags.StringVar(&f.syntheticDeviceNamespace, "synthetic-device-namespace", "default", "namespace of the Devices, capacities and allocations in the provider project")
flags.StringVar(&f.syntheticLocation, "synthetic-location", "us-central-1", "only location accepted by synthetic staging")
Expand All @@ -73,13 +75,13 @@ func (f *managerFlags) validate() error {
return errors.Join(errFlags, errors.New("--config and --leader-election-namespace are required"))
}
if !f.syntheticStaging {
if f.syntheticConsumerProjectName != "" || f.syntheticProviderProjectName != "" || f.syntheticPublishedClassName != "" || f.syntheticPublishedProfileName != "" || f.syntheticTokenFile != "" || f.syntheticCoordinatorCertDir != "" || f.syntheticReleaseCertDir != "" || f.syntheticEnrollmentFile != "" {
if f.syntheticConsumerProjectName != "" || f.syntheticProviderProjectName != "" || f.syntheticPublishedClassName != "" || f.syntheticPublishedProfileName != "" || f.syntheticTokenFile != "" || f.syntheticCoordinatorCertDir != "" || f.syntheticReleaseCertDir != "" || f.syntheticProjectorCertDir != "" || f.syntheticEnrollmentFile != "" {
return errors.Join(errFlags, errors.New("synthetic flags require --synthetic-staging"))
}
return nil
}
if f.syntheticTokenFile == "" || f.syntheticConsumerProjectName == "" || f.syntheticCoordinatorCertDir == "" || f.syntheticReleaseCertDir == "" || f.syntheticEnrollmentFile == "" {
return errors.Join(errFlags, errors.New("--synthetic-staging requires the provider site token, the coordinator and release controller client certificates, the site enrollment, and --synthetic-consumer-project-name"))
if f.syntheticTokenFile == "" || f.syntheticConsumerProjectName == "" || f.syntheticCoordinatorCertDir == "" || f.syntheticReleaseCertDir == "" || f.syntheticProjectorCertDir == "" || f.syntheticEnrollmentFile == "" {
return errors.Join(errFlags, errors.New("--synthetic-staging requires the provider site token, the coordinator, release controller and capacity projector client certificates, the site enrollment, and --synthetic-consumer-project-name"))
}
if f.syntheticProviderProjectName != "" && (f.syntheticPublishedClassName == "" || f.syntheticPublishedProfileName == "") {
return errors.Join(errFlags, errors.New("--synthetic-provider-project-name requires the published class and profile names"))
Expand Down
2 changes: 1 addition & 1 deletion cmd/fleet-manager/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestSyntheticFlagsRequireAndScopeStaging(t *testing.T) {
if err := parse(t, append(required, "--synthetic-staging", "--synthetic-provider-token-file=/t")...); !errors.Is(err, errFlags) {
t.Fatalf("staging without a consumer project: %v", err)
}
components := []string{"--synthetic-coordinator-client-cert-dir=/c", "--synthetic-release-client-cert-dir=/r", "--synthetic-site-enrollment-file=/e"}
components := []string{"--synthetic-coordinator-client-cert-dir=/c", "--synthetic-release-client-cert-dir=/r", "--synthetic-projector-client-cert-dir=/p", "--synthetic-site-enrollment-file=/e"}
staging := append(append(required, "--synthetic-staging", "--synthetic-provider-token-file=/t", "--synthetic-consumer-project-name=consumer"), components...)
if err := parse(t, staging...); err != nil {
t.Fatal(err)
Expand Down
16 changes: 12 additions & 4 deletions cmd/fleet-manager/synthetic.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"

"go.datum.net/fleet/internal/allocation"
"go.datum.net/fleet/internal/capacity"
"go.datum.net/fleet/internal/custody"
"go.datum.net/fleet/internal/delivery"
"go.datum.net/fleet/internal/site/fixture"
Expand Down Expand Up @@ -49,14 +50,18 @@ func syntheticCustody(ctx context.Context, scheme *runtime.Scheme, providerConfi
if err != nil {
return nil, nil, nil, fmt.Errorf("release controller credential: %w", err)
}
clients := make([]ctrlclient.Client, 3)
for index, config := range []*rest.Config{providerConfig, coordinatorConfig, releaseConfig} {
projectorConfig, err := withClientCert(providerConfig, flags.syntheticProjectorCertDir)
if err != nil {
return nil, nil, nil, fmt.Errorf("capacity projector credential: %w", err)
}
clients := make([]ctrlclient.Client, 4)
for index, config := range []*rest.Config{providerConfig, coordinatorConfig, releaseConfig, projectorConfig} {
// Decisions read through to the API server, never a cache.
if clients[index], err = ctrlclient.New(config, ctrlclient.Options{Scheme: scheme}); err != nil {
return nil, nil, nil, err
}
}
provider, coordinatorClient, releaseClient := clients[0], clients[1], clients[2]
provider, coordinatorClient, releaseClient, projectorClient := clients[0], clients[1], clients[2], clients[3]
providerCreator, err := allocation.Creator(ctx, providerConfig)
if err != nil {
return nil, nil, nil, fmt.Errorf("identify the Metal provider: %w", err)
Expand Down Expand Up @@ -91,14 +96,17 @@ func syntheticCustody(ctx context.Context, scheme *runtime.Scheme, providerConfi
}
coordinator := &custody.Coordinator{Client: coordinatorClient, Registry: registry, Sites: sites, Config: custody.Config{Namespace: namespace, Principals: principals}}
log := ctrl.Log.WithName("custody")
loop := &delivery.Loop{Client: coordinatorClient, Coordinator: coordinator, Namespace: namespace,
cleaning := func(context.Context, string) (string, error) { return custody.SpecDigest(syntheticCleaningPolicy) }
projector := &capacity.Projector{Reader: projectorClient, Writer: projectorClient, Namespace: namespace, Cleaning: cleaning}
loop := &delivery.Loop{Client: coordinatorClient, Coordinator: coordinator, Namespace: namespace, Capacity: projector,
Courier: &delivery.Courier{Client: coordinatorClient, Registry: registry, Coordinator: coordinator, Sites: sites, Namespace: namespace},
OnError: func(err error) { log.Info("coordinator pass incomplete", "error", err.Error()) }}
allocator := &allocation.Allocator{
Provider: provider, ProviderCreator: providerCreator,
Releaser: releaseClient, ReleaseCreator: releaseCreator,
Custody: coordinator, Namespace: namespace,
Cleaning: func(string) (string, error) { return custody.SpecDigest(syntheticCleaningPolicy) },
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"},
}
Expand Down
10 changes: 7 additions & 3 deletions cmd/fleet-multiplane/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,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", "allocate", "install", "admit-install", "admit-install-b", "release", "release-b", "reuse", "recovery-mismatch", "probe-unallocatable", "tenant-isolation":
case "seed", "commission", "allocate", "install", "admit-install", "admit-install-b", "release", "release-b", "reuse", "recovery-mismatch", "probe-unallocatable", "tenant-isolation":
return phase(os.Args[1], *configPath, *once)
case "redfish-probe":
return probe(*endpoint, *credentials, *system, *uuid, *pin, *clientID)
Expand Down Expand Up @@ -146,8 +146,12 @@ func phase(name, configPath string, once bool) error {
if err != nil {
return err
}
// The Redfish lab serves a firmware inventory; the local VM has none.
if redfishMode() {
r.PlanFirmware = multiplane.LabFirmware
}
action := map[string]func(context.Context) error{
"allocate": r.Allocate, "admit-install": r.AdmitInstall, "install": r.Install,
"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,
}[name]
Expand All @@ -164,7 +168,7 @@ func phase(name, configPath string, once bool) error {
fmt.Println("Installation admitted and delivered; its result remains Unknown")
return nil
}
if err == nil && (name == "recovery-mismatch" || name == "probe-unallocatable" || name == "tenant-isolation") {
if err == nil && (name == "commission" || name == "recovery-mismatch" || name == "probe-unallocatable" || name == "tenant-isolation") {
return nil
}
if err == nil {
Expand Down
11 changes: 9 additions & 2 deletions cmd/fleet-multiplane/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func siteRunner(_ context.Context, config *rest.Config, cell string, store *site
return nil, err
}
runner.Access = fixture.Access{Enrollment: enrollment}
runner.Kinds = map[string]site.Kind{"DeviceInstallation": vmwork.Installation{Config: vm}, "DeviceWipe": vmwork.Wipe{Config: vm}}
runner.Kinds = map[string]site.Kind{"DeviceInstallation": vmwork.Installation{Config: vm}, "DeviceWipe": vmwork.Wipe{Config: vm}, "DeviceCommissioning": vmwork.Commissioning{Config: vm}}
return runner, nil
}
work, enrollment, err := redfishConfig()
Expand All @@ -206,7 +206,14 @@ func siteRunner(_ context.Context, config *rest.Config, cell string, store *site
targets[target.Device] = target
}
runner.Access = site.RedfishAccess{Credentials: site.SecretCredentials{Reader: reader, Namespace: namespace, Project: project}, Targets: targets}
runner.Kinds = map[string]site.Kind{"DeviceInstallation": redfishwork.Installation{Config: work}, "DeviceWipe": redfishwork.Wipe{Config: work}}
// The site serves one boot image, which also burns in.
image, err := siteImage()
if err != nil {
return nil, err
}
_, burnIn, _ := strings.Cut(image, "@")
runner.Kinds = map[string]site.Kind{"DeviceInstallation": redfishwork.Installation{Config: work}, "DeviceWipe": redfishwork.Wipe{Config: work},
"DeviceCommissioning": redfishwork.Commissioning{Config: work, BurnInDigest: burnIn}}
return runner, nil
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/fleet-simulator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func main() {
defer stop()
results := site.NewResults(store)
runner := &site.Runner{Site: siteName, Store: store, Results: results, Access: fixture.Access{Enrollment: enrollment},
Kinds: map[string]site.Kind{"DeviceInstallation": simwork.Installation{}, "DeviceWipe": simwork.Wipe{}}}
Kinds: map[string]site.Kind{"DeviceInstallation": simwork.Installation{}, "DeviceWipe": simwork.Wipe{}, "DeviceCommissioning": simwork.Commissioning{}}}
dispatcher := &siteapi.Dispatcher{Runner: runner, Context: ctx, Logger: logger}
server := newServer(address, siteapi.Handler(dispatcher, store, results, func() (string, error) { return readToken(tokenPath) }), logger)
if discover {
Expand Down
68 changes: 60 additions & 8 deletions cmd/fleet-standalone-smoke/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
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/capacity"
"go.datum.net/fleet/internal/custody"
"go.datum.net/fleet/internal/delivery"
"go.datum.net/fleet/internal/site/siteapi"
Expand All @@ -41,8 +42,12 @@ const (

func main() {
options := standalone.DefaultOptions()
var phase, coordinatorToken, releaseToken, siteURL, siteToken, siteName, devices string
flag.StringVar(&phase, "phase", "", "required: allocate, install, reinstall, release, or coordinate")
var phase, coordinatorToken, releaseToken, siteURL, siteToken, siteName, devices, projectorToken, authorToken, approverToken, operatorToken string
flag.StringVar(&phase, "phase", "", "required: commission, allocate, install, reinstall, release, or coordinate")
flag.StringVar(&projectorToken, "projector-token-file", "", "the capacity projector's ServiceAccount token (coordinate)")
flag.StringVar(&authorToken, "plan-author-token-file", "", "the plan author's ServiceAccount token (commission)")
flag.StringVar(&approverToken, "plan-approver-token-file", "", "the plan approver's ServiceAccount token (commission)")
flag.StringVar(&operatorToken, "operator-token-file", "", "the commissioning operator's ServiceAccount token (commission)")
flag.StringVar(&coordinatorToken, "coordinator-token-file", "", "the custody coordinator's ServiceAccount token (phases)")
flag.StringVar(&releaseToken, "release-token-file", "", "the release controller's ServiceAccount token (phases)")
flag.StringVar(&siteURL, "site-url", "http://fleet-simulator:8080", "the simulator site's API (coordinate)")
Expand All @@ -59,7 +64,7 @@ func main() {
registry, err := custody.DefaultRegistry()
must(err)
if phase == "coordinate" {
must(coordinate(ctx, config, registry, options.ProviderNamespace, siteName, siteURL, siteToken, strings.Split(devices, ",")))
must(coordinate(ctx, config, registry, options.ProviderNamespace, siteName, siteURL, siteToken, projectorToken, strings.Split(devices, ",")))
return
}
if coordinatorToken == "" || releaseToken == "" {
Expand All @@ -76,24 +81,35 @@ func main() {
must(err)
releaseCreator, err := allocation.Creator(ctx, releaseConfig)
must(err)
offers := &capacity.Projector{Reader: provider, Namespace: options.ProviderNamespace, Cleaning: fixtureResolver}
allocator := &allocation.Allocator{
Provider: provider, ProviderCreator: providerCreator,
Releaser: releaseClient, ReleaseCreator: releaseCreator,
Custody: &custody.Coordinator{Client: coordinatorClient, Registry: registry, Config: custody.Config{Namespace: options.ProviderNamespace, Principals: principals()}},
Namespace: options.ProviderNamespace,
Cleaning: fixtureCleaning,
Capacity: offers,
// The fixture Device's boot NIC and the simulator's one enrolled disk.
BootInterface: "primary", TargetDisks: []string{"disk-0"},
}
must(standalone.Runner{Client: provider, Allocator: allocator, Options: options}.Run(ctx, phase))
runner := standalone.Runner{Client: provider, Allocator: allocator, Options: options}
if phase == standalone.PhaseCommission {
runner.Staff, err = staff(ctx, config, authorToken, approverToken, operatorToken)
must(err)
}
must(runner.Run(ctx, phase))
fmt.Printf("standalone synthetic smoke phase %s completed\n", phase)
}

// 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 string, devices []string) error {
if tokenFile == "" {
return errors.New("coordinate needs the site token file")
func coordinate(ctx context.Context, config *rest.Config, registry *custody.Registry, namespace, siteName, siteURL, tokenFile, projectorToken string, devices []string) error {
if tokenFile == "" || projectorToken == "" {
return errors.New("coordinate needs the site and capacity projector token files")
}
projectorClient, err := newClient(withToken(config, projectorToken))
if err != nil {
return err
}
api, err := newClient(config)
if err != nil {
Expand All @@ -111,12 +127,48 @@ func coordinate(ctx context.Context, config *rest.Config, registry *custody.Regi
}
coordinator := &custody.Coordinator{Client: api, Registry: registry, Sites: sites, Config: custody.Config{Namespace: namespace, Principals: principals()}}
logger := slog.New(slog.NewJSONHandler(os.Stderr, nil))
loop := &delivery.Loop{Client: api, Coordinator: coordinator, Namespace: namespace, Courier: &delivery.Courier{Client: api, Registry: registry, Coordinator: coordinator, Sites: sites, Namespace: namespace},
projector := &capacity.Projector{Reader: projectorClient, Writer: projectorClient, Namespace: namespace, Cleaning: fixtureResolver}
loop := &delivery.Loop{Client: api, Coordinator: coordinator, Namespace: namespace, Capacity: projector, Courier: &delivery.Courier{Client: api, Registry: registry, Coordinator: coordinator, Sites: sites, Namespace: namespace},
OnError: func(err error) { logger.Info("coordinator pass incomplete", "error", err.Error()) }}
logger.Info("custody coordinator running", "namespace", namespace, "site", siteName)
return loop.Run(ctx)
}

// staff returns the commissioning phase's three people, each with their own
// token.
func staff(ctx context.Context, config *rest.Config, author, approver, operator string) (*standalone.Staff, error) {
if author == "" || approver == "" || operator == "" {
return nil, errors.New("commission needs the plan author, approver and operator token files")
}
out := &standalone.Staff{}
for _, person := range []struct {
token string
client *client.Client
creator *ops.Creator
}{{author, &out.Author, &out.AuthorCreator}, {approver, &out.Approver, &out.ApproverCreator}, {operator, &out.Operator, &out.OperatorCreator}} {
personConfig := withToken(config, person.token)
api, err := newClient(personConfig)
if err != nil {
return nil, err
}
creator, err := allocation.Creator(ctx, personConfig)
if err != nil {
return nil, err
}
*person.client, *person.creator = api, creator
}
return out, nil
}

// fixtureResolver is the projector's view of the fixture cleaning policy.
func fixtureResolver(_ context.Context, name string) (string, error) {
digest, err := fixtureCleaning(name)
if err != nil {
return "", capacity.ErrUnresolved
}
return digest, nil
}

func principals() custody.Principals {
return custody.Principals{custody.CreatorMetalProvider: {{Username: providerPrincipal}}, custody.CreatorReleaseController: {{Username: releasePrincipal}}}
}
Expand Down
Loading
Loading