Skip to content

Commit

Permalink
[OCPNODE-1258] Migrate icsp to idms
Browse files Browse the repository at this point in the history
Signed-off-by: Qi Wang <qiwan@redhat.com>
  • Loading branch information
QiWang19 committed Nov 4, 2022
1 parent b300626 commit e3bc14a
Show file tree
Hide file tree
Showing 13 changed files with 468 additions and 191 deletions.
9 changes: 9 additions & 0 deletions pkg/dockerregistry/server/client/client.go
Expand Up @@ -5,6 +5,7 @@ import (
coreclientv1 "k8s.io/client-go/kubernetes/typed/core/v1"
restclient "k8s.io/client-go/rest"

cfgv1 "github.com/openshift/client-go/config/clientset/versioned/typed/config/v1"
imageclientv1 "github.com/openshift/client-go/image/clientset/versioned/typed/image/v1"
operatorclientv1alpha1 "github.com/openshift/client-go/operator/clientset/versioned/typed/operator/v1alpha1"
userclientv1 "github.com/openshift/client-go/user/clientset/versioned/typed/user/v1"
Expand Down Expand Up @@ -42,6 +43,7 @@ type apiClient struct {
image imageclientv1.ImageV1Interface
user userclientv1.UserV1Interface
operator operatorclientv1alpha1.OperatorV1alpha1Interface
config cfgv1.ConfigV1Interface
}

func newAPIClient(
Expand All @@ -50,20 +52,26 @@ func newAPIClient(
imageClient imageclientv1.ImageV1Interface,
userClient userclientv1.UserV1Interface,
operatorClient operatorclientv1alpha1.OperatorV1alpha1Interface,
configClient cfgv1.ConfigV1Interface,
) Interface {
return &apiClient{
kube: kc,
auth: authClient,
image: imageClient,
user: userClient,
operator: operatorClient,
config: configClient,
}
}

func (c *apiClient) ImageContentSourcePolicy() operatorclientv1alpha1.ImageContentSourcePolicyInterface {
return c.operator.ImageContentSourcePolicies()
}

func (c *apiClient) ImageDigestMirrorSet() cfgv1.ImageDigestMirrorSetInterface {
return c.config.ImageDigestMirrorSets()
}

func (c *apiClient) Users() UserInterface {
return c.user.Users()
}
Expand Down Expand Up @@ -127,6 +135,7 @@ func (c *registryClient) Client() (Interface, error) {
imageclientv1.NewForConfigOrDie(c.kubeConfig),
userclientv1.NewForConfigOrDie(c.kubeConfig),
operatorclientv1alpha1.NewForConfigOrDie(c.kubeConfig),
cfgv1.NewForConfigOrDie(c.kubeConfig),
), nil
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/dockerregistry/server/client/interfaces.go
Expand Up @@ -15,6 +15,7 @@ import (
operatorclientv1alpha1 "github.com/openshift/client-go/operator/clientset/versioned/typed/operator/v1alpha1"
userclientv1 "github.com/openshift/client-go/user/clientset/versioned/typed/user/v1"

cfgv1 "github.com/openshift/client-go/config/clientset/versioned/typed/config/v1"
authclientv1 "k8s.io/client-go/kubernetes/typed/authorization/v1"
)

Expand All @@ -24,6 +25,7 @@ type UsersInterfacer interface {

type ImageContentSourcePolicyInterfacer interface {
ImageContentSourcePolicy() operatorclientv1alpha1.ImageContentSourcePolicyInterface
ImageDigestMirrorSet() cfgv1.ImageDigestMirrorSetInterface
}

type ImagesInterfacer interface {
Expand Down
7 changes: 5 additions & 2 deletions pkg/dockerregistry/server/client/test.go
Expand Up @@ -3,6 +3,7 @@ package client
import (
coreclientv1 "k8s.io/client-go/kubernetes/typed/core/v1"

cfgfake "github.com/openshift/client-go/config/clientset/versioned/fake"
imageclientv1 "github.com/openshift/client-go/image/clientset/versioned/typed/image/v1"
operatorfake "github.com/openshift/client-go/operator/clientset/versioned/fake"
)
Expand All @@ -22,10 +23,12 @@ func NewFakeRegistryClient(imageclient imageclientv1.ImageV1Interface) RegistryC

func (c *fakeRegistryClient) Client() (Interface, error) {
icsp := operatorfake.NewSimpleClientset().OperatorV1alpha1()
return newAPIClient(nil, nil, c.images, nil, icsp), nil
idms := cfgfake.NewSimpleClientset().ConfigV1()
return newAPIClient(nil, nil, c.images, nil, icsp, idms), nil
}

func NewFakeRegistryAPIClient(kc coreclientv1.CoreV1Interface, imageclient imageclientv1.ImageV1Interface) Interface {
icsp := operatorfake.NewSimpleClientset().OperatorV1alpha1()
return newAPIClient(nil, nil, imageclient, nil, icsp)
idms := cfgfake.NewSimpleClientset().ConfigV1()
return newAPIClient(nil, nil, imageclient, nil, icsp, idms)
}
7 changes: 7 additions & 0 deletions pkg/dockerregistry/server/pullthroughblobstore_test.go
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/opencontainers/go-digest"

imageapiv1 "github.com/openshift/api/image/v1"
cfgfake "github.com/openshift/client-go/config/clientset/versioned/fake"
operatorfake "github.com/openshift/client-go/operator/clientset/versioned/fake"
"github.com/openshift/library-go/pkg/image/registryclient"

Expand All @@ -35,6 +36,7 @@ import (

func TestPullthroughServeBlob(t *testing.T) {
icsp := operatorfake.NewSimpleClientset().OperatorV1alpha1().ImageContentSourcePolicies()
idms := cfgfake.NewSimpleClientset().ConfigV1().ImageDigestMirrorSets()
ctx := context.Background()
ctx = testutil.WithTestLogger(ctx, t)

Expand Down Expand Up @@ -171,6 +173,7 @@ func TestPullthroughServeBlob(t *testing.T) {
cache,
metrics.NewNoopMetrics(),
icsp,
idms,
)

ptbs := &pullthroughBlobStore{
Expand Down Expand Up @@ -331,6 +334,7 @@ func TestPullthroughServeNotSeekableBlob(t *testing.T) {

func TestPullthroughServeBlobInsecure(t *testing.T) {
icsp := operatorfake.NewSimpleClientset().OperatorV1alpha1().ImageContentSourcePolicies()
idms := cfgfake.NewSimpleClientset().ConfigV1().ImageDigestMirrorSets()
namespace := "user"
repo1 := "app1"
repo2 := "app2"
Expand Down Expand Up @@ -608,6 +612,7 @@ func TestPullthroughServeBlobInsecure(t *testing.T) {
cache,
metrics.NewNoopMetrics(),
icsp,
idms,
)

ptbs := &pullthroughBlobStore{
Expand Down Expand Up @@ -675,6 +680,7 @@ func TestPullthroughServeBlobInsecure(t *testing.T) {

func TestPullthroughMetrics(t *testing.T) {
icsp := operatorfake.NewSimpleClientset().OperatorV1alpha1().ImageContentSourcePolicies()
idms := cfgfake.NewSimpleClientset().ConfigV1().ImageDigestMirrorSets()
ctx := context.Background()
ctx = testutil.WithTestLogger(ctx, t)

Expand Down Expand Up @@ -735,6 +741,7 @@ func TestPullthroughMetrics(t *testing.T) {
cache,
metrics.NewMetrics(sink),
icsp,
idms,
)

ptbs := &pullthroughBlobStore{
Expand Down
4 changes: 3 additions & 1 deletion pkg/dockerregistry/server/pullthroughmanifestservice.go
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/docker/distribution/registry/client"
"github.com/opencontainers/go-digest"

cfgv1 "github.com/openshift/client-go/config/clientset/versioned/typed/config/v1"
operatorv1alpha1 "github.com/openshift/client-go/operator/clientset/versioned/typed/operator/v1alpha1"

"github.com/openshift/image-registry/pkg/dockerregistry/server/cache"
Expand All @@ -32,6 +33,7 @@ type pullthroughManifestService struct {
mirror bool
registryAddr string
metrics metrics.Pullthrough
idms cfgv1.ImageDigestMirrorSetInterface
icsp operatorv1alpha1.ImageContentSourcePolicyInterface
}

Expand Down Expand Up @@ -129,7 +131,7 @@ func (m *pullthroughManifestService) getRemoteRepositoryClient(ctx context.Conte
dcontext.GetLogger(ctx).Errorf("error getting secrets: %v", err)
}

retriever, impErr := getImportContext(ctx, ref, secrets, m.metrics, m.icsp)
retriever, impErr := getImportContext(ctx, ref, secrets, m.metrics, m.icsp, m.idms)
if impErr != nil {
return nil, impErr
}
Expand Down
11 changes: 11 additions & 0 deletions pkg/dockerregistry/server/pullthroughmanifestservice_test.go
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/opencontainers/go-digest"

imageapiv1 "github.com/openshift/api/image/v1"
cfgfake "github.com/openshift/client-go/config/clientset/versioned/fake"
operatorfake "github.com/openshift/client-go/operator/clientset/versioned/fake"

"github.com/openshift/image-registry/pkg/dockerregistry/server/cache"
Expand Down Expand Up @@ -55,6 +56,7 @@ func createTestRegistryServer(t *testing.T, ctx context.Context) *httptest.Serve

func TestPullthroughManifests(t *testing.T) {
icsp := operatorfake.NewSimpleClientset().OperatorV1alpha1().ImageContentSourcePolicies()
idms := cfgfake.NewSimpleClientset().ConfigV1().ImageDigestMirrorSets()
namespace := "fuser"
repo := "zapp"
repoName := fmt.Sprintf("%s/%s", namespace, repo)
Expand Down Expand Up @@ -188,6 +190,7 @@ func TestPullthroughManifests(t *testing.T) {
cache: cache,
registryAddr: "localhost:5000",
metrics: metrics.NewNoopMetrics(),
idms: idms,
icsp: icsp,
}

Expand Down Expand Up @@ -228,6 +231,7 @@ func TestPullthroughManifests(t *testing.T) {

func TestPullthroughManifestInsecure(t *testing.T) {
icsp := operatorfake.NewSimpleClientset().OperatorV1alpha1().ImageContentSourcePolicies()
idms := cfgfake.NewSimpleClientset().ConfigV1().ImageDigestMirrorSets()
namespace := "fuser"
repo := "zapp"
repoName := fmt.Sprintf("%s/%s", namespace, repo)
Expand Down Expand Up @@ -431,6 +435,7 @@ func TestPullthroughManifestInsecure(t *testing.T) {
imageStream: imageStream,
cache: cache,
metrics: metrics.NewNoopMetrics(),
idms: idms,
icsp: icsp,
}

Expand Down Expand Up @@ -473,6 +478,7 @@ func TestPullthroughManifestInsecure(t *testing.T) {

func TestPullthroughManifestDockerReference(t *testing.T) {
icsp := operatorfake.NewSimpleClientset().OperatorV1alpha1().ImageContentSourcePolicies()
idms := cfgfake.NewSimpleClientset().ConfigV1().ImageDigestMirrorSets()
namespace := "user"
repo1 := "repo1"
repo2 := "repo2"
Expand Down Expand Up @@ -572,6 +578,7 @@ func TestPullthroughManifestDockerReference(t *testing.T) {
ManifestService: newTestManifestService(tc.repoName, nil),
imageStream: imageStream,
metrics: metrics.NewNoopMetrics(),
idms: idms,
icsp: icsp,
}

Expand Down Expand Up @@ -668,6 +675,7 @@ func (ms *putWaiterManifestService) Put(ctx context.Context, manifest distributi

func TestPullthroughManifestMirroring(t *testing.T) {
icsp := operatorfake.NewSimpleClientset().OperatorV1alpha1().ImageContentSourcePolicies()
idms := cfgfake.NewSimpleClientset().ConfigV1().ImageDigestMirrorSets()
const timeout = 5 * time.Second

namespace := "myproject"
Expand Down Expand Up @@ -732,6 +740,7 @@ func TestPullthroughManifestMirroring(t *testing.T) {
imageStream: imageStream,
mirror: true,
metrics: metrics.NewNoopMetrics(),
idms: idms,
icsp: icsp,
}

Expand All @@ -749,6 +758,7 @@ func TestPullthroughManifestMirroring(t *testing.T) {

func TestPullthroughManifestMetrics(t *testing.T) {
icsp := operatorfake.NewSimpleClientset().OperatorV1alpha1().ImageContentSourcePolicies()
idms := cfgfake.NewSimpleClientset().ConfigV1().ImageDigestMirrorSets()
namespace := "myproject"
repo := "myapp"
repoName := fmt.Sprintf("%s/%s", namespace, repo)
Expand Down Expand Up @@ -810,6 +820,7 @@ func TestPullthroughManifestMetrics(t *testing.T) {
newLocalManifestService: func(ctx context.Context) (distribution.ManifestService, error) { return ms, nil },
imageStream: imageStream,
metrics: metrics.NewMetrics(sink),
idms: idms,
icsp: icsp,
}

Expand Down
8 changes: 6 additions & 2 deletions pkg/dockerregistry/server/remoteblobgetter.go
Expand Up @@ -13,6 +13,7 @@ import (

corev1 "k8s.io/api/core/v1"

cfgv1 "github.com/openshift/client-go/config/clientset/versioned/typed/config/v1"
operatorv1alpha1 "github.com/openshift/client-go/operator/clientset/versioned/typed/operator/v1alpha1"
"github.com/openshift/library-go/pkg/image/registryclient"

Expand Down Expand Up @@ -72,6 +73,7 @@ type remoteBlobGetterService struct {
digestToStore *digestBlobStoreCache
metrics metrics.Pullthrough
icsp operatorv1alpha1.ImageContentSourcePolicyInterface
idms cfgv1.ImageDigestMirrorSetInterface
}

var _ BlobGetterService = &remoteBlobGetterService{}
Expand All @@ -84,6 +86,7 @@ func NewBlobGetterService(
cache cache.RepositoryDigest,
m metrics.Pullthrough,
icsp operatorv1alpha1.ImageContentSourcePolicyInterface,
idms cfgv1.ImageDigestMirrorSetInterface,
) BlobGetterService {
return &remoteBlobGetterService{
imageStream: imageStream,
Expand All @@ -92,6 +95,7 @@ func NewBlobGetterService(
digestToStore: newDigestBlobStoreCache(m),
metrics: m,
icsp: icsp,
idms: idms,
}
}

Expand Down Expand Up @@ -295,7 +299,7 @@ func (rbgs *remoteBlobGetterService) findCandidateRepository(
continue
}

retriever, impErr := getImportContext(ctx, spec.DockerImageReference, secrets, rbgs.metrics, rbgs.icsp)
retriever, impErr := getImportContext(ctx, spec.DockerImageReference, secrets, rbgs.metrics, rbgs.icsp, rbgs.idms)
if impErr != nil {
return distribution.Descriptor{}, nil, impErr
}
Expand All @@ -317,7 +321,7 @@ func (rbgs *remoteBlobGetterService) findCandidateRepository(
continue
}

retriever, impErr := getImportContext(ctx, spec.DockerImageReference, secrets, rbgs.metrics, rbgs.icsp)
retriever, impErr := getImportContext(ctx, spec.DockerImageReference, secrets, rbgs.metrics, rbgs.icsp, rbgs.idms)
if impErr != nil {
return distribution.Descriptor{}, nil, impErr
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/dockerregistry/server/repository.go
Expand Up @@ -11,6 +11,7 @@ import (

restclient "k8s.io/client-go/rest"

cfgv1 "github.com/openshift/client-go/config/clientset/versioned/typed/config/v1"
operatorv1alpha1 "github.com/openshift/client-go/operator/clientset/versioned/typed/operator/v1alpha1"

"github.com/openshift/image-registry/pkg/dockerregistry/server/audit"
Expand Down Expand Up @@ -47,6 +48,7 @@ type repository struct {

imageStream imagestream.ImageStream
icsp operatorv1alpha1.ImageContentSourcePolicyInterface
idms cfgv1.ImageDigestMirrorSetInterface

// remoteBlobGetter is used to fetch blobs from remote registries if pullthrough is enabled.
remoteBlobGetter BlobGetterService
Expand Down Expand Up @@ -75,6 +77,7 @@ func (app *App) Repository(ctx context.Context, repo distribution.Repository, cr
imageStream: imagestream.New(ctx, namespace, name, registryOSClient),
cache: cache.NewRepositoryDigest(app.cache),
icsp: registryOSClient.ImageContentSourcePolicy(),
idms: registryOSClient.ImageDigestMirrorSet(),
}

r.remoteBlobGetter = NewBlobGetterService(
Expand All @@ -83,6 +86,7 @@ func (app *App) Repository(ctx context.Context, repo distribution.Repository, cr
r.cache,
r.app.metrics,
r.icsp,
r.idms,
)

repo = distribution.Repository(r)
Expand Down Expand Up @@ -122,6 +126,7 @@ func (r *repository) Manifests(ctx context.Context, options ...distribution.Mani
mirror: r.app.config.Pullthrough.Mirror,
registryAddr: r.app.config.Server.Addr,
metrics: r.app.metrics,
idms: r.idms,
icsp: r.icsp,
}

Expand Down

0 comments on commit e3bc14a

Please sign in to comment.