Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OCPBUGS-17975: Support both icsp and idms #375

Merged
merged 2 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions pkg/dockerregistry/server/client/client.go
Original file line number Diff line number Diff line change
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,30 @@ 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) ImageTagMirrorSet() cfgv1.ImageTagMirrorSetInterface {
return c.config.ImageTagMirrorSets()
}

func (c *apiClient) Users() UserInterface {
return c.user.Users()
}
Expand Down Expand Up @@ -127,6 +139,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
3 changes: 3 additions & 0 deletions pkg/dockerregistry/server/client/interfaces.go
Original file line number Diff line number Diff line change
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,8 @@ type UsersInterfacer interface {

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

type ImagesInterfacer interface {
Expand Down
7 changes: 5 additions & 2 deletions pkg/dockerregistry/server/client/test.go
Original file line number Diff line number Diff line change
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
cfgclient := cfgfake.NewSimpleClientset().ConfigV1()
return newAPIClient(nil, nil, c.images, nil, icsp, cfgclient), 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)
}
13 changes: 13 additions & 0 deletions pkg/dockerregistry/server/pullthroughblobstore_test.go
Original file line number Diff line number Diff line change
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,8 @@ import (

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

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

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

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

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

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

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

ptbs := &pullthroughBlobStore{
Expand Down
5 changes: 4 additions & 1 deletion pkg/dockerregistry/server/pullthroughmanifestservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/distribution/distribution/v3/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,8 @@ type pullthroughManifestService struct {
mirror bool
registryAddr string
metrics metrics.Pullthrough
idms cfgv1.ImageDigestMirrorSetInterface
itms cfgv1.ImageTagMirrorSetInterface
icsp operatorv1alpha1.ImageContentSourcePolicyInterface
}

Expand Down Expand Up @@ -129,7 +132,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, m.itms)
if impErr != nil {
return nil, impErr
}
Expand Down
21 changes: 21 additions & 0 deletions pkg/dockerregistry/server/pullthroughmanifestservice_test.go
Original file line number Diff line number Diff line change
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,8 @@ 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()
itms := cfgfake.NewSimpleClientset().ConfigV1().ImageTagMirrorSets()
namespace := "fuser"
repo := "zapp"
repoName := fmt.Sprintf("%s/%s", namespace, repo)
Expand Down Expand Up @@ -188,6 +191,8 @@ func TestPullthroughManifests(t *testing.T) {
cache: cache,
registryAddr: "localhost:5000",
metrics: metrics.NewNoopMetrics(),
idms: idms,
itms: itms,
icsp: icsp,
}

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

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

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

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

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

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

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

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

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

Expand Down
11 changes: 9 additions & 2 deletions pkg/dockerregistry/server/remoteblobgetter.go
Original file line number Diff line number Diff line change
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,8 @@ type remoteBlobGetterService struct {
digestToStore *digestBlobStoreCache
metrics metrics.Pullthrough
icsp operatorv1alpha1.ImageContentSourcePolicyInterface
idms cfgv1.ImageDigestMirrorSetInterface
itms cfgv1.ImageTagMirrorSetInterface
}

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

Expand Down Expand Up @@ -295,7 +302,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, rbgs.itms)
if impErr != nil {
return distribution.Descriptor{}, nil, impErr
}
Expand All @@ -317,7 +324,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, rbgs.itms)
if impErr != nil {
return distribution.Descriptor{}, nil, impErr
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/dockerregistry/server/repository.go
Original file line number Diff line number Diff line change
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,8 @@ type repository struct {

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

// remoteBlobGetter is used to fetch blobs from remote registries if pullthrough is enabled.
remoteBlobGetter BlobGetterService
Expand Down Expand Up @@ -75,6 +78,8 @@ 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(),
itms: registryOSClient.ImageTagMirrorSet(),
}

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

repo = distribution.Repository(r)
Expand Down Expand Up @@ -128,7 +135,9 @@ 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,
itms: r.itms,
}

ms = newPendingErrorsManifestService(ms, r)
Expand Down