Skip to content

Commit

Permalink
update fleetdb when a validation is successful
Browse files Browse the repository at this point in the history
  • Loading branch information
DoctorVin committed Aug 30, 2024
1 parent 27b3342 commit ce66bde
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
7 changes: 6 additions & 1 deletion internal/flipflop/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,12 @@ func (cth *ConditionTaskHandler) validateFirmware(ctx context.Context) error {
return cth.failedWithError(ctx, "failed to retrieve host boot status", err)
}
if booted {
// TODO: record successful result in fleetdb before returning
done := time.Now()
srvID := cth.task.Parameters.AssetID
fwID := cth.task.Parameters.ValidateFirmwareID
if dbErr := cth.store.ValidateFirmwareSet(ctx, srvID, fwID, done); dbErr != nil {
return cth.failedWithError(ctx, "marking firmware set validated", dbErr)
}
return nil
}
}
Expand Down
4 changes: 2 additions & 2 deletions internal/store/fleetdb/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ func newFleetDBClientWithOAuthOtel(ctx context.Context, cfg *Config, logger *log
return nil, err
}

// clientID defaults to 'alloy'
clientID := "alloy"
// clientID defaults to 'flipflop'
clientID := "flipflop"

if cfg.OidcClientID != "" {
clientID = cfg.OidcClientID
Expand Down
6 changes: 6 additions & 0 deletions internal/store/fleetdb/fleetdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"net"
"time"

"github.com/google/uuid"
"github.com/metal-toolbox/flipflop/internal/model"
Expand Down Expand Up @@ -180,3 +181,8 @@ func serverAttributes(attributes []fleetdbapi.Attributes) (map[string]string, er

return sAttributes, nil
}

// ValidateFirmwareSet reaches out to FleetDB to record that this firmware set has been successfully tested.
func (s *Store) ValidateFirmwareSet(ctx context.Context, srvID, fwID uuid.UUID, done time.Time) error {
return s.api.ValidateFirmwareSet(ctx, srvID, fwID, done)
}
4 changes: 4 additions & 0 deletions internal/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package store

import (
"context"
"time"

"github.com/google/uuid"
"github.com/metal-toolbox/flipflop/internal/model"
"github.com/metal-toolbox/flipflop/internal/store/fleetdb"
"github.com/pkg/errors"
Expand All @@ -12,6 +14,8 @@ import (
type Repository interface {
// AssetByID returns asset based on the identifier.
AssetByID(ctx context.Context, assetID string) (*model.Asset, error)
// ValidateFirmwareSet marks the set as successfully tested
ValidateFirmwareSet(context.Context, uuid.UUID, uuid.UUID, time.Time) error
}

func NewRepository(ctx context.Context, storeKind model.StoreKind, cfg *fleetdb.Config, logger *logrus.Logger) (Repository, error) {
Expand Down

0 comments on commit ce66bde

Please sign in to comment.