Skip to content
This repository was archived by the owner on Mar 27, 2024. It is now read-only.

Remove Docker dependency for retrieving image filesystem #97

Closed
wants to merge 9 commits into from

Conversation

nkubala
Copy link
Contributor

@nkubala nkubala commented Sep 20, 2017

Also, add support for 'daemon' prefix to specify image in local docker daemon.

cmd/diff.go Outdated
}
return nil
}

func diffImages(image1Arg, image2Arg string, diffArgs []string) error {
diffTypes, err := differs.GetAnalyzers(diffArgs)
if err != nil {
glog.Error(err.Error())
return errors.New("Could not perform image diff")
return fmt.Errorf("err msg: %s", 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.

just return err or make this more informative?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed up the errors in this file

cmd/diff.go Outdated
@@ -116,6 +116,14 @@ func diffImages(image1Arg, image2Arg string, diffArgs []string) error {
return nil
}

func processImageName(imageName string) string {
if pkgutil.IsTar(imageName) || strings.HasPrefix(imageName, "daemon://") {
Copy link
Contributor

Choose a reason for hiding this comment

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

What if it already has remote://? would this add it a second time?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't really planning on advertising that prefix to users, but I guess there's nothing stopping them from adding it in which case this would break. fixed

glog.Infof("Starting prep for image %s", p.Source)
img := p.Source

var prepper Prepper

// first, respect prefixes on image names
if strings.HasPrefix(p.Source, "daemon://") {
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like this should be redundant with the loop below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this was stripping off the prefix of the image source before creating the prepper, but since the rest of the logic was essentially redundant I moved this into the SupportsImage() method.

@@ -47,7 +47,8 @@ func (p CloudPrepper) SupportsImage() bool {
}
strippedSource := strings.Replace(p.ImagePrepper.Source, RemotePrefix, "", -1)
_, err := reference.Parse(p.ImagePrepper.Source)
if err != nil {
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.

i would reverse these conditionals

if err != nil {
  // log the error or inspect it
  return false 
} 

p.ImagePrepper.Source = strippedSource
return true

I also don't like that calling a validation function actually mutates my p.ImagePrepper.Source. Is there a better pattern for prefixing these correctly? Seems very prone to break (repeated calls, calling this with the with/without a prefix, etc.)

Copy link
Contributor

Choose a reason for hiding this comment

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

Thinking a little more, I think the real problem here is that ImagePrepper shouldn't have Source be a string but it should actually be a containers/image types.ImageReference, which is exactly what you can pass into all of the containers/images functions without have to worry about parsing it at the end.

https://github.com/containers/image/blob/master/types/types.go#L37-L90

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are a few problems here, the biggest of which is that the ImagePrepper is supposed to be an abstraction inside of the Prepper interface, and not all implementations have a types.ImageReference (e.g. the TarPrepper) doesn't use this. So there isn't a 1:1 conversion of the source to the ImageReference.

I do agree that mutating the source in the validation function isn't a great pattern though, I'm working on fixing this. We should probably do all source parsing in the client code, and keep everything constant once we get down into the library code that actually does the processing.

Copy link
Contributor

@dlorenc dlorenc left a comment

Choose a reason for hiding this comment

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

A few nits, this looks basically ready to me though.

I think we want to do a bit of cleanup around the ImagePrepper struct and prepper interfaces, but that can come next.

@@ -35,10 +35,10 @@ var diffCmd = &cobra.Command{
Long: `Compares two images using the specifed analyzers as indicated via flags (see documentation for available ones).`,
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably document the available image name flags somewhere, does it make sense here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah I should put it here. should also go in the README somewhere

}
return true
func (p CloudPrepper) GetImage() (Image, error) {
return getImage(p)
Copy link
Contributor

Choose a reason for hiding this comment

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

is getImage used anywhere else? Should you just inline it here instead of breaking it out?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah it's actually the same across all the preppers (currently), but it made more sense to me to just have them all use a helper method and expose the GetImage() publicly on each of the preppers. WDYT?

@nkubala
Copy link
Contributor Author

nkubala commented Sep 21, 2017

Ok, third time's a charm. Closing this to split the refactoring, docker client change, and cleanup into separate PRs for readability.

@nkubala nkubala closed this Sep 21, 2017
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