mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-15 23:05:57 +01:00
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:
parent
53c8ad8228
commit
8fa03e3739
@ -17,7 +17,6 @@ package runtime
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
redislib "github.com/goharbor/harbor/src/lib/redis"
|
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"sync"
|
"sync"
|
||||||
@ -44,10 +43,10 @@ import (
|
|||||||
"github.com/goharbor/harbor/src/jobservice/worker"
|
"github.com/goharbor/harbor/src/jobservice/worker"
|
||||||
"github.com/goharbor/harbor/src/jobservice/worker/cworker"
|
"github.com/goharbor/harbor/src/jobservice/worker/cworker"
|
||||||
"github.com/goharbor/harbor/src/lib/errors"
|
"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/p2p/preheat"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention"
|
"github.com/goharbor/harbor/src/pkg/retention"
|
||||||
sc "github.com/goharbor/harbor/src/pkg/scan"
|
"github.com/goharbor/harbor/src/pkg/scan"
|
||||||
"github.com/goharbor/harbor/src/pkg/scan/all"
|
|
||||||
"github.com/goharbor/harbor/src/pkg/scheduler"
|
"github.com/goharbor/harbor/src/pkg/scheduler"
|
||||||
"github.com/gomodule/redigo/redis"
|
"github.com/gomodule/redigo/redis"
|
||||||
)
|
)
|
||||||
@ -255,8 +254,7 @@ func (bs *Bootstrap) loadAndRunRedisWorkerPool(
|
|||||||
// Only for debugging and testing purpose
|
// Only for debugging and testing purpose
|
||||||
job.SampleJob: (*sample.Job)(nil),
|
job.SampleJob: (*sample.Job)(nil),
|
||||||
// Functional jobs
|
// Functional jobs
|
||||||
job.ImageScanJob: (*sc.Job)(nil),
|
job.ImageScanJob: (*scan.Job)(nil),
|
||||||
job.ImageScanAllJob: (*all.Job)(nil),
|
|
||||||
job.ImageGC: (*gc.GarbageCollector)(nil),
|
job.ImageGC: (*gc.GarbageCollector)(nil),
|
||||||
job.ImageGCReadOnly: (*gcreadonly.GarbageCollector)(nil),
|
job.ImageGCReadOnly: (*gcreadonly.GarbageCollector)(nil),
|
||||||
job.Replication: (*replication.Replication)(nil),
|
job.Replication: (*replication.Replication)(nil),
|
||||||
|
@ -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)
|
|
||||||
}
|
|
@ -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
|
|
Loading…
Reference in New Issue
Block a user