Skip to content

Commit

Permalink
Move copyfiles function to client-go
Browse files Browse the repository at this point in the history
Resolves #443

This PR will remove dependency of oc binary for `copyfiles` function which copies file to component while `odo push`
  • Loading branch information
surajnarwade committed Jun 14, 2018
1 parent f528d59 commit 533f5e2
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 240 deletions.
2 changes: 1 addition & 1 deletion cmd/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ var pushCmd = &cobra.Command{
if sourceType == "binary" {
asFile = true
}
err = component.PushLocal(client, componentName, applicationName, u.Path, asFile, os.Stdout)
err = component.PushLocal(client, componentName, applicationName, u.Path, asFile, os.Stdout, []string{})
checkError(err, fmt.Sprintf("failed to push component: %v", componentName))
case "git":
// currently we don't support changing build type
Expand Down
10 changes: 2 additions & 8 deletions pkg/component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ 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 {
func PushLocal(client *occlient.Client, componentName string, applicationName string, path string, asFile bool, out io.Writer, watchedFiles []string) error {
const targetPath = "/opt/app-root/src"

if !asFile {
Expand All @@ -175,17 +175,11 @@ func PushLocal(client *occlient.Client, componentName string, applicationName st
if err != nil {
return errors.Wrapf(err, "error while waiting for pod %s", podSelector)
}
var syncOutput string
if !asFile {
syncOutput, err = client.RsyncPath(path, pod.Name, targetPath)
} else {
syncOutput, err = client.CopyFile(path, pod.Name, targetPath)

}
err = client.CopyFile(asFile, path, pod.Name, targetPath, watchedFiles)
if err != nil {
return errors.Wrap(err, "unable push files to pod")
}
fmt.Fprintf(out, syncOutput)
fmt.Fprintf(out, "Please wait, building component....\n")

// use pipes to write output from ExecCMDInContainer in yellow to 'out' io.Writer
Expand Down
2 changes: 1 addition & 1 deletion pkg/component/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func WatchAndPush(client *occlient.Client, componentName string, applicationName
fmt.Fprintf(out, "File %s changed\n", file)
}
fmt.Fprintf(out, "Pushing files...\n")
err := PushLocal(client, componentName, applicationName, path, asFile, out)
err := PushLocal(client, componentName, applicationName, path, asFile, out, changedFiles)
if err != nil {
// Intentionally not exiting on error here.
// We don't want to break watch when push failed, it might be fixed with the next change.
Expand Down

0 comments on commit 533f5e2

Please sign in to comment.