-
Notifications
You must be signed in to change notification settings - Fork 244
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
File sync for devfiles #2681
Merged
openshift-merge-robot
merged 25 commits into
redhat-developer:master
from
johnmcollier:DevfileSyncing
Mar 12, 2020
Merged
File sync for devfiles #2681
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
c6485ff
Implement devfile syncing on odo push
johnmcollier 98f4c23
Add test for GetRemoteFilesMarkedForDeletion
johnmcollier 0888d70
Properly retrieve sourcePath
johnmcollier 19f0359
Don't push if not needed to
johnmcollier c017d17
Remove duplicate WaitAndGetPod
johnmcollier 49a620a
Use odo volume constants
johnmcollier b33cea8
Fix race condition (oops)
johnmcollier fe7ba17
Fix gosec errors
johnmcollier a49eadf
Add namespace flag to odo push
johnmcollier 48999ab
Implement integration tests for odo push
johnmcollier 9e593e5
Address review comments on tests
johnmcollier 5f5f59f
Remove duplicated preferences lines
johnmcollier ec8a692
Merge branch 'master' of github.com:openshift/odo into DevfileSyncing
johnmcollier 03acdfb
Address review comments
johnmcollier 1994334
Fix unit test
johnmcollier 2625db8
Merge branch 'master' of github.com:openshift/odo into DevfileSyncing
johnmcollier fcd0c07
Address review comments
johnmcollier 3364a1b
Fix rebase
johnmcollier fbdfc0d
Properly return error if sync fails
johnmcollier 1c2a1fb
Sync to `/projects/<projectName>` when needed
johnmcollier b6b7e10
Fix unit tests
johnmcollier c0005c0
Remove debugging line
johnmcollier a010475
Add more unit tests for functions in pushlocal
johnmcollier f0fedb9
Add comments
johnmcollier 18ac435
Fix test on Windows
johnmcollier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -218,6 +218,8 @@ func (a Adapter) createOrUpdateComponent(componentExists bool) (err error) { | |
func (a Adapter) pushLocal(path string, files []string, delFiles []string, isForcePush bool, globExps []string) error { | ||
glog.V(4).Infof("Push: componentName: %s, path: %s, files: %s, delFiles: %s, isForcePush: %+v", a.ComponentName, path, files, delFiles, isForcePush) | ||
|
||
syncFolder := kclient.OdoSourceVolumeMount | ||
|
||
// Edge case: check to see that the path is NOT empty. | ||
emptyDir, err := util.IsEmpty(path) | ||
if err != nil { | ||
|
@@ -246,6 +248,22 @@ func (a Adapter) pushLocal(path string, files []string, delFiles []string, isFor | |
s := log.Spinner("Syncing files to the component") | ||
defer s.End(false) | ||
|
||
// If there's only one project defined in the devfile, sync to `/projects/project-name`, otherwise sync to /projects | ||
projects := a.Devfile.Data.GetProjects() | ||
fmt.Println(len(projects)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like an errant println slipped through There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That was an errant debugging line that slipped through, removed. |
||
if len(projects) == 1 { | ||
syncFolder = filepath.Join(kclient.OdoSourceVolumeMount, projects[0].Name) | ||
|
||
// Need to make sure the folder already exists on the component or else sync will fail | ||
reader, writer := io.Pipe() | ||
glog.V(4).Infof("Creating %s on the remote container if it doesn't already exist", syncFolder) | ||
cmdArr := []string{"mkdir", "-p", syncFolder} | ||
|
||
err := a.Client.ExecCMDInContainer(pod.Name, containerName, cmdArr, writer, writer, reader, false) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
// If there were any files deleted locally, delete them remotely too. | ||
if len(delFiles) > 0 { | ||
reader, writer := io.Pipe() | ||
|
@@ -270,7 +288,7 @@ func (a Adapter) pushLocal(path string, files []string, delFiles []string, isFor | |
|
||
if isForcePush || len(files) > 0 { | ||
glog.V(4).Infof("Copying files %s to pod", strings.Join(files, " ")) | ||
err = sync.CopyFile(&a.Client, path, pod.GetName(), containerName, kclient.OdoSourceVolumeMount, files, globExps) | ||
err = sync.CopyFile(&a.Client, path, pod.GetName(), containerName, syncFolder, files, globExps) | ||
if err != nil { | ||
s.End(false) | ||
return errors.Wrap(err, "unable push files to pod") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 function is doing alot of things, lets try to extract certain portions to make unit testing better.
two suggestions would be be -
1 - https://github.com/openshift/odo/pull/2681/files#diff-825a1a88d75e789899c58e89a79eb767R254-R264 can be extracted into a function
2 - https://github.com/openshift/odo/pull/2681/files#diff-825a1a88d75e789899c58e89a79eb767R268-R277 can be extracted into a function
Also if the function has more then 5 args please try to create a struct to pass on data or consider moving it as part of the method's struct if it doesn't change through out the lifecycle of the struct.
e.g. path and ignoredFiles fields might not change throughout the life of
Adapter
so maybe it can be places as part of the Adapter's struct? - this is just an example.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.
@girishramnani I'm not sure moving those sections into separate functions would make unit testing easier - they both involve exec'ing into an already running container and manipulating the files that exist there, and that can't be mocked with the fake kube client.
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 should be able to mock it 🤔 ( I think kube/openshift would have a mock clientset for whatever function exec is using ) and it will definitely make unit testing pushLocal easier because when you would write test for pushLocal you would mock the https://github.com/openshift/odo/pull/2681/files#diff-825a1a88d75e789899c58e89a79eb767R254-R264 and https://github.com/openshift/odo/pull/2681/files#diff-825a1a88d75e789899c58e89a79eb767R268-R277 functions.
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 think what makes it different is that we're interacting with the kube client differently than we do for other resources. We're interacting directly with the rest client, not calling an existing
exec
function, and I think that doesn't work well with the mock Kube client:and
(see https://github.com/openshift/odo/blob/master/pkg/kclient/pods.go#L93)
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.
As a compromise, rather than putting those sections with the exec into separate functions, what about moving everything before the exec into their own functions (maybe
getCommandToCreateFolder
andgetCommandToDelete
)? Then we could still write unit tests.(Note when moving
ExecCMDInContainer
over from occlient, I couldn't find any references in the existing odo code that had unit tests for it, or unit tests for functions that called it, so other parts of odo have had this problem too.)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.
and that is the reason that we should unit test these as we have the opportunity to re-write/replace this functionality
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 keep that upto you, I just wanted to break this function down into smaller pieces to make it more unit testable
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.
@girishramnani I'll go with approach for now (and see if there are any other pieces we can break up). I'll also address your comment regarding the number of parameters.
Since unit tests for the
ExecCmdInContainer
function will require more work / intevestigation / design, I'll address it as part of #2652 (which is also dealing with unit-testing exec as part of sync)