Repository navigation
Replace legacy client in Docker Registry with external clientset - #15624
Conversation
|
@smarterclayton surprise :-) PTAL pls. |
|
FYI, this is first compilable version, I still need to plumb tests. I haven't tested this live yet. The clients will be merged before this: #15625 |
| // openshift helpers here, we need to fix this when we switch those to | ||
| // external versions. | ||
| image := imageapi.Image{} | ||
| if err := imageapiv1.Convert_v1_Image_To_image_Image(&ism.Image, &image, nil); err != nil { |
There was a problem hiding this comment.
@smarterclayton this is controversial... the FillImageMetadata is pretty heavy helper.
There was a problem hiding this comment.
Why is having an external version bad? They aren't changing that much. A copy isn't that bad if tests validate nothing differs between two impls. Image API helpers need to be moved out of that package anyway, and split into discrete groups.
There was a problem hiding this comment.
@smarterclayton i'm fine moving this into v1/helpers.go and start copying helpers we need externally there (including unit tests).
| context.GetLogger(r.ctx).Errorf("failed to convert image %s: %v", image.Name, err) | ||
| return | ||
| } | ||
| if err := imageapi.ImageWithMetadata(&newImage); err != nil { |
There was a problem hiding this comment.
should be util.ImageWithMetadata, will fix
| context.GetLogger(r.ctx).Errorf("failed to convert image %s: %v", image.Name, err) | ||
| return | ||
| } | ||
| if err := imageapi.ImageWithMetadata(&newImage); err != nil { |
There was a problem hiding this comment.
Can you use util.ImageWithMetadata here ?
There was a problem hiding this comment.
yeah, this is really just draft trying to gather early feedback
6e13112 to
64c1019
Compare
| } | ||
|
|
||
| func (c *apiClient) ImageStreamSecrets(namespace string) ImageStreamSecretInterface { | ||
| return c.oc.ImageStreamSecrets(namespace) |
There was a problem hiding this comment.
oc — WIP or will be a follow-up?
There was a problem hiding this comment.
@dmage oc is openshift client, kube is kubernetes client
There was a problem hiding this comment.
Don't we want to replace openshift client with clientset?
There was a problem hiding this comment.
@dmage we don't have client for ImageSecrets yet, so i need to keep legacy for that resource (for now). We need to fix the API to return correct resource instead of []Secret.
| config *clientcmd.Config | ||
| } | ||
|
|
||
| func NewRegistryClient(config *clientcmd.Config) RegistryClient { |
There was a problem hiding this comment.
I hope one day we'll find a better name for this...
There was a problem hiding this comment.
MasterApiClient? or rather masterapiclient.Client?
There was a problem hiding this comment.
I think I will stick with NewRegistryClient for now :)
| @@ -0,0 +1,2 @@ | |||
| // Package client provides functions to make requests to Openshift Master API. | |||
There was a problem hiding this comment.
Ditch it completely. The code should not refer to any product name.
| } | ||
|
|
||
| if len(image.DockerImageLayers) > 0 { | ||
| newImage, err := util.ImageWithMetadata(image) |
There was a problem hiding this comment.
this will move to image/v1/helpers.go
| } | ||
|
|
||
| // resolveImageID returns latest TagEvent for specified imageID and an error if | ||
| // there's more than one image matching the ID or when one does not exist. |
There was a problem hiding this comment.
This is bad, and I don't think we should do it. We want pkg/image/apis/image/helpers/v1 or something.
| @@ -0,0 +1,78 @@ | |||
| // This file was automatically generated by lister-gen | |||
There was a problem hiding this comment.
Split all these out into their own pull ahead of this Pr.
There was a problem hiding this comment.
already done, that commit will go away once this merge #15625
|
/test extended_conformance_install_update |
|
/test extended_conformance_install_update |
1 similar comment
|
/test extended_conformance_install_update |
25d9cde to
9beb9d1
Compare
|
@smarterclayton @dmage @legionus now without any conversions \o/ i moved the helpers to v1/image/helpers.go (unit tests TBD). |
| func sarResponse(ns string, allowed bool, reason string) *authorizationapi.SelfSubjectAccessReview { | ||
| resp := &authorizationapi.SelfSubjectAccessReview{} | ||
| if len(ns) > 0 { | ||
| resp.Namespace = ns |
There was a problem hiding this comment.
No need to be conditional.
| // has already been done. There are none. | ||
| return false | ||
| } | ||
| err = imageapi.ImageWithMetadata(image) |
There was a problem hiding this comment.
Dropping this ImageWithMetadata isn't obvious to me.
@miminar ptal.
There was a problem hiding this comment.
@deads2k this is more complicated... external Image have everything encoded in JSON inside DockerImageMetadata so the filling happens differently there...
|
|
||
| // Interface contains client methods that registry use to communicate with | ||
| // Origin or Kubernetes API. | ||
| type Interface interface { |
There was a problem hiding this comment.
Interesting. I may not have done it, but we'll see how it plays out.
|
|
||
| return newAPIClient( | ||
| oc, | ||
| kc.Core(), |
There was a problem hiding this comment.
why aren't these constructed like the others?
There was a problem hiding this comment.
agree, we don't have force us to use clientmd
| } | ||
|
|
||
| // safeClientConfig returns a client config without authentication info. | ||
| func (с *registryClient) safeClientConfig() restclient.Config { |
There was a problem hiding this comment.
eliminate this function and call the AnonymousClientConfig directly. It's more obvious for people familiar with kube patterns.
| } | ||
|
|
||
| type ImageSignatureInterface interface { | ||
| Create(signature *imageapiv1.ImageSignature) (*imageapiv1.ImageSignature, error) |
There was a problem hiding this comment.
Need type assertions to make sure that the generated clients conform to these interfaces.
| @@ -0,0 +1,31 @@ | |||
| package client | |||
There was a problem hiding this comment.
followup issue: please move this to a fake package.
| var _ ManifestHandler = &manifestSchema1Handler{} | ||
|
|
||
| func (h *manifestSchema1Handler) FillImageMetadata(ctx context.Context, image *imageapi.Image) error { | ||
| func (h *manifestSchema1Handler) FillImageMetadata(ctx context.Context, image *imageapiv1.Image) error { |
There was a problem hiding this comment.
pre-existing, but mutation of args always rubs me the wrong way.
There was a problem hiding this comment.
will capture this as follow up for @legionus
| registryAddr string | ||
| namespace string | ||
| name string | ||
| //config *configuration.Configuration |
|
one question about backwards compatibility. Otherwise, if it looks good to the registry guys, it looks good to me. /approve |
|
@deads2k addressed comments, I also refactored the client a little to be more DRY. Do you know if there is an alternative for |
|
/test extended_conformance_install_update |
| kerrors "k8s.io/apimachinery/pkg/api/errors" | ||
|
|
||
| imageapi "github.com/openshift/origin/pkg/image/apis/image" | ||
| imageapiv1 "github.com/openshift/origin/pkg/image/apis/image/v1" |
There was a problem hiding this comment.
@mfojtik @smarterclayton I think it's strange if we use both versions of the API. I thought the dockerregistry server must use only external API. No?
There was a problem hiding this comment.
agree, we should probably copy the docker types into external version, but I hate to do that just to get rid of this import (we will have two relatively large structs to keep eye on).
There was a problem hiding this comment.
@mfojtik It's not about imports, but about the self-sufficiency of API. In this PR to read the metadata received from the external API you have to use internal API. This means that the external API is not complete.
| image.DockerImageLayers[i].MediaType = layer.MediaType | ||
| } | ||
| // reverse order of the layers for v1 (lowest = 0, highest = i) | ||
| for i, j := 0, len(image.DockerImageLayers)-1; i < j; i, j = i+1, j-1 { |
There was a problem hiding this comment.
@mfojtik I guess this is wrong. The layer list is ordered starting from the base image (opposite order of schema1)
There was a problem hiding this comment.
@legionus i just copied this over from the original helper (I guess it is broken there as well). Mind fixing this as a follow up issue? (don't think it is a blocker for this PR).
|
/lgtm |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: deads2k, legionus, mfojtik The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these OWNERS Files:
You can indicate your approval by writing |
|
/test extended_conformance_install_update flake: #16008 |
|
/test extended_networking_minimal |
|
/test all [submit-queue is verifying that this PR is safe to merge] |
|
flake: #16013 /test extended_conformance_gce |
|
Automatic merge from submit-queue (batch tested with PRs 15964, 15624, 15924) |
|
@mfojtik: The following tests failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
|
@mfojtik congrats! )) |
This use the recent changes to codegen to provide missing clients for some of the image.openshift.io group resouces and then replace clients in registry with external clientsets.
In order to pickup external clients I had to rework the registry code in some places to deal with external types. I failed to do that in some places and fall-backed to conversions, which I hate but it will require more plumbing in the origin code to get this right.
Also I failed to use the external clientset for ImageSecrets as it is implemented as not-standard client returning
[]Secretinstead ofImageSecretList(so we can't generate client for that).Part of fixing: #15272