Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dissociate status update from pod status update #1561

Merged
merged 1 commit into from
Sep 13, 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
25 changes: 15 additions & 10 deletions deepfence_worker/ingesters/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,30 @@ func CommitFuncStatus[Status any](ts utils.Neo4jScanType) func(ns string, data [
return err
}

if ts != utils.NEO4J_CLOUD_COMPLIANCE_SCAN && ts != utils.NEO4J_COMPLIANCE_SCAN {
err = updatePodScanStatus(ts, recordMap, tx)
if err != nil {
return err
}
}

err = tx.Commit()
if err != nil {
return err
}

return nil
if ts != utils.NEO4J_CLOUD_COMPLIANCE_SCAN && ts != utils.NEO4J_COMPLIANCE_SCAN {
err = updatePodScanStatus(ts, recordMap, session)
}

return err
}
}

// TODO: move to a specific task
func updatePodScanStatus(ts utils.Neo4jScanType,
recordMap []map[string]interface{}, tx neo4j.Transaction) error {
recordMap []map[string]interface{}, session neo4j.Session) error {

tx, err := session.BeginTransaction(neo4j.WithTxTimeout(30 * time.Second))
if err != nil {
return err
}
defer tx.Close()

// TODO: Take into account all containers, not just last one
query := `
UNWIND $batch as row
MATCH (s:` + string(ts) + `{node_id: row.scan_id})-[:SCANNED]->(c:Container)
Expand All @@ -96,7 +101,7 @@ func updatePodScanStatus(ts utils.Neo4jScanType,
SET n.` + ingestersUtil.ScanStatusField[ts] + `=row.scan_status`

log.Debug().Msgf("query: %v", query)
_, err := tx.Run(query,
_, err = tx.Run(query,
map[string]interface{}{
"batch": recordMap,
},
Expand Down