-
Notifications
You must be signed in to change notification settings - Fork 401
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
Add go module support #60
Conversation
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 looks great! 🎉
Just a few tiny comments, otherwise lgtm
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.
Either way, lgtm, go modules gooooo 🚀
Good question... I'm not sure. I can imagine someone wanting to do this, even though ideally all your source would be within your project. Should we stop people from building external dependencies? |
Yeah I'm just not sure. My instinct says we should disallow it until someone asks for it, because that's easier than locking it down in the future. But how this would manifest is by silently passing the reference through to the output YAML, instead of raising an error. :-/ |
This looks great @jonjohnsonjr. The only caveat about this solution is with multi-modules, if we run
Running |
Yeah that's really frustrating... I was trying to figure out a way around this, but I'm not sure that it's possible to cover 100% of cases we care about. If you can think of a clean way to do this, we can fix it in a separate PR. What's worse is that if you have this:
it won't work either unless you |
Agree with the :-/ but I think you're right. Let's see if anyone actually does this. Updated. |
Let's merge this and see how people feel about it. |
@jonjohnsonjr I've ran into a need for submodules to be ko-applyable. Do you think this is possible? Unfortunately what I have is your worst case scenario:
|
:( I might be mistaken, but I would think that scenario actually works, since the directory structure matches the go module path structure (handled here where we just match the prefix). Can you point me to a repro of this? I can take a look when I get back from kubecon. |
This is based on my comment here.
Fixes #7
This uses
go list -mod=readonly -m -json
to determine if we should use go modules (and fetch required info). For modules, we use theDir
as the source directory root (instead of GOPATH) and thePath
to makeIsSupportedReference
much more efficient for modules.E.g. I've cloned
https://github.com/xmlking/micro-starter-kit
to~/hub/micro-starter-kit
:We call that once per invocation to determine if we're in a project using go modules, then reuse that info in order to find packages with matching import paths. If we don't find one, we fall back to GOPATH (old behavior).
This also uses the
packages
package to handle qualifying local imports (in order to make them work with go modules).