@@ -25,6 +25,7 @@ import (
25
25
"os"
26
26
"strings"
27
27
28
+ "github.com/blang/semver/v4"
28
29
"k8s.io/apimachinery/pkg/util/json"
29
30
30
31
"k8s.io/client-go/rest"
@@ -37,7 +38,8 @@ import (
37
38
log "k8s.io/klog/v2"
38
39
)
39
40
40
- var k3dVersion = "v5.7.2"
41
+ var k3dVersion = "v5.8.0"
42
+ var k3dWithExportLogSupport = "v5.8.0"
41
43
42
44
type Cluster struct {
43
45
path string
@@ -88,7 +90,7 @@ func WithImage(image string) support.ClusterOpts {
88
90
}
89
91
90
92
func NewCluster (name string ) * Cluster {
91
- return & Cluster {name : name }
93
+ return & Cluster {name : name , version : k3dVersion }
92
94
}
93
95
94
96
func NewProvider () support.E2EClusterProvider {
@@ -251,8 +253,25 @@ func (c *Cluster) GetKubectlContext() string {
251
253
}
252
254
253
255
func (c * Cluster ) ExportLogs (ctx context.Context , dest string ) error {
254
- log .Warning ("ExportLogs not implemented for k3d. Please use regular kubectl like commands to extract the logs from the cluster" )
255
- return nil
256
+ reqVersion , err := semver .Parse (c .version )
257
+ supVersion , _ := semver .Parse (k3dWithExportLogSupport )
258
+ if err != nil {
259
+ log .ErrorS (err , "failed to determine the k3d version to decide if the current version supporst the log export helpers. Please use regular kubectl like commands to extract the logs from the cluster" )
260
+ return nil
261
+ }
262
+ var stdout , stderr bytes.Buffer
263
+ if reqVersion .GE (supVersion ) {
264
+ p := utils .RunCommandWithCustomWriter (fmt .Sprintf ("%s debug export-logs %s --path %s" , c .path , c .name , dest ), & stdout , & stderr )
265
+ err = p .Err ()
266
+ if err != nil {
267
+ log .ErrorS (err , "failed to export cluster logs due to an error" , "stdout" , stdout .String (), "stderr" , stderr .String (), "result" , p .Result ())
268
+ return err
269
+ }
270
+ return nil
271
+ } else {
272
+ log .Warning ("ExportLogs not implemented for k3d. Please use regular kubectl like commands to extract the logs from the cluster" )
273
+ return nil
274
+ }
256
275
}
257
276
258
277
func (c * Cluster ) Destroy (ctx context.Context ) error {
0 commit comments