11package k8s_test
22
33import (
4+ "fmt"
45 "regexp"
6+ "strings"
57 "testing"
68
79 "github.com/ghodss/yaml"
810 "github.com/scaleway/scaleway-cli/v2/core"
911 "github.com/scaleway/scaleway-cli/v2/internal/namespaces/k8s/v1"
1012 api "github.com/scaleway/scaleway-cli/v2/internal/namespaces/k8s/v1/types"
13+ k8ssdk "github.com/scaleway/scaleway-sdk-go/api/k8s/v1"
1114 "github.com/scaleway/scaleway-sdk-go/scw"
1215 "github.com/stretchr/testify/assert"
1316 "github.com/stretchr/testify/require"
@@ -17,7 +20,6 @@ func Test_GetKubeconfig(t *testing.T) {
1720 ////
1821 // Simple use case
1922 ////
20-
2123 t .Run ("simple" , core .Test (& core.TestConfig {
2224 Commands : k8s .GetCommands (),
2325 BeforeFunc : createClusterAndWaitAndKubeconfig (
@@ -283,9 +285,34 @@ func Test_GetKubeconfig(t *testing.T) {
283285 t .Run ("legacy" , core .Test (& core.TestConfig {
284286 Commands : k8s .GetCommands (),
285287 Cmd : "scw k8s kubeconfig get {{ ." + clusterMetaKey + ".ID }} auth-method=legacy" ,
286- BeforeFunc : createClusterAndWaitAndKubeconfig (
287- "get-kubeconfig-legacy" ,
288- ),
288+ BeforeFunc : func (ctx * core.BeforeFuncCtx ) error {
289+ cmd := fmt .Sprintf (
290+ "scw k8s cluster create name=cli-test-%s version=%s cni=cilium pools.0.node-type=DEV1-M pools.0.size=1 pools.0.name=default --wait" ,
291+ "get-kubeconfig-legacy" ,
292+ kapsuleVersion ,
293+ )
294+ res := ctx .ExecuteCmd (strings .Split (cmd , " " ))
295+ cluster := res .(* k8ssdk.Cluster )
296+ ctx .Meta [clusterMetaKey ] = cluster
297+
298+ apiKubeconfig , err := k8ssdk .NewAPI (ctx .Client ).
299+ GetClusterKubeConfig (& k8ssdk.GetClusterKubeConfigRequest {
300+ Region : cluster .Region ,
301+ ClusterID : cluster .ID ,
302+ Redacted : scw .BoolPtr (false ),
303+ })
304+ if err != nil {
305+ return err
306+ }
307+
308+ var kubeconfig api.Config
309+ if err = yaml .Unmarshal (apiKubeconfig .GetRaw (), & kubeconfig ); err != nil {
310+ return err
311+ }
312+ ctx .Meta [kubeconfigMetaKey ] = kubeconfig
313+
314+ return nil
315+ },
289316 Check : core .TestCheckCombine (
290317 core .TestCheckExitCode (0 ),
291318 func (t * testing.T , ctx * core.CheckFuncCtx ) {
0 commit comments