Skip to content

registry: use generated imagestream clientset to retrieve secrets #16098

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

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/dockerregistry/server/blobdescriptorservice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ func TestBlobDescriptorServiceIsApplied(t *testing.T) {
// to make other unit tests working
defer m.changeUnsetRepository(false)

fos, client, imageClient := registrytest.NewFakeOpenShiftWithClient()
fos, _, imageClient := registrytest.NewFakeOpenShiftWithClient()
testImage := registrytest.AddRandomImage(t, fos, "user", "app", "latest")

ctx := context.Background()
ctx = WithConfiguration(ctx, &srvconfig.Configuration{})
ctx = WithRegistryClient(ctx, registryclient.NewFakeRegistryClient(client, imageClient))
ctx = WithRegistryClient(ctx, registryclient.NewFakeRegistryClient(imageClient))
app := handlers.NewApp(ctx, &configuration.Configuration{
Loglevel: "debug",
Auth: map[string]configuration.Parameters{
Expand Down
26 changes: 7 additions & 19 deletions pkg/dockerregistry/server/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
authclientv1 "k8s.io/kubernetes/pkg/client/clientset_generated/clientset/typed/authorization/v1"
kcoreclient "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/core/internalversion"

osclient "github.com/openshift/origin/pkg/client"
"github.com/openshift/origin/pkg/cmd/util/clientcmd"
imageclientv1 "github.com/openshift/origin/pkg/image/generated/clientset/typed/image/v1"
userclientv1 "github.com/openshift/origin/pkg/user/generated/clientset/typed/user/v1"
Expand Down Expand Up @@ -36,22 +35,19 @@ type Interface interface {
}

type apiClient struct {
oc osclient.Interface
kube kcoreclient.CoreInterface
auth authclientv1.AuthorizationV1Interface
image imageclientv1.ImageV1Interface
user userclientv1.UserV1Interface
}

func newAPIClient(
c osclient.Interface,
kc kcoreclient.CoreInterface,
authClient authclientv1.AuthorizationV1Interface,
imageClient imageclientv1.ImageV1Interface,
userClient userclientv1.UserV1Interface,
) Interface {
return &apiClient{
oc: c,
kube: kc,
auth: authClient,
image: imageClient,
Expand Down Expand Up @@ -88,9 +84,7 @@ func (c *apiClient) ImageStreamTags(namespace string) ImageStreamTagInterface {
}

func (c *apiClient) ImageStreamSecrets(namespace string) ImageStreamSecretInterface {
// FIXME: When we generate expansions for images clientset, replace this with
// the clientset and get rid of the legacy client alltogether.
return c.oc.ImageStreamSecrets(namespace)
return c.image.ImageStreams(namespace)
}

func (c *apiClient) LimitRanges(namespace string) LimitRangeInterface {
Expand All @@ -106,22 +100,21 @@ func (c *apiClient) SelfSubjectAccessReviews() SelfSubjectAccessReviewInterface
}

type registryClient struct {
kubeConfig *restclient.Config
openshiftConfig *restclient.Config
kubeConfig *restclient.Config
}

// NewRegistryClient provides a new registry client.
// TODO: Remove clientcmd dependency and move the parsing of required
// environemtn variable to registry.
func NewRegistryClient(config *clientcmd.Config) RegistryClient {
return &registryClient{
kubeConfig: config.KubeConfig(),
openshiftConfig: config.OpenShiftConfig(),
kubeConfig: config.KubeConfig(),
}
}

// Client returns the authenticated client to use with the server.
func (c *registryClient) Client() (Interface, error) {
return newAPIClient(
osclient.NewOrDie(c.openshiftConfig),
kcoreclient.NewForConfigOrDie(c.kubeConfig),
authclientv1.NewForConfigOrDie(c.kubeConfig),
imageclientv1.NewForConfigOrDie(c.kubeConfig),
Expand All @@ -132,14 +125,9 @@ func (c *registryClient) Client() (Interface, error) {
// ClientFromToken returns the client based on the bearer token.
func (c *registryClient) ClientFromToken(token string) (Interface, error) {
newClient := *c
newOpenshiftConfig := clientcmd.AnonymousClientConfig(newClient.openshiftConfig)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use k8s.io/client-go/rest.AnonymousClientConfig

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

newOpenshiftConfig.BearerToken = token

newKubeconfig := *newClient.kubeConfig
newKubeconfig := restclient.AnonymousClientConfig(newClient.kubeConfig)
newKubeconfig.BearerToken = token

newClient.kubeConfig = &newKubeconfig
newClient.openshiftConfig = &newOpenshiftConfig
newClient.kubeConfig = newKubeconfig

return newClient.Client()
}
5 changes: 4 additions & 1 deletion pkg/dockerregistry/server/client/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package client
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
kapi "k8s.io/kubernetes/pkg/api"
kapiv1 "k8s.io/kubernetes/pkg/api/v1"
kcoreclient "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/core/internalversion"

imageapiv1 "github.com/openshift/origin/pkg/image/apis/image/v1"
Expand Down Expand Up @@ -103,8 +104,10 @@ type ImageStreamTagInterface interface {
Delete(name string, options *metav1.DeleteOptions) error
}

var _ ImageStreamSecretInterface = imageclientv1.ImageStreamInterface(nil)

type ImageStreamSecretInterface interface {
Secrets(name string, options metav1.ListOptions) (*kapi.SecretList, error)
Secrets(name string, options metav1.ListOptions) (*kapiv1.SecretList, error)
}

var _ LimitRangeInterface = kcoreclient.LimitRangeInterface(nil)
Expand Down
11 changes: 4 additions & 7 deletions pkg/dockerregistry/server/client/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,26 @@ package client
import (
kcoreclient "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/core/internalversion"

"github.com/openshift/origin/pkg/client"
imageclientv1 "github.com/openshift/origin/pkg/image/generated/clientset/typed/image/v1"
)

type fakeRegistryClient struct {
RegistryClient

client client.Interface
images imageclientv1.ImageV1Interface
}

func NewFakeRegistryClient(c client.Interface, imageclient imageclientv1.ImageV1Interface) RegistryClient {
func NewFakeRegistryClient(imageclient imageclientv1.ImageV1Interface) RegistryClient {
return &fakeRegistryClient{
RegistryClient: &registryClient{},
client: c,
images: imageclient,
}
}

func (c *fakeRegistryClient) Client() (Interface, error) {
return newAPIClient(c.client, nil, nil, c.images, nil), nil
return newAPIClient(nil, nil, c.images, nil), nil
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmage as part of the test client refactoring we should get rid of all this nils and just pass the clients we actually use (I believe we use just images client).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We just don't have unit tests for the paths with other clients (e.g., limit ranges). If we have better code coverage, we will not have nils there.

}

func NewFakeRegistryAPIClient(c client.Interface, kc kcoreclient.CoreInterface, imageclient imageclientv1.ImageV1Interface) Interface {
return newAPIClient(c, nil, nil, imageclient, nil)
func NewFakeRegistryAPIClient(kc kcoreclient.CoreInterface, imageclient imageclientv1.ImageV1Interface) Interface {
return newAPIClient(nil, nil, imageclient, nil)
}
16 changes: 8 additions & 8 deletions pkg/dockerregistry/server/manifestservice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ func TestManifestServiceExists(t *testing.T) {
repo := "app"
tag := "latest"

fos, client, imageClient := testutil.NewFakeOpenShiftWithClient()
fos, _, imageClient := testutil.NewFakeOpenShiftWithClient()
testImage := testutil.AddRandomImage(t, fos, namespace, repo, tag)

r := newTestRepository(t, namespace, repo, testRepositoryOptions{
client: registryclient.NewFakeRegistryAPIClient(client, nil, imageClient),
client: registryclient.NewFakeRegistryAPIClient(nil, imageClient),
})

ms := &manifestService{
Expand Down Expand Up @@ -51,7 +51,7 @@ func TestManifestServiceGetDoesntChangeDockerImageReference(t *testing.T) {
repo := "app"
tag := "latest"

fos, client, imageClient := testutil.NewFakeOpenShiftWithClient()
fos, _, imageClient := testutil.NewFakeOpenShiftWithClient()

testImage, err := testutil.CreateRandomImage(namespace, repo)
if err != nil {
Expand All @@ -77,7 +77,7 @@ func TestManifestServiceGetDoesntChangeDockerImageReference(t *testing.T) {
}

r := newTestRepository(t, namespace, repo, testRepositoryOptions{
client: registryclient.NewFakeRegistryAPIClient(client, nil, imageClient),
client: registryclient.NewFakeRegistryAPIClient(nil, imageClient),
})

ms := &manifestService{
Expand Down Expand Up @@ -113,7 +113,7 @@ func TestManifestServicePut(t *testing.T) {
repo := "app"
repoName := fmt.Sprintf("%s/%s", namespace, repo)

_, client, imageClient := testutil.NewFakeOpenShiftWithClient()
_, _, imageClient := testutil.NewFakeOpenShiftWithClient()

bs := newTestBlobStore(map[digest.Digest][]byte{
"test:1": []byte("{}"),
Expand All @@ -122,7 +122,7 @@ func TestManifestServicePut(t *testing.T) {
tms := newTestManifestService(repoName, nil)

r := newTestRepository(t, namespace, repo, testRepositoryOptions{
client: registryclient.NewFakeRegistryAPIClient(client, nil, imageClient),
client: registryclient.NewFakeRegistryAPIClient(nil, imageClient),
blobs: bs,
})

Expand All @@ -146,7 +146,7 @@ func TestManifestServicePut(t *testing.T) {
},
}

osclient, err := registryclient.NewFakeRegistryClient(client, imageClient).Client()
osclient, err := registryclient.NewFakeRegistryClient(imageClient).Client()
if err != nil {
t.Fatal(err)
}
Expand All @@ -161,7 +161,7 @@ func TestManifestServicePut(t *testing.T) {

// recreate repository to reset cached image stream
r = newTestRepository(t, namespace, repo, testRepositoryOptions{
client: registryclient.NewFakeRegistryAPIClient(client, nil, imageClient),
client: registryclient.NewFakeRegistryAPIClient(nil, imageClient),
blobs: bs,
})

Expand Down
12 changes: 6 additions & 6 deletions pkg/dockerregistry/server/pullthroughblobstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestPullthroughServeBlob(t *testing.T) {
os.Setenv("OPENSHIFT_DEFAULT_REGISTRY", serverURL.Host)
testImage.DockerImageReference = fmt.Sprintf("%s/%s@%s", serverURL.Host, repoName, testImage.Name)

fos, client, imageClient := registrytest.NewFakeOpenShiftWithClient()
fos, _, imageClient := registrytest.NewFakeOpenShiftWithClient()
registrytest.AddImageStream(t, fos, namespace, name, map[string]string{
imageapi.InsecureRepositoryAnnotation: "true",
})
Expand Down Expand Up @@ -137,7 +137,7 @@ func TestPullthroughServeBlob(t *testing.T) {

ctx := WithTestPassthroughToUpstream(context.Background(), false)
repo := newTestRepository(t, namespace, name, testRepositoryOptions{
client: registryclient.NewFakeRegistryAPIClient(client, nil, imageClient),
client: registryclient.NewFakeRegistryAPIClient(nil, imageClient),
enablePullThrough: true,
})
ptbs := &pullthroughBlobStore{
Expand Down Expand Up @@ -278,7 +278,7 @@ func TestPullthroughServeNotSeekableBlob(t *testing.T) {
}
testImage.DockerImageReference = fmt.Sprintf("%s/%s@%s", serverURL.Host, repoName, testImage.Name)

fos, client, imageClient := registrytest.NewFakeOpenShiftWithClient()
fos, _, imageClient := registrytest.NewFakeOpenShiftWithClient()
registrytest.AddImageStream(t, fos, namespace, name, map[string]string{
imageapi.InsecureRepositoryAnnotation: "true",
})
Expand All @@ -288,7 +288,7 @@ func TestPullthroughServeNotSeekableBlob(t *testing.T) {

ctx := WithTestPassthroughToUpstream(context.Background(), false)
repo := newTestRepository(t, namespace, name, testRepositoryOptions{
client: registryclient.NewFakeRegistryAPIClient(client, nil, imageClient),
client: registryclient.NewFakeRegistryAPIClient(nil, imageClient),
enablePullThrough: true,
})
ptbs := &pullthroughBlobStore{
Expand Down Expand Up @@ -598,7 +598,7 @@ func TestPullthroughServeBlobInsecure(t *testing.T) {
expectedBytesServed: int64(m1img.DockerImageLayers[0].LayerSize),
},
} {
fos, client, imageClient := registrytest.NewFakeOpenShiftWithClient()
fos, _, imageClient := registrytest.NewFakeOpenShiftWithClient()

tc.fakeOpenShiftInit(fos)

Expand All @@ -607,7 +607,7 @@ func TestPullthroughServeBlobInsecure(t *testing.T) {
ctx := WithTestPassthroughToUpstream(context.Background(), false)

repo := newTestRepository(t, namespace, repo1, testRepositoryOptions{
client: registryclient.NewFakeRegistryAPIClient(client, nil, imageClient),
client: registryclient.NewFakeRegistryAPIClient(nil, imageClient),
enablePullThrough: true,
})

Expand Down
12 changes: 6 additions & 6 deletions pkg/dockerregistry/server/pullthroughmanifestservice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func TestPullthroughManifests(t *testing.T) {
image.DockerImageReference = fmt.Sprintf("%s/%s/%s@%s", serverURL.Host, namespace, repo, image.Name)
image.DockerImageManifest = ""

fos, client, imageClient := registrytest.NewFakeOpenShiftWithClient()
fos, _, imageClient := registrytest.NewFakeOpenShiftWithClient()
registrytest.AddImageStream(t, fos, namespace, repo, map[string]string{
imageapi.InsecureRepositoryAnnotation: "true",
})
Expand Down Expand Up @@ -136,7 +136,7 @@ func TestPullthroughManifests(t *testing.T) {
localManifestService := newTestManifestService(repoName, tc.localData)

repo := newTestRepository(t, namespace, repo, testRepositoryOptions{
client: registryclient.NewFakeRegistryAPIClient(client, nil, imageClient),
client: registryclient.NewFakeRegistryAPIClient(nil, imageClient),
enablePullThrough: true,
})

Expand Down Expand Up @@ -351,15 +351,15 @@ func TestPullthroughManifestInsecure(t *testing.T) {
},
},
} {
fos, client, imageClient := registrytest.NewFakeOpenShiftWithClient()
fos, _, imageClient := registrytest.NewFakeOpenShiftWithClient()

tc.fakeOpenShiftInit(fos)

localManifestService := newTestManifestService(repoName, tc.localData)

ctx := WithTestPassthroughToUpstream(context.Background(), false)
repo := newTestRepository(t, namespace, repo, testRepositoryOptions{
client: registryclient.NewFakeRegistryAPIClient(client, nil, imageClient),
client: registryclient.NewFakeRegistryAPIClient(nil, imageClient),
enablePullThrough: true,
})
ctx = withRepository(ctx, repo)
Expand Down Expand Up @@ -459,7 +459,7 @@ func TestPullthroughManifestDockerReference(t *testing.T) {
image2 := *img
image2.DockerImageReference = dockerImageReference(server2, "foo/bar")

fos, client, imageClient := registrytest.NewFakeOpenShiftWithClient()
fos, _, imageClient := registrytest.NewFakeOpenShiftWithClient()
registrytest.AddImageStream(t, fos, namespace, repo1, map[string]string{
imageapi.InsecureRepositoryAnnotation: "true",
})
Expand Down Expand Up @@ -493,7 +493,7 @@ func TestPullthroughManifestDockerReference(t *testing.T) {
}

r := newTestRepository(t, namespace, tc.repoName, testRepositoryOptions{
client: registryclient.NewFakeRegistryAPIClient(client, nil, imageClient),
client: registryclient.NewFakeRegistryAPIClient(nil, imageClient),
enablePullThrough: true,
})

Expand Down
8 changes: 4 additions & 4 deletions pkg/dockerregistry/server/repositorymiddleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ func TestRepositoryBlobStat(t *testing.T) {
ctx = withDeferredErrors(ctx, tc.deferredErrors)
}

fos, client, imageClient := registrytest.NewFakeOpenShiftWithClient()
fos, _, imageClient := registrytest.NewFakeOpenShiftWithClient()

for _, is := range tc.imageStreams {
_, err = fos.CreateImageStream(is.Namespace, &is)
Expand All @@ -313,7 +313,7 @@ func TestRepositoryBlobStat(t *testing.T) {
}
}

reg, err := newTestRegistry(ctx, registryclient.NewFakeRegistryAPIClient(client, nil, imageClient), driver, defaultBlobRepositoryCacheTTL, tc.pullthrough, true)
reg, err := newTestRegistry(ctx, registryclient.NewFakeRegistryAPIClient(nil, imageClient), driver, defaultBlobRepositoryCacheTTL, tc.pullthrough, true)
if err != nil {
t.Errorf("[%s] unexpected error: %v", tc.name, err)
continue
Expand Down Expand Up @@ -375,11 +375,11 @@ func TestRepositoryBlobStatCacheEviction(t *testing.T) {
t.Fatal(err)
}

fos, client, imageClient := registrytest.NewFakeOpenShiftWithClient()
fos, _, imageClient := registrytest.NewFakeOpenShiftWithClient()
registrytest.AddImageStream(t, fos, "nm", "is", nil)
registrytest.AddImage(t, fos, testImage, "nm", "is", "latest")

reg, err := newTestRegistry(ctx, registryclient.NewFakeRegistryAPIClient(client, nil, imageClient), driver, blobRepoCacheTTL, false, false)
reg, err := newTestRegistry(ctx, registryclient.NewFakeRegistryAPIClient(nil, imageClient), driver, blobRepoCacheTTL, false, false)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
Expand Down
Loading