Skip to content

Commit 9d7a663

Browse files
committed
tests: refresh kubernetes k3s pin and timeouts
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
1 parent 23b431f commit 9d7a663

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ ARG BUILDKIT_VERSION=v0.29.0
1515
ARG COMPOSE_VERSION=v5.1.0
1616
ARG UNDOCK_VERSION=0.9.0
1717
ARG K3D_VERSION=5.8.3
18-
ARG K3S_VERSION=v1.32.2-k3s1
18+
ARG K3S_VERSION=v1.32.13-k3s1
1919

2020
FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
2121
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS golatest

tests/helpers/k3d.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func NewK3dServer(ctx context.Context, cfg *integration.BackendConfig, dockerAdd
3333

3434
clusterName = "bk-" + identity.NewID()
3535

36-
createCtx, cancelCreate := context.WithTimeout(ctx, 90*time.Second)
36+
createCtx, cancelCreate := context.WithTimeoutCause(ctx, 90*time.Second, errors.New("timed out creating k3d cluster"))
3737
defer cancelCreate()
3838

3939
args := []string{
@@ -48,11 +48,13 @@ func NewK3dServer(ctx context.Context, cfg *integration.BackendConfig, dockerAdd
4848
cmd.Env = k3dEnv(dockerAddress)
4949
out, err := cmd.CombinedOutput()
5050
if err != nil {
51-
diag := KubernetesDiagnostics(clusterName, dockerAddress)
51+
diag := KubernetesDiagnostics(ctx, clusterName, dockerAddress)
5252
return "", "", nil, errors.Wrapf(err, "failed to create k3d cluster %s: %s\n%s\nouter dockerd logs: %s", clusterName, strings.TrimSpace(string(out)), diag, integration.FormatLogs(cfg.Logs))
5353
}
5454
deferF.Append(func() error {
55-
cmd := exec.Command(k3dBin, "cluster", "delete", clusterName)
55+
deleteCtx, cancelDelete := context.WithTimeoutCause(context.WithoutCancel(ctx), 30*time.Second, errors.New("timed out deleting k3d cluster"))
56+
defer cancelDelete()
57+
cmd := exec.CommandContext(deleteCtx, k3dBin, "cluster", "delete", clusterName)
5658
cmd.Env = k3dEnv(dockerAddress)
5759
out, err := cmd.CombinedOutput()
5860
if err != nil {
@@ -61,14 +63,14 @@ func NewK3dServer(ctx context.Context, cfg *integration.BackendConfig, dockerAdd
6163
return nil
6264
})
6365

64-
kubeconfigCtx, cancelKubeconfig := context.WithTimeout(ctx, 30*time.Second)
66+
kubeconfigCtx, cancelKubeconfig := context.WithTimeoutCause(ctx, 30*time.Second, errors.New("timed out writing k3d kubeconfig"))
6567
defer cancelKubeconfig()
6668

6769
cmd = exec.CommandContext(kubeconfigCtx, k3dBin, "kubeconfig", "write", clusterName)
6870
cmd.Env = k3dEnv(dockerAddress)
6971
out, err = cmd.CombinedOutput()
7072
if err != nil {
71-
diag := KubernetesDiagnostics(clusterName, dockerAddress)
73+
diag := KubernetesDiagnostics(ctx, clusterName, dockerAddress)
7274
return "", "", nil, errors.Wrapf(err, "failed to write kubeconfig for cluster %s: %s\n%s\nouter dockerd logs: %s", clusterName, strings.TrimSpace(string(out)), diag, integration.FormatLogs(cfg.Logs))
7375
}
7476
kubeConfig = strings.TrimSpace(string(out))

tests/helpers/kubernetes_diagnostics.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package helpers
33
import (
44
"bytes"
55
"context"
6+
"errors"
67
"fmt"
78
"os"
89
"os/exec"
@@ -35,8 +36,8 @@ func KubernetesK3DLoadBalancerImage() string {
3536
return os.Getenv("TEST_K3D_LOADBALANCER_IMAGE")
3637
}
3738

38-
func KubernetesDiagnostics(clusterName, dockerContext string) string {
39-
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
39+
func KubernetesDiagnostics(ctx context.Context, clusterName, dockerContext string) string {
40+
ctx, cancel := context.WithTimeoutCause(context.WithoutCancel(ctx), 20*time.Second, errors.New("timed out collecting kubernetes diagnostics"))
4041
defer cancel()
4142

4243
var buf bytes.Buffer

tests/workers/kubernetes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (w *kubernetesWorker) New(ctx context.Context, cfg *integration.BackendConf
7979
)
8080
out, err := cmd.CombinedOutput()
8181
if err != nil {
82-
diag := helpers.KubernetesDiagnostics(w.k3dName, w.docker.DockerAddress())
82+
diag := helpers.KubernetesDiagnostics(ctx, w.k3dName, w.docker.DockerAddress())
8383
return nil, nil, errors.Wrapf(err, "failed to create buildx instance %s with image %s: %s\n%s", name, helpers.KubernetesBuildkitImage(), strings.TrimSpace(string(out)), diag)
8484
}
8585

0 commit comments

Comments
 (0)