Skip to content

Commit

Permalink
add delete debug logging
Browse files Browse the repository at this point in the history
  • Loading branch information
sbueringer committed Sep 23, 2022
1 parent 334f6a8 commit 9313fda
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions test/infrastructure/docker/internal/docker/types/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ limitations under the License.
package types

import (
"bytes"
"context"
"io"
"path/filepath"
"strings"
"time"

"github.com/pkg/errors"
ctrl "sigs.k8s.io/controller-runtime"

"sigs.k8s.io/cluster-api/test/infrastructure/container"
)
Expand Down Expand Up @@ -96,6 +99,21 @@ func (n *Node) Delete(ctx context.Context) error {

err = containerRuntime.DeleteContainer(ctx, n.Name)
if err != nil {
log := ctrl.LoggerFrom(ctx)

// Use our own context, so we are able to get debug information even
// when the context used in the layers above is already timed out.
debugCtx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
defer cancel()

var buffer bytes.Buffer
err = containerRuntime.ContainerDebugInfo(debugCtx, n.Name, &buffer)
if err != nil {
log.Error(err, "failed to get logs from the machine container")
} else {
log.Info("Got logs from the machine container", "output", strings.ReplaceAll(buffer.String(), "\\n", "\n"))
}

return errors.Wrapf(err, "failed to delete container %q", n.Name)
}

Expand Down

0 comments on commit 9313fda

Please sign in to comment.