Skip to content

Commit

Permalink
UD-1141: Fix instances of stale scan ID information
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Conner <[email protected]>
  • Loading branch information
knrc committed Jan 24, 2024
1 parent 1750517 commit d3a3a7c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
3 changes: 3 additions & 0 deletions internal/controller/zora/clusterscan_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ func (r *ClusterScanReconciler) Reconcile(ctx context.Context, req ctrl.Request)
}

err := r.reconcile(ctx, clusterscan)
if err != nil {
return ctrl.Result{}, err
}

if r.OnUpdate != nil {
if err := r.OnUpdate(ctx, clusterscan); err != nil {
Expand Down
11 changes: 7 additions & 4 deletions internal/saas/clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,14 @@ func NewCluster(cluster v1alpha1.Cluster) Cluster {
return cl
}

func NewScanStatus(scans []v1alpha1.ClusterScan) (map[string]*PluginStatus, *int) {
func NewScanStatus(clusterScan *v1alpha1.ClusterScan, scans []v1alpha1.ClusterScan) (map[string]*PluginStatus, *int) {
var pluginStatus map[string]*PluginStatus
var totalIssues *int

for _, cs := range scans {
allScans := []v1alpha1.ClusterScan{}
allScans = append(allScans, scans...)
allScans = append(allScans, *clusterScan)
for _, cs := range allScans {
if cs.Status.TotalIssues != nil {
if totalIssues == nil {
totalIssues = new(int)
Expand Down Expand Up @@ -196,8 +199,8 @@ func NewScanStatus(scans []v1alpha1.ClusterScan) (map[string]*PluginStatus, *int
return pluginStatus, totalIssues
}

func NewScanStatusWithIssues(scans []v1alpha1.ClusterScan, issues []v1alpha1.ClusterIssue) map[string]*PluginStatus {
pluginStatus, _ := NewScanStatus(scans)
func NewScanStatusWithIssues(clusterScan *v1alpha1.ClusterScan, scans []v1alpha1.ClusterScan, issues []v1alpha1.ClusterIssue) map[string]*PluginStatus {
pluginStatus, _ := NewScanStatus(clusterScan, scans)
if pluginStatus == nil {
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions internal/saas/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func pushMisconfigs(saasClient Client, c ctrlClient.Client, ctx context.Context,
return false, nil
}

status := NewScanStatusWithIssues(scanList.Items, issueList.Items)
status := NewScanStatusWithIssues(clusterScan, scanList.Items, issueList.Items)
if status == nil {
return true, nil
}
Expand Down Expand Up @@ -190,7 +190,7 @@ func pushVulns(scl Client, cl ctrlClient.Client, ctx context.Context, cs *v1alph
}

func pushStatusUpdate(saasClient Client, c ctrlClient.Client, ctx context.Context, clusterScan *v1alpha1.ClusterScan, scanList *v1alpha1.ClusterScanList) error {
status, _ := NewScanStatus(scanList.Items)
status, _ := NewScanStatus(clusterScan, scanList.Items)
processedPluginStatus := getPluginProcessedStatus(status)

if reflect.DeepEqual(processedPluginStatus, clusterScan.Status.ProcessedPluginStatus) {
Expand Down

0 comments on commit d3a3a7c

Please sign in to comment.