Skip to content

Commit 0aeb1a8

Browse files
committed
fix(kapsule): allow getting kubeconfig with readonly permission
1 parent c1a08c4 commit 0aeb1a8

23 files changed

Lines changed: 11385 additions & 11355 deletions

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ require (
2323
github.com/mattn/go-isatty v0.0.20
2424
github.com/moby/buildkit v0.25.1
2525
github.com/opencontainers/go-digest v1.0.0
26-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.35.0.20251002202252-ab1363c81acf
26+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.35.0.20251014133246-1080af8a8039
2727
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
2828
github.com/spf13/cobra v1.10.1
2929
github.com/spf13/pflag v1.0.10

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,8 @@ github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7
462462
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
463463
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 h1:OkMGxebDjyw0ULyrTYWeN0UNCCkmCWfjPnIA2W6oviI=
464464
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06/go.mod h1:+ePHsJ1keEjQtpvf9HHw0f4ZeJ0TLRsxhunSI2hYJSs=
465-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.35.0.20251002202252-ab1363c81acf h1:mz7af7+CKpRvbZMilDwowLtNOQ0sZOYdTAjdkG9lRho=
466-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.35.0.20251002202252-ab1363c81acf/go.mod h1:DVB9HV7nK7TdTRqlpdxw6T0Wxg+aB9xPBEpO3aM2iqQ=
465+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.35.0.20251014133246-1080af8a8039 h1:jQtzY/CcJKOMQl6p8yfSBgF0Am9As2myjla35QQ6QOw=
466+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.35.0.20251014133246-1080af8a8039/go.mod h1:SVm1Zk6UpZtqZN6KtEQpjC+v+Lir4tyVfhQTU19q3PA=
467467
github.com/sclevine/spec v1.4.0 h1:z/Q9idDcay5m5irkZ28M7PtQM4aOISzOpj4bUPkDee8=
468468
github.com/sclevine/spec v1.4.0/go.mod h1:LvpgJaFyvQzRvc1kaDs0bulYwzC70PbiYjC4QnFHkOM=
469469
github.com/secure-systems-lab/go-securesystemslib v0.8.0 h1:mr5An6X45Kb2nddcFlbmfHkLguCE9laoZCUzEEpIZXA=

internal/namespaces/k8s/v1/custom_kubeconfig_get.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ func k8sKubeconfigGetRun(ctx context.Context, argsI any) (i any, e error) {
7272
GetClusterKubeConfig(&k8s.GetClusterKubeConfigRequest{
7373
Region: request.Region,
7474
ClusterID: request.ClusterID,
75+
Redacted: scw.BoolPtr(request.AuthMethod != authMethodLegacy), // put true after legacy deprecation
7576
})
7677
if err != nil {
7778
return nil, err

internal/namespaces/k8s/v1/custom_kubeconfig_get_test.go

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
package k8s_test
22

33
import (
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) {

internal/namespaces/k8s/v1/custom_kubeconfig_install.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ func k8sKubeconfigInstallRun(ctx context.Context, argsI any) (i any, e error) {
8686
GetClusterKubeConfig(&k8s.GetClusterKubeConfigRequest{
8787
Region: request.Region,
8888
ClusterID: request.ClusterID,
89+
Redacted: scw.BoolPtr(request.AuthMethod != authMethodLegacy), // put true after legacy deprecation
8990
})
9091
if err != nil {
9192
return nil, err

internal/namespaces/k8s/v1/helpers_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/scaleway/scaleway-cli/v2/core"
1111
go_api "github.com/scaleway/scaleway-cli/v2/internal/namespaces/k8s/v1/types"
1212
k8s "github.com/scaleway/scaleway-sdk-go/api/k8s/v1"
13+
"github.com/scaleway/scaleway-sdk-go/scw"
1314
)
1415

1516
const (
@@ -60,6 +61,7 @@ func createClusterAndWaitAndKubeconfig(
6061
GetClusterKubeConfig(&k8s.GetClusterKubeConfigRequest{
6162
Region: cluster.Region,
6263
ClusterID: cluster.ID,
64+
Redacted: scw.BoolPtr(true),
6365
})
6466
if err != nil {
6567
return err

0 commit comments

Comments
 (0)