Skip to content

Commit 16fabd4

Browse files
Merge pull request #16195 from soltysh/image_clientsets
Automatic merge from submit-queue Switch pkg/image to use clientsets @mfojtik @deads2k I hope this handles all of them, including the SAR bits we've talked about yesterday.
2 parents 5f37ec0 + cd5fccb commit 16fabd4

File tree

24 files changed

+257
-221
lines changed

24 files changed

+257
-221
lines changed

pkg/client/imagestreamimages.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ func newImageStreamImages(c *Client, namespace string) *imageStreamImages {
3131
// Get finds the specified image by name of an image repository and id.
3232
func (c *imageStreamImages) Get(name, id string) (result *imageapi.ImageStreamImage, err error) {
3333
result = &imageapi.ImageStreamImage{}
34-
err = c.r.Get().Namespace(c.ns).Resource("imageStreamImages").Name(imageapi.MakeImageStreamImageName(name, id)).Do().Into(result)
34+
err = c.r.Get().Namespace(c.ns).Resource("imageStreamImages").Name(imageapi.JoinImageStreamImage(name, id)).Do().Into(result)
3535
return
3636
}

pkg/cmd/server/admission/init.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/openshift/origin/pkg/client"
1212
configapi "github.com/openshift/origin/pkg/cmd/server/api"
1313
imageapi "github.com/openshift/origin/pkg/image/apis/image"
14+
imageclient "github.com/openshift/origin/pkg/image/generated/internalclientset"
1415
"github.com/openshift/origin/pkg/project/cache"
1516
"github.com/openshift/origin/pkg/quota/controller/clusterquotamapping"
1617
quotainformer "github.com/openshift/origin/pkg/quota/generated/informers/internalversion/quota/internalversion"
@@ -21,6 +22,7 @@ import (
2122

2223
type PluginInitializer struct {
2324
OpenshiftClient client.Interface
25+
OpenshiftInternalImageClient imageclient.Interface
2426
OpenshiftInternalTemplateClient templateclient.Interface
2527
ProjectCache *cache.ProjectCache
2628
OriginQuotaRegistry quota.Registry
@@ -41,6 +43,9 @@ func (i *PluginInitializer) Initialize(plugin admission.Interface) {
4143
if wantsDeprecatedOpenshiftClient, ok := plugin.(WantsDeprecatedOpenshiftClient); ok {
4244
wantsDeprecatedOpenshiftClient.SetDeprecatedOpenshiftClient(i.OpenshiftClient)
4345
}
46+
if wantsOpenshiftImageClient, ok := plugin.(WantsOpenshiftInternalImageClient); ok {
47+
wantsOpenshiftImageClient.SetOpenshiftInternalImageClient(i.OpenshiftInternalImageClient)
48+
}
4449
if WantsOpenshiftInternalTemplateClient, ok := plugin.(WantsOpenshiftInternalTemplateClient); ok {
4550
WantsOpenshiftInternalTemplateClient.SetOpenShiftInternalTemplateClient(i.OpenshiftInternalTemplateClient)
4651
}

pkg/cmd/server/admission/types.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"github.com/openshift/origin/pkg/client"
1111
configapi "github.com/openshift/origin/pkg/cmd/server/api"
12+
imageclient "github.com/openshift/origin/pkg/image/generated/internalclientset"
1213
"github.com/openshift/origin/pkg/project/cache"
1314
"github.com/openshift/origin/pkg/quota/controller/clusterquotamapping"
1415
quotainformer "github.com/openshift/origin/pkg/quota/generated/informers/internalversion/quota/internalversion"
@@ -24,13 +25,20 @@ type WantsDeprecatedOpenshiftClient interface {
2425
admission.Validator
2526
}
2627

27-
// WantDeprecatedOpenshiftClient should be implemented by admission plugins that need
28+
// WantsOpenshiftInternalTemplateClient should be implemented by admission plugins that need
2829
// an Openshift internal template client
2930
type WantsOpenshiftInternalTemplateClient interface {
3031
SetOpenShiftInternalTemplateClient(templateclient.Interface)
3132
admission.Validator
3233
}
3334

35+
// WantsOpenshiftInternalImageClient should be implemented by admission plugins that need
36+
// an Openshift internal image client
37+
type WantsOpenshiftInternalImageClient interface {
38+
SetOpenshiftInternalImageClient(imageclient.Interface)
39+
admission.Validator
40+
}
41+
3442
// WantsProjectCache should be implemented by admission plugins that need a
3543
// project cache
3644
type WantsProjectCache interface {

pkg/cmd/server/origin/master_config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ import (
8181
imagepolicy "github.com/openshift/origin/pkg/image/admission/imagepolicy/api"
8282
imageapi "github.com/openshift/origin/pkg/image/apis/image"
8383
imageinformer "github.com/openshift/origin/pkg/image/generated/informers/internalversion"
84+
imageclient "github.com/openshift/origin/pkg/image/generated/internalclientset"
8485
ingressadmission "github.com/openshift/origin/pkg/ingress/admission"
8586
oauthclient "github.com/openshift/origin/pkg/oauth/generated/internalclientset/typed/oauth/internalversion"
8687
projectauth "github.com/openshift/origin/pkg/project/auth"
@@ -201,6 +202,10 @@ func BuildMasterConfig(options configapi.MasterConfig, informers InformerAccess)
201202
if err != nil {
202203
return nil, err
203204
}
205+
imageClient, err := imageclient.NewForConfig(privilegedLoopbackClientConfig)
206+
if err != nil {
207+
return nil, err
208+
}
204209

205210
templateClient, err := templateclient.NewForConfig(privilegedLoopbackClientConfig)
206211
if err != nil {
@@ -277,6 +282,7 @@ func BuildMasterConfig(options configapi.MasterConfig, informers InformerAccess)
277282
quotaRegistry)
278283
openshiftPluginInitializer := &oadmission.PluginInitializer{
279284
OpenshiftClient: privilegedLoopbackOpenShiftClient,
285+
OpenshiftInternalImageClient: imageClient,
280286
OpenshiftInternalTemplateClient: templateClient,
281287
ProjectCache: projectCache,
282288
OriginQuotaRegistry: quotaRegistry,

pkg/cmd/util/clientcmd/factory_client_access.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
deployapi "github.com/openshift/origin/pkg/apps/apis/apps"
3737
deploycmd "github.com/openshift/origin/pkg/apps/cmd"
3838
"github.com/openshift/origin/pkg/client"
39+
imageclient "github.com/openshift/origin/pkg/image/generated/internalclientset"
3940
imageutil "github.com/openshift/origin/pkg/image/util"
4041
"github.com/openshift/origin/pkg/oc/cli/config"
4142
"github.com/openshift/origin/pkg/oc/cli/describe"
@@ -311,15 +312,20 @@ func (f *ring0Factory) ResolveImage(image string) (string, error) {
311312
if imageutil.IsDocker(options.Source) {
312313
return f.kubeClientAccessFactory.ResolveImage(image)
313314
}
314-
oc, _, err := f.Clients()
315+
config, err := f.OpenShiftClientConfig().ClientConfig()
316+
if err != nil {
317+
return "", err
318+
}
319+
imageClient, err := imageclient.NewForConfig(config)
315320
if err != nil {
316321
return "", err
317322
}
318323
namespace, _, err := f.DefaultNamespace()
319324
if err != nil {
320325
return "", err
321326
}
322-
return imageutil.ResolveImagePullSpec(oc, oc, options.Source, image, namespace)
327+
328+
return imageutil.ResolveImagePullSpec(imageClient.Image(), options.Source, image, namespace)
323329
}
324330

325331
func (f *ring0Factory) Resumer(info *resource.Info) ([]byte, error) {

pkg/dockerregistry/server/signaturedispatcher.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func (s *signatureHandler) Get(w http.ResponseWriter, req *http.Request) {
158158
return
159159
}
160160

161-
image, err := s.isImageClient.ImageStreamImages(s.reference.Namespace).Get(imageapi.MakeImageStreamImageName(s.reference.Name, s.reference.ID), metav1.GetOptions{})
161+
image, err := s.isImageClient.ImageStreamImages(s.reference.Namespace).Get(imageapi.JoinImageStreamImage(s.reference.Name, s.reference.ID), metav1.GetOptions{})
162162
switch {
163163
case err == nil:
164164
case kapierrors.IsUnauthorized(err):

pkg/dockerregistry/testutil/fakeopenshift.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ func (fos *FakeOpenShift) GetImageStreamImage(namespace string, id string) (*ima
287287
isi := imageapiv1.ImageStreamImage{
288288
ObjectMeta: metav1.ObjectMeta{
289289
Namespace: namespace,
290-
Name: imageapi.MakeImageStreamImageName(name, imageID),
290+
Name: imageapi.JoinImageStreamImage(name, imageID),
291291
CreationTimestamp: image.ObjectMeta.CreationTimestamp,
292292
Annotations: repo.Annotations,
293293
},

pkg/image/admission/imagepolicy/imagepolicy.go

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@ import (
1818

1919
"github.com/openshift/origin/pkg/api/latest"
2020
"github.com/openshift/origin/pkg/api/meta"
21-
"github.com/openshift/origin/pkg/client"
2221
oadmission "github.com/openshift/origin/pkg/cmd/server/admission"
2322
configlatest "github.com/openshift/origin/pkg/cmd/server/api/latest"
2423
"github.com/openshift/origin/pkg/image/admission/imagepolicy/api"
2524
"github.com/openshift/origin/pkg/image/admission/imagepolicy/api/validation"
2625
"github.com/openshift/origin/pkg/image/admission/imagepolicy/rules"
2726
imageapi "github.com/openshift/origin/pkg/image/apis/image"
27+
imageclient "github.com/openshift/origin/pkg/image/generated/internalclientset"
28+
imageinternalclient "github.com/openshift/origin/pkg/image/generated/internalclientset/typed/image/internalversion"
2829
"github.com/openshift/origin/pkg/project/cache"
2930
)
3031

@@ -53,7 +54,7 @@ func Register(plugins *admission.Plugins) {
5354
type imagePolicyPlugin struct {
5455
*admission.Handler
5556
config *api.ImagePolicyConfig
56-
client client.Interface
57+
client imageinternalclient.ImageInterface
5758

5859
accepter rules.Accepter
5960

@@ -65,7 +66,7 @@ type imagePolicyPlugin struct {
6566
resolver imageResolver
6667
}
6768

68-
var _ = oadmission.WantsDeprecatedOpenshiftClient(&imagePolicyPlugin{})
69+
var _ = oadmission.WantsOpenshiftInternalImageClient(&imagePolicyPlugin{})
6970
var _ = oadmission.WantsDefaultRegistryFunc(&imagePolicyPlugin{})
7071

7172
type integratedRegistryMatcher struct {
@@ -112,8 +113,8 @@ func (a *imagePolicyPlugin) SetDefaultRegistryFunc(fn func() (string, bool)) {
112113
a.integratedRegistryMatcher.RegistryMatcher = rules.RegistryNameMatcher(fn)
113114
}
114115

115-
func (a *imagePolicyPlugin) SetDeprecatedOpenshiftClient(c client.Interface) {
116-
a.client = c
116+
func (a *imagePolicyPlugin) SetOpenshiftInternalImageClient(c imageclient.Interface) {
117+
a.client = c.Image()
117118
}
118119

119120
func (a *imagePolicyPlugin) SetProjectCache(c *cache.ProjectCache) {
@@ -128,7 +129,7 @@ func (a *imagePolicyPlugin) Validate() error {
128129
if a.projectCache == nil {
129130
return fmt.Errorf("%s needs a project cache", api.PluginName)
130131
}
131-
imageResolver, err := newImageResolutionCache(a.client.Images(), a.client, a.client, a.client, a.integratedRegistryMatcher)
132+
imageResolver, err := newImageResolutionCache(a.client, a.integratedRegistryMatcher)
132133
if err != nil {
133134
return fmt.Errorf("unable to create image policy controller: %v", err)
134135
}
@@ -215,12 +216,9 @@ func (a *imagePolicyPlugin) Admit(attr admission.Attributes) error {
215216
}
216217

217218
type imageResolutionCache struct {
218-
images client.ImageInterface
219-
tags client.ImageStreamTagsNamespacer
220-
streams client.ImageStreamsNamespacer
221-
isImages client.ImageStreamImagesNamespacer
222-
integrated rules.RegistryMatcher
223-
expiration time.Duration
219+
imageClient imageinternalclient.ImageInterface
220+
integrated rules.RegistryMatcher
221+
expiration time.Duration
224222

225223
cache *lru.Cache
226224
}
@@ -231,19 +229,16 @@ type imageCacheEntry struct {
231229
}
232230

233231
// newImageResolutionCache creates a new resolver that caches frequently loaded images for one minute.
234-
func newImageResolutionCache(images client.ImageInterface, tags client.ImageStreamTagsNamespacer, streams client.ImageStreamsNamespacer, isImages client.ImageStreamImagesNamespacer, integratedRegistry rules.RegistryMatcher) (*imageResolutionCache, error) {
232+
func newImageResolutionCache(imageClient imageinternalclient.ImageInterface, integratedRegistry rules.RegistryMatcher) (*imageResolutionCache, error) {
235233
imageCache, err := lru.New(128)
236234
if err != nil {
237235
return nil, err
238236
}
239237
return &imageResolutionCache{
240-
images: images,
241-
tags: tags,
242-
streams: streams,
243-
isImages: isImages,
244-
integrated: integratedRegistry,
245-
cache: imageCache,
246-
expiration: time.Minute,
238+
imageClient: imageClient,
239+
integrated: integratedRegistry,
240+
cache: imageCache,
241+
expiration: time.Minute,
247242
}, nil
248243
}
249244

@@ -299,7 +294,7 @@ func (c *imageResolutionCache) resolveImageReference(ref imageapi.DockerImageRef
299294
return &rules.ImagePolicyAttributes{Name: ref, Image: cached.image}, nil
300295
}
301296
}
302-
image, err := c.images.Get(ref.ID, metav1.GetOptions{})
297+
image, err := c.imageClient.Images().Get(ref.ID, metav1.GetOptions{})
303298
if err != nil {
304299
return nil, err
305300
}
@@ -328,7 +323,7 @@ func (c *imageResolutionCache) resolveImageReference(ref imageapi.DockerImageRef
328323
// or returns an error.
329324
func (c *imageResolutionCache) resolveImageStreamTag(namespace, name, tag string, partial, forceResolveLocalNames bool) (*rules.ImagePolicyAttributes, error) {
330325
attrs := &rules.ImagePolicyAttributes{IntegratedRegistry: true}
331-
resolved, err := c.tags.ImageStreamTags(namespace).Get(name, tag)
326+
resolved, err := c.imageClient.ImageStreamTags(namespace).Get(imageapi.JoinImageStreamTag(name, tag), metav1.GetOptions{})
332327
if err != nil {
333328
if partial {
334329
attrs.IntegratedRegistry = false
@@ -337,7 +332,7 @@ func (c *imageResolutionCache) resolveImageStreamTag(namespace, name, tag string
337332
// to the internal registry. This prevents the lookup from going to the original location, which is consistent
338333
// with the intent of resolving local names.
339334
if isImageStreamTagNotFound(err) {
340-
if stream, err := c.streams.ImageStreams(namespace).Get(name, metav1.GetOptions{}); err == nil && (forceResolveLocalNames || stream.Spec.LookupPolicy.Local) && len(stream.Status.DockerImageRepository) > 0 {
335+
if stream, err := c.imageClient.ImageStreams(namespace).Get(name, metav1.GetOptions{}); err == nil && (forceResolveLocalNames || stream.Spec.LookupPolicy.Local) && len(stream.Status.DockerImageRepository) > 0 {
341336
if ref, err := imageapi.ParseDockerImageReference(stream.Status.DockerImageRepository); err == nil {
342337
glog.V(4).Infof("%s/%s:%s points to a local name resolving stream, but the tag does not exist", namespace, name, tag)
343338
ref.Tag = tag
@@ -374,7 +369,7 @@ func (c *imageResolutionCache) resolveImageStreamTag(namespace, name, tag string
374369
// resolveImageStreamImage loads an image stream image if it exists, or returns an error.
375370
func (c *imageResolutionCache) resolveImageStreamImage(namespace, name, id string) (*rules.ImagePolicyAttributes, error) {
376371
attrs := &rules.ImagePolicyAttributes{IntegratedRegistry: true}
377-
resolved, err := c.isImages.ImageStreamImages(namespace).Get(name, id)
372+
resolved, err := c.imageClient.ImageStreamImages(namespace).Get(imageapi.JoinImageStreamImage(name, id), metav1.GetOptions{})
378373
if err != nil {
379374
return attrs, err
380375
}

0 commit comments

Comments
 (0)