From 39995dcfa6d14ddba5142cbee73f8cf45dc8a3ac Mon Sep 17 00:00:00 2001 From: Manuel Buil Date: Thu, 11 Jan 2024 16:00:49 +0100 Subject: [PATCH] Use a file to log kube-proxy output in windows Signed-off-by: Manuel Buil --- pkg/pebinaryexecutor/pebinary.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/pkg/pebinaryexecutor/pebinary.go b/pkg/pebinaryexecutor/pebinary.go index dc746cd5202..f77c55af730 100644 --- a/pkg/pebinaryexecutor/pebinary.go +++ b/pkg/pebinaryexecutor/pebinary.go @@ -67,6 +67,8 @@ const ( CNICalico = "calico" CNICilium = "cilium" CNICanal = "canal" + LogPath = "C:\\var\\log\\" + ) // Bootstrap prepares the binary executor to run components by setting the system default registry @@ -124,6 +126,11 @@ func (p *PEBinaryConfig) Bootstrap(ctx context.Context, nodeConfig *daemonconfig // required to initialize KubeProxy p.KubeConfigKubeProxy = nodeConfig.AgentConfig.KubeConfigKubeProxy + // create the path where the logs are written + if err := os.MkdirAll(LogPath, 0755); err != nil { + return fmt.Errorf("error creating %s directory: %v", LogPath, err) + } + logrus.Infof("Windows bootstrap okay. Exiting setup.") return nil } @@ -220,11 +227,16 @@ func (p *PEBinaryConfig) KubeProxy(ctx context.Context, args []string) error { logrus.Infof("Running RKE2 kube-proxy %s", args) go func() { + outputFile, err := os.Create(LogPath + "kube-proxy.log") + if err != nil { + logrus.Fatalf("error creating kube-proxy.log: %v", err) + } + defer outputFile.Close() for { cmd := exec.CommandContext(ctx, filepath.Join("c:\\", p.DataDir, "bin", "kube-proxy.exe"), args...) - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - err := cmd.Run() + cmd.Stdout = outputFile + cmd.Stderr = outputFile + err = cmd.Run() logrus.Errorf("kube-proxy exited: %v", err) time.Sleep(5 * time.Second) }