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
Conversation
79d84c7
to
d25a255
Compare
|
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. |
There was a problem hiding this 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 | |||
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
Please run |
There was a problem hiding this 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.
pkg/clients/openshift.go
Outdated
| // ListRegistryImages - List images in internal OpenShift registry | ||
| func (o OpenshiftClient) ListRegistryImages(log *logging.Logger) (images []string, err error) { | ||
| r := &ImageList{} | ||
| var imageList []string |
There was a problem hiding this comment.
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.
pkg/clients/openshift.go
Outdated
| for _, image := range r.Items { | ||
| imageList = append(imageList, strings.Split(image.DockerImage, "@")[0]) | ||
| } | ||
| if err != nil { |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
|
@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(). |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
fe508bc
to
1205bdf
Compare
|
|
||
| // RegistryName - Retrieve the registry name | ||
| func (r LocalOpenShiftAdapter) RegistryName() string { | ||
| return localOpenShiftName |
There was a problem hiding this comment.
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()
There was a problem hiding this comment.
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.
…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
This PR addresses Bug 1507111 to add an adapter for the internal OpenShift registry.
Changes proposed in this pull request