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

Commit

Permalink
fix(provider): skip mark terminated if asset found but patch failed (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
paralta authored Sep 6, 2023
1 parent 30e832d commit f3a933d
Showing 1 changed file with 10 additions and 3 deletions.
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

0 comments on commit f3a933d

Please sign in to comment.