Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 1507111 - Add support for a local OpenShift Registry adapter #527

Merged
merged 3 commits into from Nov 3, 2017

Conversation

dymurray
Copy link
Member

@dymurray dymurray commented Nov 1, 2017

This PR addresses Bug 1507111 to add an adapter for the internal OpenShift registry.

Changes proposed in this pull request

  • New adapter file
  • New clusterrolebindings for asb service account to access imagestream resource
  • More openshift client changes so that we can access the imagestream resource

@openshift-ci-robot openshift-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 1, 2017
@dymurray
Copy link
Member Author

dymurray commented Nov 1, 2017

@dymurray dymurray changed the title [Do Not Merge] Bug 1507111 - Add support for a local OpenShift Registry adapter Bug 1507111 - Add support for a local OpenShift Registry adapter Nov 2, 2017
@dymurray
Copy link
Member Author

dymurray commented Nov 2, 2017

Only thing I'm still working on is a unit test.

Edit: The more I tried to write for this I realized that I can't mock out the openshift client. I will need to revisit writing more extensive tests than just checking the config.

Copy link
Contributor

@shawn-hurley shawn-hurley left a comment

Choose a reason for hiding this comment

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

Two small things

@@ -81,6 +81,35 @@ objects:
verbs: ["get", "post", "put", "patch", "delete"]

- apiVersion: v1
kind: ClusterRole
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we just add these to the existing cluster role for asb service account?

Copy link
Member Author

Choose a reason for hiding this comment

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

I actually don't think I can because the other cluster roles are being created under the rbac apiGroup (apiVersion rbac.authorization.k8s.io/v1beta1. I am going to test it to see if there's a way to consolidate them but I thought that would cause roadbumps.

"strings"
)

const localOpenShiftName = "openshift-registry"
Copy link
Contributor

Choose a reason for hiding this comment

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

If the registry name is hardcoded we should make sure that one someone makes a registry they don't have this name for the registry.

Copy link
Member Author

Choose a reason for hiding this comment

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

For this I was following what was done in the other adapters. For example the dockerhub adapter hardcodes the names to docker.io. But yes I agree.

@jmrodri jmrodri self-requested a review November 3, 2017 03:11
@jmrodri
Copy link
Contributor

jmrodri commented Nov 3, 2017

Please run make check. Travis failed because the linter failed. The CI actually worked.

Copy link
Contributor

@jmrodri jmrodri left a comment

Choose a reason for hiding this comment

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

First linter, and a few places where we're eating errors.

// ListRegistryImages - List images in internal OpenShift registry
func (o OpenshiftClient) ListRegistryImages(log *logging.Logger) (images []string, err error) {
r := &ImageList{}
var imageList []string
Copy link
Contributor

Choose a reason for hiding this comment

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

Flip lines 371 and 370. I almost didn't see where r was being assigned.

for _, image := range r.Items {
imageList = append(imageList, strings.Split(image.DockerImage, "@")[0])
}
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is checking the error return from the imageRestClient? If there's an error from the client how can r be filled out and have items?

I think line 380 error check should be on line 377 BEFORE you loop through r.Items.

r.Log.Debug("LocalOpenShiftAdapter::GetImageNames")
r.Log.Debug("BundleSpecLabel: %s", BundleSpecLabel)

openshiftClient, err := clients.Openshift(r.Log)
Copy link
Contributor

Choose a reason for hiding this comment

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

you are eating the err. If that clients.Openshift failed, line 51 will die a miserable death which might be a panic.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, fixed

r.Log.Debug("LocalOpenShiftAdapter::FetchSpecs")
r.Log.Debugf("HERE %v", r.Config.Namespaces)
specList := []*apb.Spec{}
registryIP, err := r.getServiceIP("docker-registry", "default")
Copy link
Contributor

Choose a reason for hiding this comment

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

eating another err, you might be able to do something like

var registryIP WHATEVERITRETURNS
var err error

if registryIP, err := r.getServiceIP("docker-registry", "default"); err != nil {
   r.logErrorf("Failed to load registry images")
   return nil, err
}

specList := []*apb.Spec{}
registryIP, err := r.getServiceIP("docker-registry", "default")

openshiftClient, err := clients.Openshift(r.Log)
Copy link
Contributor

Choose a reason for hiding this comment

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

another err eaten


func (r LocalOpenShiftAdapter) loadSpec(yamlSpec []byte) (*apb.Spec, error) {
r.Log.Debug("LocalOpenShiftAdapter::LoadSpec")
var err error
Copy link
Contributor

Choose a reason for hiding this comment

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

weird to declare a var when you can easily do err := yaml.Unmarshal on line 103.

serviceData, err := k8scli.CoreV1().Services(namespace).Get(service, meta_v1.GetOptions{})
if err != nil {
r.Log.Warningf("Unable to load service '%s' from namespace '%s'", service, namespace)
return "", nil
Copy link
Contributor

Choose a reason for hiding this comment

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

So we got an error but we're returning nil?

@dymurray
Copy link
Member Author

dymurray commented Nov 3, 2017

@jmrodri @shawn-hurley Thanks for the feedback guys. I think I've addressed everything except for the hardcoded name. Let me know your thoughts on that.

fqImage := FQImage{}
var err error
r := &ImageList{}
err = o.imageRestClient.Get().
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, didn't catch this one before, but should check the error before working with the items.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, fixed

Updates to getImageList
more updates
Remove unneeded yaml files
Add configuration ability for administrator
Added unit test
Linting fixes

// RegistryName - Retrieve the registry name
func (r LocalOpenShiftAdapter) RegistryName() string {
return localOpenShiftName
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the name can be changed of the registry. Think this should be like rhcc: return r.Config.URL.String()

Copy link
Contributor

@rthallisey rthallisey Nov 3, 2017

Choose a reason for hiding this comment

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

The internal registry uses the api. Name will always be the same.

@jmrodri jmrodri added bug and removed needs-review labels Nov 3, 2017
@shawn-hurley shawn-hurley merged commit e543438 into openshift:master Nov 3, 2017
jianzhangbjz pushed a commit to jianzhangbjz/ansible-service-broker that referenced this pull request May 17, 2018
…nshift#527)

* Bug 1507111 - Add local openshift registry adapter
Updates to getImageList
more updates
Remove unneeded yaml files
Add configuration ability for administrator
Added unit test
Linting fixes

* Move cluster role declaration to preexisting one

* Fix template
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants