@@ -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) {
5354type 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 {})
6970var _ = oadmission .WantsDefaultRegistryFunc (& imagePolicyPlugin {})
7071
7172type 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
119120func (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
217218type 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.
329324func (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.
375370func (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