Skip to content

Commit 906cbfd

Browse files
committed
registry: use imagestream clientset to get secrets
1 parent e765e9c commit 906cbfd

15 files changed

+96
-95
lines changed

pkg/dockerregistry/server/blobdescriptorservice_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ func TestBlobDescriptorServiceIsApplied(t *testing.T) {
4848
// to make other unit tests working
4949
defer m.changeUnsetRepository(false)
5050

51-
fos, client, imageClient := registrytest.NewFakeOpenShiftWithClient()
51+
fos, _, imageClient := registrytest.NewFakeOpenShiftWithClient()
5252
testImage := registrytest.AddRandomImage(t, fos, "user", "app", "latest")
5353

5454
ctx := context.Background()
5555
ctx = WithConfiguration(ctx, &srvconfig.Configuration{})
56-
ctx = WithRegistryClient(ctx, registryclient.NewFakeRegistryClient(client, imageClient))
56+
ctx = WithRegistryClient(ctx, registryclient.NewFakeRegistryClient(imageClient))
5757
app := handlers.NewApp(ctx, &configuration.Configuration{
5858
Loglevel: "debug",
5959
Auth: map[string]configuration.Parameters{

pkg/dockerregistry/server/client/client.go

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
authclientv1 "k8s.io/kubernetes/pkg/client/clientset_generated/clientset/typed/authorization/v1"
66
kcoreclient "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/core/internalversion"
77

8-
osclient "github.com/openshift/origin/pkg/client"
98
"github.com/openshift/origin/pkg/cmd/util/clientcmd"
109
imageclientv1 "github.com/openshift/origin/pkg/image/generated/clientset/typed/image/v1"
1110
userclientv1 "github.com/openshift/origin/pkg/user/generated/clientset/typed/user/v1"
@@ -36,22 +35,19 @@ type Interface interface {
3635
}
3736

3837
type apiClient struct {
39-
oc osclient.Interface
4038
kube kcoreclient.CoreInterface
4139
auth authclientv1.AuthorizationV1Interface
4240
image imageclientv1.ImageV1Interface
4341
user userclientv1.UserV1Interface
4442
}
4543

4644
func newAPIClient(
47-
c osclient.Interface,
4845
kc kcoreclient.CoreInterface,
4946
authClient authclientv1.AuthorizationV1Interface,
5047
imageClient imageclientv1.ImageV1Interface,
5148
userClient userclientv1.UserV1Interface,
5249
) Interface {
5350
return &apiClient{
54-
oc: c,
5551
kube: kc,
5652
auth: authClient,
5753
image: imageClient,
@@ -88,9 +84,7 @@ func (c *apiClient) ImageStreamTags(namespace string) ImageStreamTagInterface {
8884
}
8985

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

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

108102
type registryClient struct {
109-
kubeConfig *restclient.Config
110-
openshiftConfig *restclient.Config
103+
kubeConfig *restclient.Config
111104
}
112105

113106
// NewRegistryClient provides a new registry client.
107+
// TODO: Remove clientcmd dependency and move the parsing of required
108+
// environemtn variable to registry.
114109
func NewRegistryClient(config *clientcmd.Config) RegistryClient {
115110
return &registryClient{
116-
kubeConfig: config.KubeConfig(),
117-
openshiftConfig: config.OpenShiftConfig(),
111+
kubeConfig: config.KubeConfig(),
118112
}
119113
}
120114

121115
// Client returns the authenticated client to use with the server.
122116
func (c *registryClient) Client() (Interface, error) {
123117
return newAPIClient(
124-
osclient.NewOrDie(c.openshiftConfig),
125118
kcoreclient.NewForConfigOrDie(c.kubeConfig),
126119
authclientv1.NewForConfigOrDie(c.kubeConfig),
127120
imageclientv1.NewForConfigOrDie(c.kubeConfig),
@@ -132,14 +125,9 @@ func (c *registryClient) Client() (Interface, error) {
132125
// ClientFromToken returns the client based on the bearer token.
133126
func (c *registryClient) ClientFromToken(token string) (Interface, error) {
134127
newClient := *c
135-
newOpenshiftConfig := clientcmd.AnonymousClientConfig(newClient.openshiftConfig)
136-
newOpenshiftConfig.BearerToken = token
137-
138128
newKubeconfig := *newClient.kubeConfig
139129
newKubeconfig.BearerToken = token
140-
141130
newClient.kubeConfig = &newKubeconfig
142-
newClient.openshiftConfig = &newOpenshiftConfig
143131

144132
return newClient.Client()
145133
}

pkg/dockerregistry/server/client/interfaces.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package client
33
import (
44
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
55
kapi "k8s.io/kubernetes/pkg/api"
6+
kapiv1 "k8s.io/kubernetes/pkg/api/v1"
67
kcoreclient "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/core/internalversion"
78

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

107+
var _ ImageStreamSecretInterface = imageclientv1.ImageStreamInterface(nil)
108+
106109
type ImageStreamSecretInterface interface {
107-
Secrets(name string, options metav1.ListOptions) (*kapi.SecretList, error)
110+
Secrets(name string, options metav1.ListOptions) (*kapiv1.SecretList, error)
108111
}
109112

110113
var _ LimitRangeInterface = kcoreclient.LimitRangeInterface(nil)

pkg/dockerregistry/server/client/test.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,26 @@ package client
33
import (
44
kcoreclient "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/core/internalversion"
55

6-
"github.com/openshift/origin/pkg/client"
76
imageclientv1 "github.com/openshift/origin/pkg/image/generated/clientset/typed/image/v1"
87
)
98

109
type fakeRegistryClient struct {
1110
RegistryClient
1211

13-
client client.Interface
1412
images imageclientv1.ImageV1Interface
1513
}
1614

17-
func NewFakeRegistryClient(c client.Interface, imageclient imageclientv1.ImageV1Interface) RegistryClient {
15+
func NewFakeRegistryClient(imageclient imageclientv1.ImageV1Interface) RegistryClient {
1816
return &fakeRegistryClient{
1917
RegistryClient: &registryClient{},
20-
client: c,
2118
images: imageclient,
2219
}
2320
}
2421

2522
func (c *fakeRegistryClient) Client() (Interface, error) {
26-
return newAPIClient(c.client, nil, nil, c.images, nil), nil
23+
return newAPIClient(nil, nil, c.images, nil), nil
2724
}
2825

29-
func NewFakeRegistryAPIClient(c client.Interface, kc kcoreclient.CoreInterface, imageclient imageclientv1.ImageV1Interface) Interface {
30-
return newAPIClient(c, nil, nil, imageclient, nil)
26+
func NewFakeRegistryAPIClient(kc kcoreclient.CoreInterface, imageclient imageclientv1.ImageV1Interface) Interface {
27+
return newAPIClient(nil, nil, imageclient, nil)
3128
}

pkg/dockerregistry/server/manifestservice_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ func TestManifestServiceExists(t *testing.T) {
1919
repo := "app"
2020
tag := "latest"
2121

22-
fos, client, imageClient := testutil.NewFakeOpenShiftWithClient()
22+
fos, _, imageClient := testutil.NewFakeOpenShiftWithClient()
2323
testImage := testutil.AddRandomImage(t, fos, namespace, repo, tag)
2424

2525
r := newTestRepository(t, namespace, repo, testRepositoryOptions{
26-
client: registryclient.NewFakeRegistryAPIClient(client, nil, imageClient),
26+
client: registryclient.NewFakeRegistryAPIClient(nil, imageClient),
2727
})
2828

2929
ms := &manifestService{
@@ -51,7 +51,7 @@ func TestManifestServiceGetDoesntChangeDockerImageReference(t *testing.T) {
5151
repo := "app"
5252
tag := "latest"
5353

54-
fos, client, imageClient := testutil.NewFakeOpenShiftWithClient()
54+
fos, _, imageClient := testutil.NewFakeOpenShiftWithClient()
5555

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

7979
r := newTestRepository(t, namespace, repo, testRepositoryOptions{
80-
client: registryclient.NewFakeRegistryAPIClient(client, nil, imageClient),
80+
client: registryclient.NewFakeRegistryAPIClient(nil, imageClient),
8181
})
8282

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

116-
_, client, imageClient := testutil.NewFakeOpenShiftWithClient()
116+
_, _, imageClient := testutil.NewFakeOpenShiftWithClient()
117117

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

124124
r := newTestRepository(t, namespace, repo, testRepositoryOptions{
125-
client: registryclient.NewFakeRegistryAPIClient(client, nil, imageClient),
125+
client: registryclient.NewFakeRegistryAPIClient(nil, imageClient),
126126
blobs: bs,
127127
})
128128

@@ -146,7 +146,7 @@ func TestManifestServicePut(t *testing.T) {
146146
},
147147
}
148148

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

162162
// recreate repository to reset cached image stream
163163
r = newTestRepository(t, namespace, repo, testRepositoryOptions{
164-
client: registryclient.NewFakeRegistryAPIClient(client, nil, imageClient),
164+
client: registryclient.NewFakeRegistryAPIClient(nil, imageClient),
165165
blobs: bs,
166166
})
167167

pkg/dockerregistry/server/pullthroughblobstore_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func TestPullthroughServeBlob(t *testing.T) {
4646
os.Setenv("OPENSHIFT_DEFAULT_REGISTRY", serverURL.Host)
4747
testImage.DockerImageReference = fmt.Sprintf("%s/%s@%s", serverURL.Host, repoName, testImage.Name)
4848

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

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

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

289289
ctx := WithTestPassthroughToUpstream(context.Background(), false)
290290
repo := newTestRepository(t, namespace, name, testRepositoryOptions{
291-
client: registryclient.NewFakeRegistryAPIClient(client, nil, imageClient),
291+
client: registryclient.NewFakeRegistryAPIClient(nil, imageClient),
292292
enablePullThrough: true,
293293
})
294294
ptbs := &pullthroughBlobStore{
@@ -598,7 +598,7 @@ func TestPullthroughServeBlobInsecure(t *testing.T) {
598598
expectedBytesServed: int64(m1img.DockerImageLayers[0].LayerSize),
599599
},
600600
} {
601-
fos, client, imageClient := registrytest.NewFakeOpenShiftWithClient()
601+
fos, _, imageClient := registrytest.NewFakeOpenShiftWithClient()
602602

603603
tc.fakeOpenShiftInit(fos)
604604

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

609609
repo := newTestRepository(t, namespace, repo1, testRepositoryOptions{
610-
client: registryclient.NewFakeRegistryAPIClient(client, nil, imageClient),
610+
client: registryclient.NewFakeRegistryAPIClient(nil, imageClient),
611611
enablePullThrough: true,
612612
})
613613

pkg/dockerregistry/server/pullthroughmanifestservice_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func TestPullthroughManifests(t *testing.T) {
9393
image.DockerImageReference = fmt.Sprintf("%s/%s/%s@%s", serverURL.Host, namespace, repo, image.Name)
9494
image.DockerImageManifest = ""
9595

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

138138
repo := newTestRepository(t, namespace, repo, testRepositoryOptions{
139-
client: registryclient.NewFakeRegistryAPIClient(client, nil, imageClient),
139+
client: registryclient.NewFakeRegistryAPIClient(nil, imageClient),
140140
enablePullThrough: true,
141141
})
142142

@@ -351,15 +351,15 @@ func TestPullthroughManifestInsecure(t *testing.T) {
351351
},
352352
},
353353
} {
354-
fos, client, imageClient := registrytest.NewFakeOpenShiftWithClient()
354+
fos, _, imageClient := registrytest.NewFakeOpenShiftWithClient()
355355

356356
tc.fakeOpenShiftInit(fos)
357357

358358
localManifestService := newTestManifestService(repoName, tc.localData)
359359

360360
ctx := WithTestPassthroughToUpstream(context.Background(), false)
361361
repo := newTestRepository(t, namespace, repo, testRepositoryOptions{
362-
client: registryclient.NewFakeRegistryAPIClient(client, nil, imageClient),
362+
client: registryclient.NewFakeRegistryAPIClient(nil, imageClient),
363363
enablePullThrough: true,
364364
})
365365
ctx = withRepository(ctx, repo)
@@ -459,7 +459,7 @@ func TestPullthroughManifestDockerReference(t *testing.T) {
459459
image2 := *img
460460
image2.DockerImageReference = dockerImageReference(server2, "foo/bar")
461461

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

495495
r := newTestRepository(t, namespace, tc.repoName, testRepositoryOptions{
496-
client: registryclient.NewFakeRegistryAPIClient(client, nil, imageClient),
496+
client: registryclient.NewFakeRegistryAPIClient(nil, imageClient),
497497
enablePullThrough: true,
498498
})
499499

pkg/dockerregistry/server/repositorymiddleware_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ func TestRepositoryBlobStat(t *testing.T) {
297297
ctx = withDeferredErrors(ctx, tc.deferredErrors)
298298
}
299299

300-
fos, client, imageClient := registrytest.NewFakeOpenShiftWithClient()
300+
fos, _, imageClient := registrytest.NewFakeOpenShiftWithClient()
301301

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

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

378-
fos, client, imageClient := registrytest.NewFakeOpenShiftWithClient()
378+
fos, _, imageClient := registrytest.NewFakeOpenShiftWithClient()
379379
registrytest.AddImageStream(t, fos, "nm", "is", nil)
380380
registrytest.AddImage(t, fos, testImage, "nm", "is", "latest")
381381

382-
reg, err := newTestRegistry(ctx, registryclient.NewFakeRegistryAPIClient(client, nil, imageClient), driver, blobRepoCacheTTL, false, false)
382+
reg, err := newTestRegistry(ctx, registryclient.NewFakeRegistryAPIClient(nil, imageClient), driver, blobRepoCacheTTL, false, false)
383383
if err != nil {
384384
t.Fatalf("unexpected error: %v", err)
385385
}

pkg/dockerregistry/server/signaturedispatcher_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,19 @@ func TestSignatureGet(t *testing.T) {
4747
testImage.DockerImageManifest = ""
4848
testImage.Signatures = append(testImage.Signatures, testSignature)
4949

50-
fos, client, imageClient := registrytest.NewFakeOpenShiftWithClient()
50+
fos, _, imageClient := registrytest.NewFakeOpenShiftWithClient()
5151
registrytest.AddImageStream(t, fos, "user", "app", map[string]string{
5252
imageapi.InsecureRepositoryAnnotation: "true",
5353
})
5454
registrytest.AddImage(t, fos, testImage, "user", "app", "latest")
5555

56-
osclient, err := registryclient.NewFakeRegistryClient(client, imageClient).Client()
56+
osclient, err := registryclient.NewFakeRegistryClient(imageClient).Client()
5757
if err != nil {
5858
t.Fatal(err)
5959
}
6060

6161
ctx := context.Background()
62-
ctx = WithRegistryClient(ctx, registryclient.NewFakeRegistryClient(client, imageClient))
62+
ctx = WithRegistryClient(ctx, registryclient.NewFakeRegistryClient(imageClient))
6363
ctx = WithConfiguration(ctx, &regconfig.Configuration{})
6464
ctx = withUserClient(ctx, osclient)
6565
registryApp := handlers.NewApp(ctx, &configuration.Configuration{
@@ -162,13 +162,13 @@ func TestSignaturePut(t *testing.T) {
162162
return true, sign, nil
163163
})
164164

165-
osclient, err := registryclient.NewFakeRegistryClient(nil, imageClient).Client()
165+
osclient, err := registryclient.NewFakeRegistryClient(imageClient).Client()
166166
if err != nil {
167167
t.Fatal(err)
168168
}
169169

170170
ctx := context.Background()
171-
ctx = WithRegistryClient(ctx, registryclient.NewFakeRegistryClient(nil, imageClient))
171+
ctx = WithRegistryClient(ctx, registryclient.NewFakeRegistryClient(imageClient))
172172
ctx = WithConfiguration(ctx, &regconfig.Configuration{})
173173
ctx = withUserClient(ctx, osclient)
174174
registryApp := handlers.NewApp(ctx, &configuration.Configuration{

0 commit comments

Comments
 (0)