refactor: remove code of scan all job (#13821)

Remove code of scan all job as it's implemented by execution now.

Signed-off-by: He Weiwei <hweiwei@vmware.com>
This commit is contained in:
He Weiwei 2020-12-22 11:39:18 +08:00 committed by GitHub
parent 53c8ad8228
commit 8fa03e3739
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 3 additions and 123 deletions

View File

@ -17,7 +17,6 @@ package runtime
import (
"context"
"fmt"
redislib "github.com/goharbor/harbor/src/lib/redis"
"os"
"os/signal"
"sync"
@ -44,10 +43,10 @@ import (
"github.com/goharbor/harbor/src/jobservice/worker"
"github.com/goharbor/harbor/src/jobservice/worker/cworker"
"github.com/goharbor/harbor/src/lib/errors"
redislib "github.com/goharbor/harbor/src/lib/redis"
"github.com/goharbor/harbor/src/pkg/p2p/preheat"
"github.com/goharbor/harbor/src/pkg/retention"
sc "github.com/goharbor/harbor/src/pkg/scan"
"github.com/goharbor/harbor/src/pkg/scan/all"
"github.com/goharbor/harbor/src/pkg/scan"
"github.com/goharbor/harbor/src/pkg/scheduler"
"github.com/gomodule/redigo/redis"
)
@ -255,8 +254,7 @@ func (bs *Bootstrap) loadAndRunRedisWorkerPool(
// Only for debugging and testing purpose
job.SampleJob: (*sample.Job)(nil),
// Functional jobs
job.ImageScanJob: (*sc.Job)(nil),
job.ImageScanAllJob: (*all.Job)(nil),
job.ImageScanJob: (*scan.Job)(nil),
job.ImageGC: (*gc.GarbageCollector)(nil),
job.ImageGCReadOnly: (*gcreadonly.GarbageCollector)(nil),
job.Replication: (*replication.Replication)(nil),

View File

@ -1,83 +0,0 @@
// Copyright Project Harbor Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package all
import (
"github.com/goharbor/harbor/src/jobservice/job"
"github.com/goharbor/harbor/src/lib/errors"
)
const (
// The max number of the goroutines to retrieve the tags
maxProcessors = 25
// Job parameter key for the admin job ID
jobParamAJID = "admin_job_id"
)
// Job query the DB and Registry for all image and tags,
// then call Harbor's API to scan each of them.
type Job struct{}
// MaxFails implements the interface in job/Interface
func (sa *Job) MaxFails() uint {
return 1
}
// MaxCurrency is implementation of same method in Interface.
func (sa *Job) MaxCurrency() uint {
return 0
}
// ShouldRetry implements the interface in job/Interface
func (sa *Job) ShouldRetry() bool {
return false
}
// Validate implements the interface in job/Interface
func (sa *Job) Validate(params job.Parameters) error {
_, err := parseAJID(params)
if err != nil {
return errors.Wrap(err, "job validation: scan all job")
}
return nil
}
// Run implements the interface in job/Interface
func (sa *Job) Run(ctx job.Context, params job.Parameters) error {
logger := ctx.GetLogger()
logger.Info("Scanning all the images in the registry")
// No need to check error any more as it has been checked in job validation.
requester, _ := parseAJID(params)
if err := ctx.Checkin(requester); err != nil {
logger.Error(errors.Wrap(err, "check in data: scan all job"))
}
return nil
}
func parseAJID(params job.Parameters) (string, error) {
if len(params) > 0 {
if v, ok := params[jobParamAJID]; ok {
if id, y := v.(string); y {
return id, nil
}
}
}
return "", errors.Errorf("missing required job parameter: %s", jobParamAJID)
}

View File

@ -1,35 +0,0 @@
// Copyright Project Harbor Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package all
// Stats provides the overall progress of the scan all process.
type Stats struct {
Total uint `json:"total"`
// Status including `Success`, `Error` or `Stopped` will be counted as completed.
// This data may be influenced by job retrying
Completed uint `json:"completed"`
Metrics StatusMetrics `json:"metrics"`
Requester string `json:"requester"`
Ongoing bool `json:"ongoing"` // Indicate if the metrics data is stable now
}
// StatusMetrics contains the metrics of each status.
// The key should be the following valid status texts:
// - "pending"
// - "running"
// - "success"
// - "error"
// - "stopped"
type StatusMetrics map[string]uint