From e8872d7f80e1c381ed6ab6bf843312654e6f36c0 Mon Sep 17 00:00:00 2001 From: Sivaanand Murugesan Date: Tue, 12 Sep 2023 17:30:24 +0530 Subject: [PATCH 1/2] PLT-678:Admin kube config sdk support --- client/cluster.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/client/cluster.go b/client/cluster.go index 29db1d54..26f3b64a 100644 --- a/client/cluster.go +++ b/client/cluster.go @@ -215,6 +215,37 @@ func (h *V1Client) GetClusterKubeConfig(uid, ClusterContext string) (string, err return builder.String(), nil } +func (h *V1Client) GetClusterAdminKubeConfig(uid, ClusterContext string) (string, error) { + if h.GetClusterKubeConfigFn != nil { + return h.GetClusterKubeConfigFn(uid) + } + client, err := h.GetClusterClient() + if err != nil { + return "", err + } + + var params *clusterC.V1SpectroClustersUIDAdminKubeConfigParams + switch ClusterContext { + case "project": + params = clusterC.NewV1SpectroClustersUIDAdminKubeConfigParamsWithContext(h.Ctx).WithUID(uid) + case "tenant": + params = clusterC.NewV1SpectroClustersUIDAdminKubeConfigParams().WithUID(uid) + default: + return "", errors.New("invalid cluster scope specified") + } + + builder := new(strings.Builder) + _, err = client.V1SpectroClustersUIDAdminKubeConfig(params, builder) + if err != nil { + if herr.IsNotFound(err) { + return "", nil + } + return "", err + } + + return builder.String(), nil +} + func (h *V1Client) GetClusterImportManifest(uid string) (string, error) { client, err := h.GetClusterClient() if err != nil { From 5eeb433156b98f18f004982822f9823bf7809308 Mon Sep 17 00:00:00 2001 From: nikolay-spectro Date: Fri, 22 Sep 2023 16:10:28 -0700 Subject: [PATCH 2/2] PLT-678: addressing review comments. --- client/client.go | 1 + client/cluster.go | 4 ++-- go.mod | 2 +- go.sum | 2 ++ 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/client/client.go b/client/client.go index 7db18aa0..3dc95f7e 100644 --- a/client/client.go +++ b/client/client.go @@ -54,6 +54,7 @@ type V1Client struct { // Cluster generic GetClusterWithoutStatusFn func(string) (*models.V1SpectroCluster, error) GetClusterFn func(scope, uid string) (*models.V1SpectroCluster, error) + GetClusterAdminConfigFn func(uid string) (string, error) GetClusterKubeConfigFn func(uid string) (string, error) GetClusterBackupConfigFn func(uid string) (*models.V1ClusterBackup, error) GetClusterScanConfigFn func(uid string) (*models.V1ClusterComplianceScan, error) diff --git a/client/cluster.go b/client/cluster.go index 26f3b64a..c70c15de 100644 --- a/client/cluster.go +++ b/client/cluster.go @@ -216,8 +216,8 @@ func (h *V1Client) GetClusterKubeConfig(uid, ClusterContext string) (string, err } func (h *V1Client) GetClusterAdminKubeConfig(uid, ClusterContext string) (string, error) { - if h.GetClusterKubeConfigFn != nil { - return h.GetClusterKubeConfigFn(uid) + if h.GetClusterAdminConfigFn != nil { + return h.GetClusterAdminConfigFn(uid) } client, err := h.GetClusterClient() if err != nil { diff --git a/go.mod b/go.mod index 96a588e3..42f53574 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/go-openapi/strfmt v0.20.0 github.com/pkg/errors v0.9.1 github.com/spectrocloud/gomi v1.14.1-0.20230412095143-b0595c6c6f08 - github.com/spectrocloud/hapi v1.14.1-0.20230814141242-394093e7fedb + github.com/spectrocloud/hapi v1.14.1-0.20230921130725-2afc79a3ea05 github.com/stretchr/testify v1.7.0 ) diff --git a/go.sum b/go.sum index aea7aa5f..2af9d5c4 100644 --- a/go.sum +++ b/go.sum @@ -213,6 +213,8 @@ github.com/spectrocloud/hapi v1.14.1-0.20230809113851-e533537baa55 h1:0V4LeAlh+/ github.com/spectrocloud/hapi v1.14.1-0.20230809113851-e533537baa55/go.mod h1:O/Bkbw92QPSGPNQPqKt7Qlkn+9BKK/a22KTUlk76KHI= github.com/spectrocloud/hapi v1.14.1-0.20230814141242-394093e7fedb h1:Y/TDXfEZ6GJbYi4bKxFS0HFvmOL6Xs653BoxuZjuKEQ= github.com/spectrocloud/hapi v1.14.1-0.20230814141242-394093e7fedb/go.mod h1:O/Bkbw92QPSGPNQPqKt7Qlkn+9BKK/a22KTUlk76KHI= +github.com/spectrocloud/hapi v1.14.1-0.20230921130725-2afc79a3ea05 h1:QHuGuSItjNA0iVda1OCvHlWDjps6NR1X1/pjlYmIOp8= +github.com/spectrocloud/hapi v1.14.1-0.20230921130725-2afc79a3ea05/go.mod h1:aI54jbfaSec1ikHSMOJQ7mMOTaRKpQTRCoMKamhBE9s= github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=