Skip to content

Commit

Permalink
log container loadbalancers
Browse files Browse the repository at this point in the history
  • Loading branch information
aojea committed May 31, 2024
1 parent ae8b178 commit 741e89e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions pkg/loadbalancer/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 741e89e

Please sign in to comment.