diff --git a/pkg/container/container.go b/pkg/container/container.go index 9a5e8e9b..614e5f2d 100644 --- a/pkg/container/container.go +++ b/pkg/container/container.go @@ -43,6 +43,15 @@ func init() { } } +func Logs(name string) ([]string, error) { + cmd := kindexec.Command(containerRuntime, []string{"logs", name}...) + lines, err := kindexec.OutputLines(cmd) + if err != nil { + return nil, fmt.Errorf("failed to get container logs: %w", err) + } + return lines, nil +} + func Create(name string, args []string) error { if err := exec.Command(containerRuntime, append([]string{"run", "--name", name}, args...)...).Run(); err != nil { return err diff --git a/pkg/loadbalancer/server.go b/pkg/loadbalancer/server.go index 6c4abbbb..6f455105 100644 --- a/pkg/loadbalancer/server.go +++ b/pkg/loadbalancer/server.go @@ -90,6 +90,7 @@ func (s *Server) GetLoadBalancerName(ctx context.Context, clusterName string, se func (s *Server) EnsureLoadBalancer(ctx context.Context, clusterName string, service *v1.Service, nodes []*v1.Node) (*v1.LoadBalancerStatus, error) { name := loadBalancerName(clusterName, service) if !container.IsRunning(name) { + klog.Infof("container %s for loadbalancer is not running", name) if container.Exist(name) { err := container.Delete(name) if err != nil { @@ -143,6 +144,10 @@ func (s *Server) EnsureLoadBalancerDeleted(ctx context.Context, clusterName stri if s.tunnelManager != nil { err1 = s.tunnelManager.removeTunnels(containerName) } + lines, err := container.Logs(containerName) + if err == nil && klog.V(4).Enabled() { + klog.Infof("-------------- Logs loadbalancer %s:\n%s\n--------------------------------------------", containerName, lines) + } err2 = container.Delete(containerName) return errors.Join(err1, err2) }