Skip to content
This repository has been archived by the owner on Dec 9, 2022. It is now read-only.

serve the status of image acquiring #82

Merged
merged 5 commits into from
Jan 23, 2018

Conversation

enoodle
Copy link

@enoodle enoodle commented Nov 22, 2017

When image-inspector fails to acquire an image and is in the serve mode it fails to serve this status and just exists. I consider this a bug.
To fix I added two fields to the metadata status: ImageAcquireSuccess, ImageAcquireError to report that status.

@bazulay
Copy link

bazulay commented Nov 22, 2017

@simon3z PTAL

@simon3z
Copy link

simon3z commented Nov 23, 2017

@pweil- @ilackarms can you review this?

@enoodle
Copy link
Author

enoodle commented Dec 5, 2017

@ilackarms @pweil- ping

@simon3z
Copy link

simon3z commented Jan 4, 2018

@enoodle anything that we can test here?

@enoodle
Copy link
Author

enoodle commented Jan 4, 2018

@simon3z This is moving a bulk of code into the acquireImage function and then depending on the error either continue or serve the result.
To test this I wanted a good way to fail acquireImage and this is one of the reasons that made me create #87.
I can try to move those tests form there to here, but if this is the only problem with this PR then I think we should first go with #87 and then get those tests .

@simon3z
Copy link

simon3z commented Jan 5, 2018

IIUC you want to add the ability to expose a more granular image-inspector status through the rest-api, and you want to do that before a new release.

Now the question is, do you feel more confident that either this PR or #87 are going to solve more issues than creating new ones? If so how can we be sure about that?

Do you prefer to go with #87 with many more changes and partly tested (and you can add more), or do you want to work more on this one with less changes (smaller impact overall) and trying to add some tests?

@enoodle
Copy link
Author

enoodle commented Jan 5, 2018

I feel that the code is getting too much complicated to keep in one package and that #87 simplifies things. most of the code was just moved and not changed so it not such a big change in my opinion.
I think postponing the change will only make it harder later and that fixing problems and getting new releases is not a difficulty worth not making changes for. So I would go with #87 first.

@enoodle
Copy link
Author

enoodle commented Jan 14, 2018

@simon3z I added tests here. Some even helped identify a bug with decodeDockerResponse that I fixed.


// acquireImage returns error, the docker image that was acquired, the image ID,
// the container ID that the image was acquired from, and iiapi.FilesFilter for this image.
func (i *defaultImageInspector) acquireImage(client DockerRuntimeClient) (error, docker.Image, string, string, iiapi.FilesFilter) {
Copy link

Choose a reason for hiding this comment

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

@enoodle when you return such a large number of items you may want to consider an object approach, e.g. either you make those attributes of the relevant defaultImageInspector class (if it makes sense), or you return an object of a new class.

pkg/api/types.go Outdated
@@ -93,6 +93,9 @@ var (

// InspectorMetadata is the metadata type with information about image-inspector's operation
type InspectorMetadata struct {
ImageAcquireSuccess bool // status of aquiring the image
Copy link

Choose a reason for hiding this comment

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

@enoodle do you need to make this an attribute or could it be just a method that that relies on whether ImageAcquireError is nil or not?

Copy link
Author

Choose a reason for hiding this comment

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

I can do that, It is mostly effecting on the user side.

pkg/api/types.go Outdated
@@ -93,6 +93,9 @@ var (

// InspectorMetadata is the metadata type with information about image-inspector's operation
type InspectorMetadata struct {
ImageAcquireSuccess bool // status of aquiring the image
ImageAcquireError string // error message from aquiring the image
Copy link

Choose a reason for hiding this comment

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

@enoodle I think this should be an error that you stringfy only on when some output requires it

Copy link
Author

Choose a reason for hiding this comment

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

@simon3z This struct is served as a JSON to the user [1], so I can't have error here.

[1] https://github.com/openshift/image-inspector/blob/master/pkg/imageserver/webdav.go#L96

Copy link
Author

Choose a reason for hiding this comment

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

never mind that, it can json marshal error, I will make this change.

Copy link
Author

Choose a reason for hiding this comment

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

Sorry, apparently it is not possible to meaningfully do it yet
golang/go#5161

}
}

if i.imageServer != nil {
return i.imageServer.ServeImage(&i.meta, i.opts.DstPath, scanResults, scanReport, htmlScanReport)
if i.meta.ImageAcquireSuccess {
Copy link

Choose a reason for hiding this comment

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

@enoodle it's not easy to understand why you need this check now. In general I would try to encapsulate any further logic in ServeImage.

Copy link
Author

Choose a reason for hiding this comment

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

Will move to the ServeImage function.

@enoodle enoodle force-pushed the serve_image_aquire_status branch from dba2c89 to f17e056 Compare January 14, 2018 17:43
return []iiapi.Result{}, nil, nil
}

func TestScanImage(t *testing.T) {
Copy link
Author

Choose a reason for hiding this comment

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

This test was meaningless , I used to test something but over the time it was refactored not to test anything and the function it used to test was removed.

Erez Freiberger added 3 commits January 15, 2018 10:09
Factoring out the whole image acquiring to a function and
abstracting docker client with an interface to ease testing
also checking return value of getContainerChanges
@enoodle enoodle force-pushed the serve_image_aquire_status branch from f17e056 to d7cfc31 Compare January 15, 2018 08:10
@enoodle
Copy link
Author

enoodle commented Jan 15, 2018

@simon3z PTAL

}
i.meta.Image = *imageMetadata
scanResults.ImageID = i.meta.Image.ID
i.meta.ImageAcquireError = err.Error()
Copy link

Choose a reason for hiding this comment

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

@enoodle please keep the logic of this (already too long) method simple and return on error.

If you need to serve even on error please use a wrapper method,

@enoodle enoodle force-pushed the serve_image_aquire_status branch from 16f7b3d to 710bead Compare January 16, 2018 11:44
@enoodle
Copy link
Author

enoodle commented Jan 23, 2018

ping @simon3z Can you take another look?

// acquireImage returns error and iiapi.FilesFilter for this image.
func (i *defaultImageInspector) acquireImage(client DockerRuntimeClient) (error, iiapi.FilesFilter) {
var err error
if len(i.opts.Container) == 0 {
Copy link

Choose a reason for hiding this comment

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

@enoodle this method calls for a refactoring, anything that looks like

func ... {
    if (...) {
        ...
    } else {
        ...
    }
}

should be better designed.

Anyway it's not for this PR.

Copy link

Choose a reason for hiding this comment

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

@enoodle to be clear you can just factor out those large bodies to other functions, etc. what I am saying is that a whole long function with two in-line code paths should be refactored.

@simon3z simon3z merged commit ba9122f into openshift:master Jan 23, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants