Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PLT-1019:Added SDK support for custom cloud cluster. #90

Merged
merged 1 commit into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,20 @@ type V1Client struct {
DeleteMacrosFn func(uid string, body *models.V1Macros) error
GetMacrosIdFn func(uid string) (string, error)

// Cloud Accounts
// Custom Cloud Accounts
CreateCustomCloudAccountFn func(account *models.V1CustomAccountEntity, cloudType string, accountContext string) (string, error)
GetCustomCloudAccountFn func(uid, cloudType string, accountContext string) (*models.V1CustomAccount, error)
UpdateCustomCloudAccountFn func(uid string, account *models.V1CustomAccountEntity, cloudType string, accountContext string) error
DeleteCustomCloudAccountFn func(uid, cloudType string, accountContext string) error
ValidateCustomCloudTypeFn func(cloudType string, cloudContext string) error

// Custom Cloud Cluster
GetCloudConfigCustomCloudFn func(configUID string, cloudType string, clusterContext string) (*models.V1CustomCloudConfig, error)
CreateClusterCustomCloudFn func(cluster *models.V1SpectroCustomClusterEntity, cloudType string, clusterContext string) (string, error)
UpdateCloudConfigCustomCloudFn func(updatedConfig *models.V1CustomCloudClusterConfigEntity, configUID string, cloudType string, clusterContext string) error
CreateMachinePoolCustomCloudFn func(mpEntity *models.V1CustomMachinePoolConfigEntity, configUID string, cloudType string, clusterContext string) error
UpdateMachinePoolCustomCloudFn func(mpEntity *models.V1CustomMachinePoolConfigEntity, configUID string, cloudType string, clusterContext string) error
DeleteMachinePoolCustomCloudFn func(mpName string, configUID string, cloudType string, clusterContext string) error
}

func New(options ...func(*V1Client)) *V1Client {
Expand Down
134 changes: 134 additions & 0 deletions client/cluster_custom_cloud.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
package client

import (
"fmt"
"github.com/spectrocloud/hapi/models"
clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1"
)

func (h *V1Client) CreateClusterCustomCloud(cluster *models.V1SpectroCustomClusterEntity, cloudType string, clusterContext string) (string, error) {
if h.CreateClusterCustomCloudFn != nil {
return h.CreateClusterCustomCloudFn(cluster, cloudType, clusterContext)
}

var params *clusterC.V1SpectroClustersCustomCreateParams

switch clusterContext {
case "project":
params = clusterC.NewV1SpectroClustersCustomCreateParamsWithContext(h.Ctx)
case "tenant":
params = clusterC.NewV1SpectroClustersCustomCreateParams()
}
params = params.WithCloudType(cloudType).WithBody(cluster)
success, err := h.GetClusterClient().V1SpectroClustersCustomCreate(params)
if err != nil {
return "", err
}

return *success.Payload.UID, nil
}

func (h *V1Client) GetCloudConfigCustomCloud(configUID string, cloudType string, clusterContext string) (*models.V1CustomCloudConfig, error) {
if h.GetCloudConfigCustomCloudFn != nil {
return h.GetCloudConfigCustomCloudFn(configUID, cloudType, clusterContext)
}
var params *clusterC.V1CloudConfigsCustomGetParams
switch clusterContext {
case "project":
params = clusterC.NewV1CloudConfigsCustomGetParamsWithContext(h.Ctx)
case "tenant":
params = clusterC.NewV1CloudConfigsCustomGetParams()
default:
return nil, fmt.Errorf("invalid scope %s", clusterContext)
}
params = params.WithCloudType(cloudType).WithConfigUID(configUID)
success, err := h.GetClusterClient().V1CloudConfigsCustomGet(params)
if err != nil {
return nil, err
}

// special check if the cluster is marked deleted
cluster := success.Payload
return cluster, nil

}

func (h *V1Client) UpdateCloudConfigCustomCloud(updatedConfig *models.V1CustomCloudClusterConfigEntity, configUID string, cloudType string, clusterContext string) error {
if h.UpdateCloudConfigCustomCloudFn != nil {
return h.UpdateCloudConfigCustomCloudFn(updatedConfig, configUID, cloudType, clusterContext)
}

var params *clusterC.V1CloudConfigsCustomUIDClusterConfigParams
switch clusterContext {
case "project":
params = clusterC.NewV1CloudConfigsCustomUIDClusterConfigParamsWithContext(h.Ctx)
case "tenant":
params = clusterC.NewV1CloudConfigsCustomUIDClusterConfigParams()
}
params = params.WithCloudType(cloudType).WithBody(updatedConfig).WithConfigUID(configUID)
_, err := h.GetClusterClient().V1CloudConfigsCustomUIDClusterConfig(params)
if err != nil {
return err
}
return nil
}

func (h *V1Client) CreateMachinePoolCustomCloud(mpEntity *models.V1CustomMachinePoolConfigEntity, configUID string, cloudType string, clusterContext string) error {
if h.CreateMachinePoolCustomCloudFn != nil {
return h.CreateMachinePoolCustomCloudFn(mpEntity, configUID, cloudType, clusterContext)
}

var params *clusterC.V1CloudConfigsCustomMachinePoolCreateParams
switch clusterContext {
case "project":
params = clusterC.NewV1CloudConfigsCustomMachinePoolCreateParamsWithContext(h.Ctx)
case "tenant":
params = clusterC.NewV1CloudConfigsCustomMachinePoolCreateParams()
}
params = params.WithCloudType(cloudType).WithBody(mpEntity).WithConfigUID(configUID)
_, err := h.GetClusterClient().V1CloudConfigsCustomMachinePoolCreate(params)
if err != nil {
return err
}
return nil
}

func (h *V1Client) UpdateMachinePoolCustomCloud(mpEntity *models.V1CustomMachinePoolConfigEntity, configUID string, cloudType string, clusterContext string) error {
if h.UpdateMachinePoolCustomCloudFn != nil {
return h.UpdateMachinePoolCustomCloudFn(mpEntity, configUID, cloudType, clusterContext)
}

var params *clusterC.V1CloudConfigsCustomMachinePoolUpdateParams
switch clusterContext {
case "project":
params = clusterC.NewV1CloudConfigsCustomMachinePoolUpdateParamsWithContext(h.Ctx)
case "tenant":
params = clusterC.NewV1CloudConfigsCustomMachinePoolUpdateParams()
}
params = params.WithCloudType(cloudType).WithBody(mpEntity).WithConfigUID(configUID)
_, err := h.GetClusterClient().V1CloudConfigsCustomMachinePoolUpdate(params)
if err != nil {
return err
}
return nil
}

func (h *V1Client) DeleteMachinePoolCustomCloud(mpName string, configUID string, cloudType string, clusterContext string) error {
if h.DeleteMachinePoolCustomCloudFn != nil {
return h.DeleteMachinePoolCustomCloudFn(mpName, configUID, cloudType, clusterContext)
}

var params *clusterC.V1CloudConfigsCustomMachinePoolDeleteParams
switch clusterContext {
case "project":
params = clusterC.NewV1CloudConfigsCustomMachinePoolDeleteParamsWithContext(h.Ctx)
case "tenant":
params = clusterC.NewV1CloudConfigsCustomMachinePoolDeleteParams()
}
params = params.WithCloudType(cloudType).WithConfigUID(configUID).WithMachinePoolName(mpName)
_, err := h.GetClusterClient().V1CloudConfigsCustomMachinePoolDelete(params)
if err != nil {
return err
}
return nil
}
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/go-openapi/runtime v0.19.26
github.com/go-openapi/strfmt v0.21.3
github.com/pkg/errors v0.9.1
github.com/spectrocloud/hapi v1.14.1-0.20240208170048-8ee28d936fb6
github.com/spectrocloud/hapi v1.14.1-0.20240213074743-ad09fdebcffb
github.com/stretchr/testify v1.8.4
)

Expand All @@ -34,6 +34,7 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spectrocloud/gomi v1.14.1-0.20240131155846-7276c4a27819 // indirect
github.com/spectrocloud/hubble v1.14.2-0.20240213163044-bc42a72def6e // indirect
go.mongodb.org/mongo-driver v1.10.0 // indirect
golang.org/x/sys v0.13.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ github.com/spectrocloud/gomi v1.14.1-0.20240131155846-7276c4a27819 h1:4fu4f/RKLC
github.com/spectrocloud/gomi v1.14.1-0.20240131155846-7276c4a27819/go.mod h1:LlZ9We4kDaELYi7Is0SVmnySuDhwphJLS6ZT4wXxFIk=
github.com/spectrocloud/hapi v1.14.1-0.20240208170048-8ee28d936fb6 h1:LwhOh1MPG68vy5zc2u3WCvgr7AilHOFjJ3cfXGepSg8=
github.com/spectrocloud/hapi v1.14.1-0.20240208170048-8ee28d936fb6/go.mod h1:MktpRPnSXDTHsQrFSD+daJFQ1zMLSR+1gWOL31jVvWE=
github.com/spectrocloud/hapi v1.14.1-0.20240213074743-ad09fdebcffb h1:9Hr84e3qvuggyaYcvJQVKrBdX032z+NWqgp7a+X2hm8=
github.com/spectrocloud/hapi v1.14.1-0.20240213074743-ad09fdebcffb/go.mod h1:MktpRPnSXDTHsQrFSD+daJFQ1zMLSR+1gWOL31jVvWE=
github.com/spectrocloud/hubble v1.14.2-0.20240213163044-bc42a72def6e h1:05T9nUdIgINuU35cPjz1labN0OhVVidAScXa8GOKZag=
github.com/spectrocloud/hubble v1.14.2-0.20240213163044-bc42a72def6e/go.mod h1:DR2b6bCzA//rzZrX1t4sqOAbfoN3PJBcGo9k9tfYIGU=
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=
Expand Down
Loading