-
Notifications
You must be signed in to change notification settings - Fork 29
Conversation
@simon3z PTAL |
@pweil- @ilackarms can you review this? |
@ilackarms @pweil- ping |
@enoodle anything that we can test here? |
@simon3z This is moving a bulk of code into the |
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? |
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. |
@simon3z I added tests here. Some even helped identify a bug with |
pkg/inspector/image-inspector.go
Outdated
|
||
// 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) { |
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.
@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 |
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.
@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?
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 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 |
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.
@enoodle I think this should be an error
that you stringfy only on when some output requires it
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.
@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
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.
never mind that, it can json marshal error
, I will make this change.
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, apparently it is not possible to meaningfully do it yet
golang/go#5161
pkg/inspector/image-inspector.go
Outdated
} | ||
} | ||
|
||
if i.imageServer != nil { | ||
return i.imageServer.ServeImage(&i.meta, i.opts.DstPath, scanResults, scanReport, htmlScanReport) | ||
if i.meta.ImageAcquireSuccess { |
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.
@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
.
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.
Will move to the ServeImage
function.
dba2c89
to
f17e056
Compare
return []iiapi.Result{}, nil, nil | ||
} | ||
|
||
func TestScanImage(t *testing.T) { |
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 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.
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
f17e056
to
d7cfc31
Compare
@simon3z PTAL |
} | ||
i.meta.Image = *imageMetadata | ||
scanResults.ImageID = i.meta.Image.ID | ||
i.meta.ImageAcquireError = 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.
@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,
16f7b3d
to
710bead
Compare
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 { |
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.
@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.
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.
@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.
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.