-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Attaching os standard error and out stream to the copy command #1960
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here (e.g. What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
Codecov Report
@@ Coverage Diff @@
## master #1960 +/- ##
==========================================
- Coverage 52.58% 52.56% -0.02%
==========================================
Files 180 180
Lines 7898 7900 +2
==========================================
Hits 4153 4153
- Misses 3356 3358 +2
Partials 389 389
Continue to review full report at Codecov.
|
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.
@prary I don't think it is generally acceptable to simply forward the output to stdout/stderr
. Error logging should be done with the logger. In addition, the deleteFileFn
has the same problem. What do you think about this approach:
diff --git a/pkg/skaffold/sync/kubectl/kubectl.go b/pkg/skaffold/sync/kubectl/kubectl.go
index 836e6252..6ba56f2f 100644
--- a/pkg/skaffold/sync/kubectl/kubectl.go
+++ b/pkg/skaffold/sync/kubectl/kubectl.go
@@ -19,7 +19,6 @@ package kubectl
import (
"context"
"io"
- "os"
"os/exec"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/sync"
@@ -77,9 +76,6 @@ func copyFileFn(ctx context.Context, pod v1.Pod, container v1.Container, files m
copy := exec.CommandContext(ctx, "kubectl", "exec", pod.Name, "--namespace", pod.Namespace, "-c", container.Name, "-i",
"--", "tar", "xmf", "-", "-C", "/", "--no-same-owner")
copy.Stdin = reader
- copy.Stdout = os.Stdout
- copy.Stderr = os.Stderr
-
go func() {
defer writer.Close()
diff --git a/pkg/skaffold/sync/sync.go b/pkg/skaffold/sync/sync.go
index 1994fe77..93b0bf14 100644
--- a/pkg/skaffold/sync/sync.go
+++ b/pkg/skaffold/sync/sync.go
@@ -17,6 +17,7 @@ limitations under the License.
package sync
import (
+ "bytes"
"context"
"fmt"
"os/exec"
@@ -247,7 +248,11 @@ func Perform(ctx context.Context, image string, files map[string]string, cmdFn f
cmds := cmdFn(ctx, p, c, files)
for _, cmd := range cmds {
+ buf := &bytes.Buffer{}
+ cmd.Stdout = buf
+ cmd.Stderr = buf
if err := util.RunCmd(cmd); err != nil {
+ logrus.Warnf("Sync failed: %s", buf.String())
return err
}
numSynced++
|
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
@prary This currently does not build.
I didn't realize that both |
|
This is great. If there's an error (for example, the non-debug
|
I signed it! |
Copy command doesn't output the logs to the user, hence attaching logs to stderr and stdout.