-
Notifications
You must be signed in to change notification settings - Fork 243
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
Move copyfile function to client-go & remove all ocpath related code #503
Conversation
Works but if I am inside a directory not containing the war file, then push fails
|
c587bc1
to
8c972d8
Compare
@mik-dass , check once again, your path seems to be messed up
|
@surajnarwade Yeah sorry my bad, the problem was the |
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.
It's working for me though just the comments have to be removed
pkg/occlient/occlient.go
Outdated
data *string | ||
format string | ||
} | ||
//func getOcBinary() (string, 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.
@surajnarwade Are these comments required?
pkg/occlient/occlient.go
Outdated
// RsyncPath copies local directory to directory in running Pod. | ||
func (c *Client) RsyncPath(localPath string, targetPodName string, targetPath string) (string, error) { | ||
log.Debugf("Syncing %s to pod %s:%s", localPath, targetPodName, targetPath) | ||
//// RsyncPath copies local directory to directory in running Pod. |
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.
@surajnarwade Are these comments required too?
pkg/occlient/occlient_test.go
Outdated
}) | ||
} | ||
} | ||
//func TestGetOcBinary(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.
@surajnarwade And here also, are they required?
8bef6c8
to
36da172
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.
works for me, LGTM :)
pkg/occlient/occlient.go
Outdated
servicecatalogclienset "github.com/kubernetes-incubator/service-catalog/pkg/client/clientset_generated/clientset/typed/servicecatalog/v1beta1" | ||
appsv1 "github.com/openshift/api/apps/v1" | ||
buildv1 "github.com/openshift/api/build/v1" | ||
imagev1 "github.com/openshift/api/image/v1" |
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 have you grouped everything together?
api objects an clients were separated to make logical groups that are easier to search in
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.
it wasn't me :(
it was my stupid IDE and auto go imports
corrected to original one
When I run
|
It looks like that when running |
When my repository contains bigger file (100M) it fails
|
For more than 100M file,
Reference:
ABOUT PUSHING the content of WHOLE DIRECTORY
according to documentation,
To avoid rsync, I tried to use Tar here, make sense ? @kadel , can you please give me link of python example that you are trying ? |
We can avoid that, just modify watch so it doesn't push the whole directory, but just a single file that has changed, even better tar all the files that changed in the watch loop
the error
is not from fsnotify library but it looks like it is from the |
Hmm, it looks like the 100M problem is away. I can't reproduce it anymore. |
1deedf6
to
28c3a6c
Compare
pkg/occlient/occlient.go
Outdated
//watchTar | ||
for _, fileName := range changedFiles { | ||
if checkFileExist(fileName) { | ||
fmt.Println("sending file", fileName) |
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 probably shouldn't print to stdout. Also, the message is confusing it is not actually sending a file, or is 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.
oh that was my debug line :P
pkg/occlient/occlient.go
Outdated
func (c *Client) RsyncPath(localPath string, targetPodName string, targetPath string) (string, error) { | ||
log.Debugf("Syncing %s to pod %s:%s", localPath, targetPodName, targetPath) | ||
// CopyFile copies single local file to the directory in running Pod. | ||
func (c *Client) CopyFile(asFile bool, localFile string, targetPodName string, targetPath string, changedFiles []string) 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.
We need a comment explaining what the parameters are and fix names.
for example localFile
doesn't have to be always a file, it can be a path to a directory when asFiles
is false.
changedFiles
is also not a good name.
What happens when I set both localFile
and changedFiles
?
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'll add comments, you can't set both localFile
& changedFiles
at once, changedFiles
will only set if we are using odo watch
pkg/occlient/occlient.go
Outdated
} | ||
|
||
// watchTar will be used to tar files using odo watch | ||
func watchTar(tw *taro.Writer, fileName string, destFile string) 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.
watchTar
it looks like you are watching tars :-)
Isn't this function just adding a single file to the taro.Writer
?
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.
yep :|
@@ -1,15 +1,17 @@ | |||
package occlient | |||
|
|||
import ( | |||
taro "archive/tar" |
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 is this taro
and not just tar
?
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.
because there is conflict of name tar
, we are using tar from S2I
as well,
https://github.com/surajnarwade/ocdev/blob/28c3a6c56db39ad593a0cc79b099eea9d1d24535/pkg/occlient/occlient.go#L24
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.
It is broken for binary components!!!
When you try to push on a binary component it looks like it is pushing the whole directory.
We need to fix tests first!!!
This should be caught by tests!
pkg/component/component.go
Outdated
@@ -166,13 +166,14 @@ func GetCurrent(client *occlient.Client, applicationName string, projectName str | |||
|
|||
// PushLocal push local code to the cluster and trigger build there. | |||
// asFile indicates if it is a binary component 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.
this needs to be updated
pkg/component/component.go
Outdated
// We need to make sure that there is a '/' at the end, otherwise rsync will sync files to wrong directory | ||
path = fmt.Sprintf("%s/", path) | ||
} | ||
//if !asFile { |
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.
can we delete this?
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.
yep :|
cmd/push.go
Outdated
if sourceType == "binary" { | ||
asFile = true | ||
var path string | ||
if sourceType == "local" { |
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 odd, what will happen with path when sourceType
is binary?
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.
shouldn't we call PushLocal where the last argument is slice with one file and that is the binary?
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.
that was my stupid mistake :( and was breaking the binary thing
pkg/occlient/occlient.go
Outdated
"--exclude", ".git", | ||
"--no-perms", | ||
// CopyFile copies localFile to the directory in running Pod. | ||
// if asFile is true, localFile will be file otherwise it is path to a directory |
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.
needs to be updated
pkg/occlient/occlient.go
Outdated
// if asFile is true, localFile will be file otherwise it is path to a directory | ||
// copyFiles is list of changed files captured during `odo watch` | ||
// localFile is ignored if copyFiles is set | ||
func (c *Client) CopyFile(localFile string, targetPodName string, targetPath string, copyFiles []string) 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.
localFile
should be named localPath
as it will indicate that we want to copy the whole directory.
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.
it can be binary
as well, so I kept localFile
only
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.
no, first argument should always be a directory. If single file copy is required the last argument should be used
pkg/occlient/occlient.go
Outdated
if len(copyFiles) != 0 { | ||
log.Debugf("Copying files %s to pod %s:%s", copyFiles, targetPodName, targetPath) | ||
} else { | ||
log.Debugf("Copying file %s to pod %s:%s", localFile, targetPodName, targetPath) |
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 should say that it is copying directory not files
Are you sure @mik-dass? Can you please try it again for binary components? |
417b6f6
to
ee14e02
Compare
@kadel , there was my stupid mistake, Now binary components also works :) |
@@ -46,7 +46,7 @@ var watchCmd = &cobra.Command{ | |||
componentName = args[0] | |||
} | |||
|
|||
sourceType, sourcePath, err := component.GetComponentSource(client, componentName, applicationName, projectName) | |||
_, sourcePath, err := component.GetComponentSource(client, componentName, applicationName, projectName) |
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 are we no longer retrieving the sourceType?
pkg/occlient/occlient.go
Outdated
log.Debugf("isLoggedIn err: %#v \n output: %#v", err, string(output)) | ||
// isLoggedIn checks whether user is logged in or not and returns boolean output | ||
func (c *Client) isLoggedIn() bool { | ||
output, err := c.userClient.Users().Get("~", metav1.GetOptions{}) |
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.
What's the purpose of the constant "~"? May have to add a comment here (since I don't understand either)
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.
Home maybe?
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.
it gives us current user
pkg/occlient/occlient.go
Outdated
dest := targetPath + "/" + path.Base(localPath) | ||
reader, writer := io.Pipe() | ||
|
||
go func() { |
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.
Add comment here. This section creates a go routine that creates the tar in the background, correct? Should we add input / any debug information here / progress bar?
pkg/occlient/occlient.go
Outdated
defer writer.Close() | ||
err := makeTar(localPath, dest, writer, copyFiles) | ||
if err != nil { | ||
os.Exit(-1) |
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.
Exists with -1... shouldn't we add an error out here / error message?
} | ||
return nil |
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 don't see a sync check, for this function, should we wait until the go routine is finished before proceeding?
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 am confused little bit, here;s the reference: https://github.com/kubernetes/kubernetes/blob/master/pkg/kubectl/cmd/cp.go#L235
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.
@cdrage go routine is writing to Pipe
via writer
. ExecCMDInContainer
is then streaming it to the command's stdin via reader
. There is no need to sync anything. ExecCMDInContainer
waits for the command to finish, the command will finish only after it receives all the data to stdin.
pkg/occlient/occlient.go
Outdated
var cmdArr []string | ||
|
||
if len(copyFiles) != 0 || string(localPath[len(localPath)-1]) == "/" { | ||
cmdArr = []string{"tar", "xf", "-", "-C", targetPath, "--strip", "1"} |
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're using tar commands here from the OS. even though it's unlikely, the OS may not have tar (windows users, maybe Mac), could we use the tar library that you imported instead
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 tar command runs inside container, so we don't need to worry about it, we are already using tar
library here
pkg/occlient/occlient.go
Outdated
return true | ||
} | ||
|
||
// makeTar function is copied from https://github.com/kubernetes/kubernetes/blob/master/pkg/kubectl/cmd/cp.go#L309 |
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
pkg/occlient/occlient.go
Outdated
func (c *Client) CopyFile(localFile string, targetPodName string, targetPath string) (string, error) { | ||
log.Debugf("Copying file %s to pod %s:%s", localFile, targetPodName, targetPath) | ||
// Tar will be used to tar files using odo watch | ||
func tar(tw *taro.Writer, fileName string, destFile string) 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.
is this function also copied from somewhere else?
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.
yes
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.
Updated with reference link
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.
during odo watch
on binary component I get following message:
DEBU[0009] Copying directory [/Users/tomas/tmp/odo-examples/backend/target/ROOT.war] to pod wildfly-app-1-qfnn5:/opt/app-root/src
Please wait, building component....
It should say "Copying files" not "directory"
Plus it didn't work correctly for some reason.
New war file wasn't used. Component continued to use the old one. Only after I run odo push
the new war file was actually used.
Copy either didn't happen during odo watch
or it was copied to the wrong place.
When doing push on the local component:
empty |
pkg/occlient/occlient.go
Outdated
// copyFiles is list of changed files captured during `odo watch` | ||
// localFile is ignored if copyFiles is set | ||
func (c *Client) CopyFile(localPath string, targetPodName string, targetPath string, copyFiles []string) error { | ||
if len(copyFiles) != 0 || string(localPath[len(localPath)-1]) == "/" { |
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 is it checking if there is /
at the end?
@kadel , I tried to refactor as per your suggestions. But that's not working since it will need path variable as well since we have to define filename in tar header. SO I made couple changes in the code and it seems that everything working fine in all 4 scenarios:
Examples used: |
844ddf3
to
2c3e544
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.
Comments need to be more descriptive.
Code looks good.
pkg/component/component.go
Outdated
@@ -165,14 +165,10 @@ func GetCurrent(client *occlient.Client, applicationName string, projectName str | |||
} | |||
|
|||
// PushLocal push local code to the cluster and trigger build there. | |||
// asFile indicates if it is a binary component or not | |||
func PushLocal(client *occlient.Client, componentName string, applicationName string, path string, asFile bool, out io.Writer) error { | |||
// files is list of changed files captured during `odo watch` or binary file |
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.
The comment should also describe what path
is, and how it relates to files
func (c *Client) RsyncPath(localPath string, targetPodName string, targetPath string) (string, error) { | ||
log.Debugf("Syncing %s to pod %s:%s", localPath, targetPodName, targetPath) | ||
// CopyFile copies localPath directory or list of files in copyFiles list to the directory in running Pod. | ||
// copyFiles is list of changed files captured during `odo watch` as well as binary file path |
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.
The comment should also describe how localPath
relates to copyFiles
. This is really important and not obvious.
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.
Added :0
} | ||
return nil |
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.
@cdrage go routine is writing to Pipe
via writer
. ExecCMDInContainer
is then streaming it to the command's stdin via reader
. There is no need to sync anything. ExecCMDInContainer
waits for the command to finish, the command will finish only after it receives all the data to stdin.
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.
Other than @kadel 's comment, code LGTM and testing works.
Resolves redhat-developer#443 This PR will remove dependency of oc binary for `copyfiles` function which copies file to component while `odo push`
LGTM. |
Resolves #443
This PR will remove dependency of oc binary for
copyfiles
function which copies file to component whileodo push