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

scan estimation orchestrator #560

Closed
wants to merge 3 commits into from
Closed

Conversation

fishkerez
Copy link
Contributor

@fishkerez fishkerez commented Aug 16, 2023

Description

Resolve #586

Discussion: #465

Continuing the apiserver PR: #559

Adds 2 new reconcile controllers for ScanEstimation and AssetScanEstimation.

The cost calculation implementation for AWS will be added soon.

Type of Change

[ ] Bug Fix
[* ] New Feature
[ ] Breaking Change
[ ] Refactor
[ ] Documentation
[ ] Other (please describe)

@fishkerez fishkerez self-assigned this Aug 16, 2023
@fishkerez fishkerez requested a review from a team as a code owner August 16, 2023 12:07
@Tehsmash
Copy link
Contributor

@fishkerez if you rebase this PR onto the API server one and leave this in draft there is no need for a feature branch, and we can review just the top commits for each part of the commit chain. That will make all the CI work and the top of the chain testable, and allow us to merge things directly to main without having to have a second pull request to merge it all in later.

@@ -97,6 +97,10 @@ func (c Client) Kind() models.CloudProvider {
return models.Azure
}

func (c *Client) Estimate(ctx context.Context, stats models.AssetScanStats, asset *models.Asset, assetScanTemplate *models.AssetScanTemplate) (*models.Estimation, error) {
return &models.Estimation{}, nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would return a FatalErrorf("Not Implemented") here for now

Cost: utils.PointerTo(float32(10.0)),
Size: utils.PointerTo(500),
Time: utils.PointerTo(10),
}, nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto for fatal Not Implemented error

@@ -67,6 +67,10 @@ func (c Client) Kind() models.CloudProvider {
return models.External
}

func (c *Client) Estimate(ctx context.Context, stats models.AssetScanStats, asset *models.Asset, assetScanTemplate *models.AssetScanTemplate) (*models.Estimation, error) {
return &models.Estimation{}, nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

@@ -88,6 +88,10 @@ func (c Client) Kind() models.CloudProvider {
return models.GCP
}

func (c *Client) Estimate(ctx context.Context, stats models.AssetScanStats, asset *models.Asset, assetScanTemplate *models.AssetScanTemplate) (*models.Estimation, error) {
return &models.Estimation{}, nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto


if numOfErrs > 0 {
return fmt.Errorf("failed to create %d AssetScanEstimation(s) for ScanEstimation. ScanEstimationID=%s: %w", numOfErrs, *scanEstimation.Id, assetErrs[0])
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we don't know how many Assets will match the scope we probably should avoid using buffered channels here to prevent huge memory spikes. Instead we can create an array and a consuming go routine and then wrap it the final array using errors.Join:

errs := make([]error)
errChan := make(chan error)
go func() {
   for e := range errChan {
      errs = append(errs, err)
   }
}()

for _, id := range *scanEstimation.AssetIDs {
 ....
}
wg.Wait()
close(errChan) # This stops the go routine that is consuming on errChan

err := errors.Join(errs...)
if err != nil {
   return fmt.Errorf("failed to create %d AssetScanEstimation(s) for ScanEstimation. ScanEstimationID=%s: %w", len(errs), *scanEstimation.Id, err)
} 

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took it from scanWatcher reconcile logic.

ScansCount: asset.ScansCount,
Summary: asset.Summary,
AssetInfo: asset.AssetInfo,
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a relationship to an asset in the system, we should not be duplicating any asset information in the AssetScanEstimation.

Asset: assetWriteable,
AssetScanTemplate: scanEstimation.ScanTemplate.AssetScanTemplate,
Estimation: nil,
Id: nil,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to specify these fields, their empty value will be nil.

@fishkerez fishkerez closed this Aug 23, 2023
@fishkerez fishkerez reopened this Aug 23, 2023
@fishkerez
Copy link
Contributor Author

Moved to #603

@fishkerez fishkerez closed this Aug 29, 2023
@chrisgacsal chrisgacsal deleted the estimation-orchestrator branch October 12, 2023 20:15
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants