This PR does the following things:
1. add new registry api under resources.kubesphere.io/v1alpha3 2. deprecate registry api v1alpha2 Registry API v1alpha2 uses docker client to authenticate image registry secret, which depends on docker.sock. We used to mount host `/var/run/docker.sock` to deployment. It will prevent us imgrating to containerd since no `docker.sock` exists. Registry API v1alpha3 comes to rescure, it wraps library go-containerregistry and compatible with docker registry, Harbor etc.
This commit is contained in:
71
pkg/models/registries/v2/registries.go
Normal file
71
pkg/models/registries/v2/registries.go
Normal file
@@ -0,0 +1,71 @@
|
||||
package v2
|
||||
|
||||
import (
|
||||
"github.com/google/go-containerregistry/pkg/name"
|
||||
v1 "github.com/google/go-containerregistry/pkg/v1"
|
||||
"github.com/google/go-containerregistry/pkg/v1/remote"
|
||||
)
|
||||
|
||||
type Registryer interface {
|
||||
// list repository tags
|
||||
ListRepositoryTags(image string) (RepositoryTags, error)
|
||||
|
||||
// get image config
|
||||
Config(image string) (*v1.ConfigFile, error)
|
||||
}
|
||||
|
||||
type registryer struct {
|
||||
opts options
|
||||
}
|
||||
|
||||
func NewRegistryer(opts ...Option) *registryer {
|
||||
return ®istryer{
|
||||
opts: makeOptions(opts...),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *registryer) ListRepositoryTags(src string) (RepositoryTags, error) {
|
||||
repo, err := name.NewRepository(src, r.opts.name...)
|
||||
if err != nil {
|
||||
return RepositoryTags{}, err
|
||||
}
|
||||
|
||||
tags, err := remote.List(repo, r.opts.remote...)
|
||||
if err != nil {
|
||||
return RepositoryTags{}, err
|
||||
}
|
||||
|
||||
return RepositoryTags{
|
||||
Registry: repo.RegistryStr(),
|
||||
Repository: repo.RepositoryStr(),
|
||||
Tags: tags,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (r *registryer) Config(image string) (*v1.ConfigFile, error) {
|
||||
img, _, err := r.getImage(image)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
configFile, err := img.ConfigFile()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return configFile, nil
|
||||
}
|
||||
|
||||
func (r *registryer) getImage(reference string) (v1.Image, name.Reference, error) {
|
||||
ref, err := name.ParseReference(reference, r.opts.name...)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
img, err := remote.Image(ref, r.opts.remote...)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
return img, ref, nil
|
||||
}
|
||||
Reference in New Issue
Block a user