Skip to content
This repository has been archived by the owner on Oct 14, 2024. It is now read-only.

fix(orchestrator): skip mark terminated if asset found but patch failed #614

Merged
merged 1 commit into from
Sep 6, 2023
Merged
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
13 changes: 10 additions & 3 deletions pkg/orchestrator/discovery/discoverer.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func (d *Discoverer) DiscoverAndCreateAssets(ctx context.Context) error {
}

errs := []error{}
failedPatchAssets := make(map[string]struct{})
for _, assetType := range assetTypes {
assetData := models.Asset{
AssetInfo: utils.PointerTo(assetType),
Expand All @@ -94,7 +95,7 @@ func (d *Discoverer) DiscoverAndCreateAssets(ctx context.Context) error {
// because discovering the assets is a heavy operation,
// so we want to give the best chance to create all the
// assets in the DB before failing.
errs = append(errs, fmt.Errorf("failed to post asset: %v", err))
errs = append(errs, fmt.Errorf("failed to post asset: %w", err))
continue
}

Expand All @@ -104,7 +105,8 @@ func (d *Discoverer) DiscoverAndCreateAssets(ctx context.Context) error {
assetData.FirstSeen = nil
err = d.backendClient.PatchAsset(ctx, assetData, *conflictError.ConflictingAsset.Id)
if err != nil {
errs = append(errs, fmt.Errorf("failed to patch asset: %v", err))
failedPatchAssets[*conflictError.ConflictingAsset.Id] = struct{}{}
errs = append(errs, fmt.Errorf("failed to patch asset: %w", err))
}
}

Expand All @@ -127,13 +129,18 @@ func (d *Discoverer) DiscoverAndCreateAssets(ctx context.Context) error {
// Patch all assets which were not found by this discovery as
// terminated by setting terminatedOn.
for _, asset := range *assetResp.Items {
// Skip mark terminated if asset found but patch failed.
if _, ok := failedPatchAssets[*asset.Id]; ok {
continue
}

assetData := models.Asset{
TerminatedOn: &discoveryTime,
}

err := d.backendClient.PatchAsset(ctx, assetData, *asset.Id)
if err != nil {
errs = append(errs, fmt.Errorf("failed to patch asset: %v", err))
errs = append(errs, fmt.Errorf("failed to patch asset: %w", err))
}
}

Expand Down
Loading