Merge pull request #11364 from ywk253100/200331_replication

Some tiny improvement for replication
This commit is contained in:
Wenkai Yin(尹文开) 2020-04-01 17:29:08 +08:00 committed by GitHub
commit 9f4f3be00d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 28 deletions

View File

@ -31,12 +31,12 @@ import (
) )
// NewAuthorizer creates an authorizer that can handle different auth schemes // NewAuthorizer creates an authorizer that can handle different auth schemes
func NewAuthorizer(username, password string, trType uint) lib.Authorizer { func NewAuthorizer(username, password string, insecure bool) lib.Authorizer {
return &authorizer{ return &authorizer{
username: username, username: username,
password: password, password: password,
client: &http.Client{ client: &http.Client{
Transport: commonhttp.GetHTTPTransport(trType), Transport: commonhttp.GetHTTPTransportByInsecure(insecure),
}, },
} }
} }

View File

@ -24,6 +24,7 @@ import (
"net/url" "net/url"
"strconv" "strconv"
"strings" "strings"
"time"
"github.com/docker/distribution" "github.com/docker/distribution"
"github.com/docker/distribution/manifest/manifestlist" "github.com/docker/distribution/manifest/manifestlist"
@ -94,24 +95,16 @@ type Client interface {
Copy(srcRepository, srcReference, dstRepository, dstReference string, override bool) (err error) Copy(srcRepository, srcReference, dstRepository, dstReference string, override bool) (err error)
} }
// TODO support HTTPS
// NewClient creates a registry client with the default authorizer which determines the auth scheme // NewClient creates a registry client with the default authorizer which determines the auth scheme
// of the registry automatically and calls the corresponding underlying authorizers(basic/bearer) to // of the registry automatically and calls the corresponding underlying authorizers(basic/bearer) to
// do the auth work. If a customized authorizer is needed, use "NewClientWithAuthorizer" instead // do the auth work. If a customized authorizer is needed, use "NewClientWithAuthorizer" instead
func NewClient(url, username, password string, insecure bool) Client { func NewClient(url, username, password string, insecure bool) Client {
var transportType uint
if insecure {
transportType = commonhttp.InsecureTransport
} else {
transportType = commonhttp.SecureTransport
}
return &client{ return &client{
url: url, url: url,
authorizer: auth.NewAuthorizer(username, password, transportType), authorizer: auth.NewAuthorizer(username, password, insecure),
client: &http.Client{ client: &http.Client{
Transport: commonhttp.GetHTTPTransport(transportType), Transport: commonhttp.GetHTTPTransportByInsecure(insecure),
Timeout: 30 * time.Minute,
}, },
} }
} }
@ -439,8 +432,6 @@ func (c *client) DeleteBlob(repository, digest string) error {
return nil return nil
} }
// TODO extend this method to support copy artifacts between different registries when merging codes
// TODO this can be used in replication to replace the existing implementation
func (c *client) Copy(srcRepo, srcRef, dstRepo, dstRef string, override bool) error { func (c *client) Copy(srcRepo, srcRef, dstRepo, dstRef string, override bool) error {
// pull the manifest from the source repository // pull the manifest from the source repository
manifest, srcDgt, err := c.PullManifest(srcRepo, srcRef) manifest, srcDgt, err := c.PullManifest(srcRepo, srcRef)
@ -492,17 +483,6 @@ func (c *client) Copy(srcRepo, srcRef, dstRepo, dstRef string, override bool) er
if err = c.MountBlob(srcRepo, digest, dstRepo); err != nil { if err = c.MountBlob(srcRepo, digest, dstRepo); err != nil {
return err return err
} }
/*
// copy happens between different registries
size, data, err := src.PullBlob(digest)
if err != nil {
return err
}
defer data.Close()
if err = dst.PushBlob(digest, size, data); err != nil {
return err
}
*/
} }
} }

View File

@ -16,6 +16,7 @@ package scheduler
import ( import (
"fmt" "fmt"
"net/http"
"strings" "strings"
"time" "time"
@ -104,8 +105,8 @@ func (s *scheduler) Unschedule(policyID int64) error {
if err = s.jobservice.PostAction(sj.JobID, job.JobActionStop); err != nil { if err = s.jobservice.PostAction(sj.JobID, job.JobActionStop); err != nil {
// if the job specified by jobID is not found in jobservice, just delete // if the job specified by jobID is not found in jobservice, just delete
// the record from database // the record from database
if e, ok := err.(*commonHttp.Error); !ok || if e, ok := err.(*commonHttp.Error); !ok || (e.Code != http.StatusNotFound &&
!strings.Contains(e.Message, "no valid periodic job policy found") { !strings.Contains(e.Message, "no valid periodic job policy found")) {
return err return err
} }
log.Debugf("the stop action for schedule job %s submitted to the jobservice", sj.JobID) log.Debugf("the stop action for schedule job %s submitted to the jobservice", sj.JobID)

View File

@ -165,6 +165,8 @@ func (t *transfer) copy(src *repository, dst *repository, override bool) error {
} }
} }
if err != nil { if err != nil {
err = errors.New("got error during the whole transfer period, mark the job failure")
t.logger.Error(err)
return err return err
} }