Merge pull request #14028 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) 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 { if err := task.RegisterCheckInProcessor(VendorTypeScanAll, scanTaskCheckInProcessor); err != nil {
log.Fatalf("failed to register the checkin processor for the scan all job, error %v", err) 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 { if err := task.RegisterCheckInProcessor(job.ImageScanJob, scanTaskCheckInProcessor); err != nil {
log.Fatalf("failed to register the checkin processor for the scan job, error %v", err) log.Fatalf("failed to register the checkin processor for the scan job, error %v", err)
} }
@ -76,7 +80,6 @@ func scanTaskStatusChange(ctx context.Context, taskID int64, status string) (err
return err return err
} }
if js == job.SuccessStatus {
robotID := getRobotID(t.ExtraAttrs) robotID := getRobotID(t.ExtraAttrs)
if robotID > 0 { if robotID > 0 {
if err := robotCtl.Delete(ctx, robotID); err != nil { if err := robotCtl.Delete(ctx, robotID); err != nil {
@ -86,7 +89,6 @@ func scanTaskStatusChange(ctx context.Context, taskID int64, status string) (err
logger.WithField("robot_id", robotID).Debug("Robot account for the scan task is removed") logger.WithField("robot_id", robotID).Debug("Robot account for the scan task is removed")
} }
} }
}
artifactID := getArtifactID(t.ExtraAttrs) artifactID := getArtifactID(t.ExtraAttrs)
if artifactID > 0 { if artifactID > 0 {