-
Notifications
You must be signed in to change notification settings - Fork 119
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
feat: allow git remote paths to be provided as source to move2kube #998
Conversation
Thanks for making a pull request! 😃 |
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 for the PR, Venkat, can you look at my comment and also please update this branch. Thanks.
00b0c9f
to
2475da3
Compare
Please consider this alternative, adding the feature behind a flag
Make it easier to integrate with the UI later and it avoids breaking some assumptions we have made in the CLI, API and UI. |
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.
Nice work Venkat! A few suggestions.
cmd/transform.go
Outdated
if err != nil { | ||
logrus.Errorf("Error while getting current user's home directory: %s", err) | ||
} | ||
remoteSourcesFolderAbs, err := filepath.Abs(filepath.Join(homeDir, types.AppName, common.RemoteSourcesFolder)) |
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.
we can use
move2kube/common/pathsofinterest.go
Line 53 in 6156882
TempPath = TempDirPrefix + "temp" |
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.
Please make this configurable with a flag. We can keep temp dir as default if the flag is not provided.
$ move2kube transform \
--source-repo github.com/myaccount/mysourcerepo.git \
--source-repo-dir data/workspaces/1/projects/1/expanded/sources/1
--cust-repo github.com/myaccount/mycustrepo.git \
--cust-repo-dir data/workspaces/1/projects/1/expanded/customizations/1
common/githelper/githelper.go
Outdated
// reference format - git+ssh://<git remote URL>^<branch,tag,commit>^<path within the repo> | ||
// reference format - git+https://<git remote URL>^<branch,tag,commit>^<path within the repo> | ||
// reference format - git+ssh://<git remote URL>^branch_<branchname>^<path within the repo> | ||
// reference format - git+https://<git remote URL>^branch_<branchname>^<path within the repo> |
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.
Why not reuse existing formats like https://pip.pypa.io/en/stable/topics/vcs-support/?
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 for the PR, Venkat, can you look at my comment and also please update this branch. Thanks.
Please consider this alternative, adding the feature behind a flag
$ move2kube transform --source-repo github.com/myaccount/mysourcerepo.git --cust-repo github.com/myaccount/mycustrepo.git
Make it easier to integrate with the UI later and it avoids breaking some assumptions we have made in the CLI, API and UI.
Why would it impact the UI, it would just become an additional feature supported, isn't it? Having a single flag will help avoiding coordinating between the various ways we can get input, isn't 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.
Why would it impact the UI, it would just become an additional feature supported, isn't it? Having a single flag will help avoiding coordinating between the various ways we can get input, isn't it?
Would like expose this feature in the API and UI so that users can provide the URL instead of a zip file for sources and customizations.
If we use a temporary folder it will keep cloning the same repo for every transformation. Making it configurable allows us to clone just once (clone the repo again only if the user tells us to pull some new change).
Having a single flag will help avoiding coordinating between the various ways we can get input, isn't it?
The format you mentioned https://pip.pypa.io/en/stable/topics/vcs-support/ is also valid.
I suggested using a separate flag for simplicity of implementation. It also makes it less likely to accidentally break the default flows we have right now.
common/githelper/githelper.go
Outdated
destpath := filepath.Join(basepath, destFolder) | ||
_, err := os.Stat(destpath) | ||
if err == nil { | ||
return filepath.Join(destpath, grp.PathWithinRepo), err |
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.
return nil
if there is no error
Hello @kmehant I have made the changes suggested by you. Hello @ashokponkumar. I thank you for the suggestions. The package (go git) which I am currently utilising in this work does not support the schema that you have mentioned here #998 (comment). It matches against this regex expression (https://github.com/go-git/go-git/blob/bf3471db54b0255ab5b159005069f37528a151b7/internal/url/url.go#L9) and returns an error as #998 (comment) @ashokponkumar Certainly, I didn't know that we had that in the code, I will utilise that. @HarikrishnanBalagopal I thank you for the suggestions. @HarikrishnanBalagopal and @ashokponkumar I have understood both of your approaches for the flag. However, I don't see any conclusion derived from both of your comments for me to work on changes on using the existing |
Please use the format here https://pip.pypa.io/en/stable/topics/vcs-support/ which should essentially be the input format for the user. Then you could extract components out of it and use it for your clone operation. Please use the existing Can you please extend this work for Once you are ready with the work, can you as well post a video showing the working of the following?
|
@venkatbandarupalli Please be careful while adding comments in Golang. Refer to this https://stackoverflow.com/questions/53004291/exported-type-should-have-comment-or-be-unexported-golang-vs-code. Also, please run Thank you. |
60f5a43
to
b0a3f51
Compare
Codecov ReportPatch coverage has no change and project coverage change:
Additional details and impacted files@@ Coverage Diff @@
## main #998 +/- ##
==========================================
- Coverage 17.66% 17.59% -0.07%
==========================================
Files 63 63
Lines 5249 5268 +19
==========================================
Hits 927 927
- Misses 4074 4093 +19
Partials 248 248
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report in Codecov by Sentry. |
Plan and then transform usecaseTransform usecase |
cmd/plan.go
Outdated
@@ -67,7 +67,8 @@ func planHandler(cmd *cobra.Command, flags planFlags) { | |||
planfile := flags.planfile | |||
srcpath := flags.srcpath | |||
name := flags.name | |||
|
|||
srcPathStruct := common.GetInputClonedPath(srcpath, common.RemoteSourcesFolder, true) |
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.
Line 70 means the following
- srcpath could be path on filesystem or git remote path
- third argument is meant for overwrite and it is set to true
- returned value srcPathStruct is Input struct that holds two values cloned filesystem path and git remote path.
- this implementation is backward compatible. If the input is filesystem path from the user, then the input struct will hold the same filesystem path that user provided and remote git path will be an empty string.
keys := make([]string, 0, len(mapping)) | ||
for k := range mapping { | ||
keys = append(keys, k) | ||
} | ||
|
||
sort.Slice(keys, func(i, j int) bool { | ||
return len(keys[i]) > len(keys[j]) | ||
}) | ||
|
||
for _, src := range keys { | ||
dest := mapping[src] |
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 change was discussed with @kmehant.
I have stumbled across a blocker for plan and then transform usecase.
The problem was with the usage of temp directory to store the remote sources that are cloned.
In the code here https://github.com/konveyor/move2kube/blob/6aee6e37fdb268e5cf0f25f35ffeba00291cc725/common/pathconverters/pathconverters.go#L191
a function is used to convert absolute paths in the plan file to relative paths before being written into plan file.
To this function both temp directory and sources directory are sent.
The implementation tries to get the relative path with any of the provided parent paths to the paths in the plan file.
In the case of using remote move2kube sources in the temp dir makes both of these directories as potential parents for the paths in the plan file.
Due to this reason, I have worked on a workaround where we consider the longest parent paths first and then move to shorter ones.
So that the most matching parents paths are chosen.
This workaround worked for me.
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.
@venkatbandarupalli
This might fail in the below case
If these are the two inputs to the function
/a/v/temp/somefolder
/a/v/temp/anotherfolder
If these are the paths in the plan file
/a/v/temp/anotherfolder/someconfig.yaml
Then ordering the paths based on length might result in
/a/v/temp/somefolder
/a/v/temp/anotherfolder
As I see the first one is chosen always if its a parent then the relative path will become
..
However, the relative path should be
.
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.
we might better iterate over all the paths and then choose the one have the highest prefix match in that case in the above example, the chosen path will be /a/v/temp/anotherfolder
and relative path will be .
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.
lets get inputs from @ashokponkumar and @HarikrishnanBalagopal as well.
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
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 file implements the git vcs feature
func isGitCommitHash(commithash string) bool { | ||
gitCommitHashRegex := regexp.MustCompile(`^[a-fA-F0-9]{40}$`) | ||
return gitCommitHashRegex.MatchString(commithash) | ||
} | ||
|
||
func isGitBranch(branch string) bool { | ||
gitBranchRegex := regexp.MustCompile(`^(main|development|master|(features|tests|(bug|hot)fix)((\/|-)[a-zA-Z0-9]+([-_][a-zA-Z0-9]+)*){1,2}|release(\/|-)[0-9]+(\.[0-9]+)*(-(alpha|beta|rc)[0-9]*)?)$`) | ||
return gitBranchRegex.MatchString(branch) | ||
} | ||
|
||
func isGitTag(tag string) bool { | ||
gitTagRegex := regexp.MustCompile(`^v[0-9]+(\.[0-9]+)?(\.[0-9]+)?$`) | ||
return gitTagRegex.MatchString(tag) | ||
} |
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.
Used regex for effective matching and extraction of parts of information from the input.
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
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 file defines an interface for all the VCS kind of systems that could implement this interface in the future.
b0a3f51
to
d7c307d
Compare
Signed-off-by: venkatbandarupalli <vbandarupalli19@gmail.com>
Signed-off-by: venkatbandarupalli <vbandarupalli19@gmail.com>
…kube Signed-off-by: venkatbandarupalli <vbandarupalli19@gmail.com>
43c5a6e
to
8fa519d
Compare
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.
LGTM
Details
Git remote path format
SSH
HTTPS
Example Usage
move2kube transform -s https://github.com/konveyor/move2kube-demos.git^branch_main^samples/enterprise-app --overwrite