1
0
mirror of https://github.com/goharbor/harbor.git synced 2025-02-13 10:21:25 +01:00

Merge pull request from heww/fix-issue-14000

fix: always remove the robot after scan job finished
This commit is contained in:
Daniel Jiang 2021-01-19 14:33:21 +08:00 committed by GitHub
commit cccfa40526
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -46,11 +46,15 @@ func init() {
log.Fatalf("failed to register the callback for the scan all schedule, error %v", err)
}
// NOTE: the vendor type of execution for the scan job trigger by the scan all is job.ImageScanAllJob
// NOTE: the vendor type of execution for the scan job trigger by the scan all is VendorTypeScanAll
if err := task.RegisterCheckInProcessor(VendorTypeScanAll, scanTaskCheckInProcessor); err != nil {
log.Fatalf("failed to register the checkin processor for the scan all job, error %v", err)
}
if err := task.RegisterTaskStatusChangePostFunc(VendorTypeScanAll, scanTaskStatusChange); err != nil {
log.Fatalf("failed to register the task status change post for the scan all job, error %v", err)
}
if err := task.RegisterCheckInProcessor(job.ImageScanJob, scanTaskCheckInProcessor); err != nil {
log.Fatalf("failed to register the checkin processor for the scan job, error %v", err)
}
@ -76,15 +80,13 @@ func scanTaskStatusChange(ctx context.Context, taskID int64, status string) (err
return err
}
if js == job.SuccessStatus {
robotID := getRobotID(t.ExtraAttrs)
if robotID > 0 {
if err := robotCtl.Delete(ctx, robotID); err != nil {
// Should not block the main flow, just logged
logger.WithFields(log.Fields{"robot_id": robotID, "error": err}).Error("delete robot account failed")
} else {
logger.WithField("robot_id", robotID).Debug("Robot account for the scan task is removed")
}
robotID := getRobotID(t.ExtraAttrs)
if robotID > 0 {
if err := robotCtl.Delete(ctx, robotID); err != nil {
// Should not block the main flow, just logged
logger.WithFields(log.Fields{"robot_id": robotID, "error": err}).Error("delete robot account failed")
} else {
logger.WithField("robot_id", robotID).Debug("Robot account for the scan task is removed")
}
}