Skip to content

Replace legacy client in Docker Registry with external clientset - #15624

Merged
openshift-merge-robot merged 4 commits into
openshift:masterfrom
mfojtik:image-clients
Aug 28, 2017
Merged

openshift-merge-robot merged 4 commits into
openshift:masterfrom
mfojtik:image-clients

Conversation

@mfojtik

@mfojtik mfojtik commented Aug 3, 2017 •

Copy link
Copy Markdown
Contributor

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 []Secret instead of ImageSecretList (so we can't generate client for that).

Part of fixing: #15272

@openshift-merge-robot openshift-merge-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Aug 3, 2017
@openshift-merge-robot openshift-merge-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 3, 2017
@mfojtik

mfojtik commented Aug 3, 2017

Copy link
Copy Markdown
Contributor Author

@smarterclayton surprise :-) PTAL pls.

@mfojtik
mfojtik requested review from dmage, legionus and miminar and removed request for legionus August 3, 2017 13:30
@mfojtik

mfojtik commented Aug 3, 2017

Copy link
Copy Markdown
Contributor Author

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 {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@smarterclayton this is controversial... the FillImageMetadata is pretty heavy helper.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@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 {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you use util.ImageWithMetadata here ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yeah, this is really just draft trying to gather early feedback

@mfojtik
mfojtik force-pushed the image-clients branch 2 times, most recently from 6e13112 to 64c1019 Compare August 3, 2017 18:12
@mfojtik mfojtik removed the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 3, 2017
@openshift-merge-robot openshift-merge-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 3, 2017
}

func (c *apiClient) ImageStreamSecrets(namespace string) ImageStreamSecretInterface {
return c.oc.ImageStreamSecrets(namespace)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

oc — WIP or will be a follow-up?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@dmage oc is openshift client, kube is kubernetes client

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Don't we want to replace openshift client with clientset?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@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 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I hope one day we'll find a better name for this...

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

MasterApiClient? or rather masterapiclient.Client?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think I will stick with NewRegistryClient for now :)

Comment thread pkg/dockerregistry/server/client/doc.go Outdated
@@ -0,0 +1,2 @@
// Package client provides functions to make requests to Openshift Master API.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

OpenShift

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Ditch it completely. The code should not refer to any product name.

}

if len(image.DockerImageLayers) > 0 {
newImage, err := util.ImageWithMetadata(image)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

WIP?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this will move to image/v1/helpers.go

Comment thread pkg/dockerregistry/server/util.go Outdated
}

// 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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is bad, and I don't think we should do it. We want pkg/image/apis/image/helpers/v1 or something.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@smarterclayton good idea

@@ -0,0 +1,78 @@
// This file was automatically generated by lister-gen

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Split all these out into their own pull ahead of this Pr.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

already done, that commit will go away once this merge #15625

@stevekuznetsov

Copy link
Copy Markdown
Contributor

/test extended_conformance_install_update

@stevekuznetsov

Copy link
Copy Markdown
Contributor

/test extended_conformance_install_update

1 similar comment
@stevekuznetsov

Copy link
Copy Markdown
Contributor

/test extended_conformance_install_update

@mfojtik
mfojtik force-pushed the image-clients branch 4 times, most recently from 25d9cde to 9beb9d1 Compare August 4, 2017 11:26
@mfojtik

mfojtik commented Aug 4, 2017

Copy link
Copy Markdown
Contributor Author

@smarterclayton @dmage @legionus now without any conversions \o/ i moved the helpers to v1/image/helpers.go (unit tests TBD).

Comment thread pkg/dockerregistry/server/auth_test.go Outdated
func sarResponse(ns string, allowed bool, reason string) *authorizationapi.SelfSubjectAccessReview {
resp := &authorizationapi.SelfSubjectAccessReview{}
if len(ns) > 0 {
resp.Namespace = ns

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No need to be conditional.

// has already been done. There are none.
return false
}
err = imageapi.ImageWithMetadata(image)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Dropping this ImageWithMetadata isn't obvious to me.

@miminar ptal.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@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 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Interesting. I may not have done it, but we'll see how it plays out.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@deads2k we needed a wrapper if we want to potentially add metrics for the API calls, I think that was originally @legionus idea


return newAPIClient(
oc,
kc.Core(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why aren't these constructed like the others?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

agree, we don't have force us to use clientmd

}

// safeClientConfig returns a client config without authentication info.
func (с *registryClient) safeClientConfig() restclient.Config {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Need type assertions to make sure that the generated clients conform to these interfaces.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

+1 good catch

@@ -0,0 +1,31 @@
package client

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

pre-existing, but mutation of args always rubs me the wrong way.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

will capture this as follow up for @legionus

registryAddr string
namespace string
name string
//config *configuration.Configuration

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

cruft

@deads2k

deads2k commented Aug 25, 2017

Copy link
Copy Markdown
Contributor

one question about backwards compatibility. Otherwise, if it looks good to the registry guys, it looks good to me.

/approve

@mfojtik

mfojtik commented Aug 28, 2017

Copy link
Copy Markdown
Contributor Author

@deads2k addressed comments, I also refactored the client a little to be more DRY. Do you know if there is an alternative for pkg/cmd/util/clientcmd ? (guess we need to read env vars/etc.)

@mfojtik

mfojtik commented Aug 28, 2017 •

Copy link
Copy Markdown
Contributor Author

/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"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@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 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@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).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@mfojtik Sure. Your PR is so huge already.

@legionus

Copy link
Copy Markdown
Contributor

/lgtm
/approve

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Aug 28, 2017
@openshift-merge-robot

Copy link
Copy Markdown
Contributor

[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.

Details Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@mfojtik

mfojtik commented Aug 28, 2017 •

Copy link
Copy Markdown
Contributor Author

/test extended_conformance_install_update

flake: #16008

@mfojtik

mfojtik commented Aug 28, 2017

Copy link
Copy Markdown
Contributor Author

/test extended_networking_minimal

@openshift-merge-robot

Copy link
Copy Markdown
Contributor

/test all [submit-queue is verifying that this PR is safe to merge]

@mfojtik

mfojtik commented Aug 28, 2017

Copy link
Copy Markdown
Contributor Author

flake: #16013

/test extended_conformance_gce

@openshift-merge-robot

Copy link
Copy Markdown
Contributor

Automatic merge from submit-queue (batch tested with PRs 15964, 15624, 15924)

@openshift-merge-robot
openshift-merge-robot merged commit b897684 into openshift:master Aug 28, 2017
@openshift-ci-robot

openshift-ci-robot commented Aug 28, 2017 •

Copy link
Copy Markdown

@mfojtik: The following tests failed, say /retest to rerun them all:

Test name Commit Details Rerun command
ci/openshift-jenkins/extended_image_registry adeaf20 link /test extended_image_registry
ci/openshift-jenkins/extended_conformance_install_update 9364e12 link /test extended_conformance_install_update

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.

Details

Instructions 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

mfojtik commented Aug 28, 2017

Copy link
Copy Markdown
Contributor Author

@legionus @deads2k \o/

@legionus

Copy link
Copy Markdown
Contributor

@mfojtik congrats! ))

@mfojtik
mfojtik deleted the image-clients branch September 5, 2018 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants