From c7798e17ccdac3d56437eda327ef1daef25db9ba Mon Sep 17 00:00:00 2001 From: Manuel Buil Date: Thu, 11 Jan 2024 16:00:49 +0100 Subject: [PATCH] Improve kube-proxy and calico logging in Windows Signed-off-by: Manuel Buil --- pkg/pebinaryexecutor/pebinary.go | 11 ++++++++--- pkg/windows/calico.go | 23 ++++++++++------------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/pkg/pebinaryexecutor/pebinary.go b/pkg/pebinaryexecutor/pebinary.go index dc746cd5202..48c7ae97dfc 100644 --- a/pkg/pebinaryexecutor/pebinary.go +++ b/pkg/pebinaryexecutor/pebinary.go @@ -220,11 +220,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(filepath.Join(p.DataDir, "agent", "logs", "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) } diff --git a/pkg/windows/calico.go b/pkg/windows/calico.go index 7a6db6dfdd5..02e6a278dbe 100644 --- a/pkg/windows/calico.go +++ b/pkg/windows/calico.go @@ -131,7 +131,6 @@ const ( CalicoSystemNamespace = "calico-system" CalicoChart = "rke2-calico" calicoNode = "calico-node" - calicoLogPath = "C:\\var\\log\\" ) // Setup creates the basic configuration required by the CNI. @@ -263,20 +262,18 @@ func (c *Calico) createKubeConfig(ctx context.Context, restConfig *rest.Config) // Start starts the CNI services on the Windows node. func (c *Calico) Start(ctx context.Context) error { - if err := os.MkdirAll(calicoLogPath, 0755); err != nil { - return fmt.Errorf("error creating %s directory: %v", calicoLogPath, err) - } + logPath := filepath.Join(c.DataDir, "agent", "logs") for { - if err := startCalico(ctx, c.CNICfg); err != nil { + if err := startCalico(ctx, c.CNICfg, logPath); err != nil { time.Sleep(5 * time.Second) logrus.Errorf("Calico exited: %v. Retrying", err) continue } break } - go startFelix(ctx, c.CNICfg) + go startFelix(ctx, c.CNICfg, logPath) if c.CNICfg.Mode == "windows-bgp" { - go startConfd(ctx, c.CNICfg) + go startConfd(ctx, c.CNICfg, logPath) } return nil @@ -392,8 +389,8 @@ func findCalicoInterface(nodeV4 *opv1.NodeAddressAutodetection) (IPAutoDetection return } -func startConfd(ctx context.Context, config *CalicoConfig) { - outputFile, err := os.Create(calicoLogPath + "confd.log") +func startConfd(ctx context.Context, config *CalicoConfig, logPath string) { + outputFile, err := os.Create(filepath.Join(logPath, "confd.log")) if err != nil { logrus.Fatalf("error creating confd.log: %v", err) return @@ -419,8 +416,8 @@ func startConfd(ctx context.Context, config *CalicoConfig) { logrus.Error("Confd exited") } -func startFelix(ctx context.Context, config *CalicoConfig) { - outputFile, err := os.Create(calicoLogPath + "felix.log") +func startFelix(ctx context.Context, config *CalicoConfig, logPath string) { + outputFile, err := os.Create(filepath.Join(logPath, "felix.log")) if err != nil { logrus.Fatalf("error creating felix.log: %v", err) return @@ -453,8 +450,8 @@ func startFelix(ctx context.Context, config *CalicoConfig) { logrus.Error("Felix exited") } -func startCalico(ctx context.Context, config *CalicoConfig) error { - outputFile, err := os.Create(calicoLogPath + "calico-node.log") +func startCalico(ctx context.Context, config *CalicoConfig, logPath string) error { + outputFile, err := os.Create(filepath.Join(logPath, "calico-node.log")) if err != nil { return fmt.Errorf("error creating calico-node.log: %v", err) }