Skip to content

Commit

Permalink
fixed gke sdk part
Browse files Browse the repository at this point in the history
  • Loading branch information
SivaanandM committed Jul 1, 2024
1 parent 127040c commit 84bccbb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 139 deletions.
99 changes: 29 additions & 70 deletions client/cluster_gke.go
Original file line number Diff line number Diff line change
@@ -1,104 +1,63 @@
package client

import (
"errors"
"github.com/spectrocloud/hapi/apiutil/transport"
"github.com/spectrocloud/hapi/models"
clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1"
clientV1 "github.com/spectrocloud/palette-api-go/client/v1"
"github.com/spectrocloud/palette-api-go/models"
)

func (h *V1Client) CreateClusterGke(cluster *models.V1SpectroGcpClusterEntity, ClusterContext string) (string, error) {
var params *clusterC.V1SpectroClustersGkeCreateParams
switch ClusterContext {
case "project":
params = clusterC.NewV1SpectroClustersGkeCreateParamsWithContext(h.Ctx).WithBody(cluster)
case "tenant":
params = clusterC.NewV1SpectroClustersGkeCreateParams().WithBody(cluster)
}

success, err := h.GetClusterClient().V1SpectroClustersGkeCreate(params)
func (h *V1Client) CreateClusterGke(cluster *models.V1SpectroGcpClusterEntity) (string, error) {
var params *clientV1.V1SpectroClustersGkeCreateParams

Check failure on line 9 in client/cluster_gke.go

View workflow job for this annotation

GitHub Actions / build-with-coverage

S1021: should merge variable declaration with assignment on next line (gosimple)
params = clientV1.NewV1SpectroClustersGkeCreateParamsWithContext(h.ctx).WithBody(cluster)
success, err := h.Client.V1SpectroClustersGkeCreate(params)
if err != nil {
return "", err
}

return *success.Payload.UID, nil
}

func (h *V1Client) GetCloudConfigGke(configUID, ClusterContext string) (*models.V1GcpCloudConfig, error) {
var params *clusterC.V1CloudConfigsGkeGetParams
switch ClusterContext {
case "project":
params = clusterC.NewV1CloudConfigsGkeGetParamsWithContext(h.Ctx).WithConfigUID(configUID)
case "tenant":
params = clusterC.NewV1CloudConfigsGkeGetParams().WithConfigUID(configUID)
}
func (h *V1Client) GetCloudConfigGke(configUID string) (*models.V1GcpCloudConfig, error) {
var params *clientV1.V1CloudConfigsGkeGetParams

Check failure on line 20 in client/cluster_gke.go

View workflow job for this annotation

GitHub Actions / build-with-coverage

S1021: should merge variable declaration with assignment on next line (gosimple)
params = clientV1.NewV1CloudConfigsGkeGetParamsWithContext(h.ctx).WithConfigUID(configUID)

success, err := h.GetClusterClient().V1CloudConfigsGkeGet(params)
var e *transport.TransportError
if errors.As(err, &e) && e.HttpCode == 404 {
return nil, nil
} else if err != nil {
success, err := h.Client.V1CloudConfigsGkeGet(params)
if err != nil {
return nil, err
}

return success.Payload, nil
}

func (h *V1Client) CreateMachinePoolGke(cloudConfigId, ClusterContext string, machinePool *models.V1GcpMachinePoolConfigEntity) error {
var params *clusterC.V1CloudConfigsGkeMachinePoolCreateParams
switch ClusterContext {
case "project":
params = clusterC.NewV1CloudConfigsGkeMachinePoolCreateParamsWithContext(h.Ctx).WithConfigUID(cloudConfigId).WithBody(machinePool)
case "tenant":
params = clusterC.NewV1CloudConfigsGkeMachinePoolCreateParams().WithConfigUID(cloudConfigId).WithBody(machinePool)
}

_, err := h.GetClusterClient().V1CloudConfigsGkeMachinePoolCreate(params)
var params *clientV1.V1CloudConfigsGkeMachinePoolCreateParams

Check failure on line 32 in client/cluster_gke.go

View workflow job for this annotation

GitHub Actions / build-with-coverage

S1021: should merge variable declaration with assignment on next line (gosimple)
params = clientV1.NewV1CloudConfigsGkeMachinePoolCreateParamsWithContext(h.ctx).WithConfigUID(cloudConfigId).WithBody(machinePool)
_, err := h.Client.V1CloudConfigsGkeMachinePoolCreate(params)
return err
}

func (h *V1Client) UpdateMachinePoolGke(cloudConfigId, ClusterContext string, machinePool *models.V1GcpMachinePoolConfigEntity) error {
var params *clusterC.V1CloudConfigsGkeMachinePoolUpdateParams
switch ClusterContext {
case "project":
params = clusterC.NewV1CloudConfigsGkeMachinePoolUpdateParamsWithContext(h.Ctx).
WithConfigUID(cloudConfigId).
WithMachinePoolName(*machinePool.PoolConfig.Name).
WithBody(machinePool)
case "tenant":
params = clusterC.NewV1CloudConfigsGkeMachinePoolUpdateParams().
WithConfigUID(cloudConfigId).
WithMachinePoolName(*machinePool.PoolConfig.Name).
WithBody(machinePool)
}
func (h *V1Client) UpdateMachinePoolGke(cloudConfigId string, machinePool *models.V1GcpMachinePoolConfigEntity) error {
var params *clientV1.V1CloudConfigsGkeMachinePoolUpdateParams

Check failure on line 39 in client/cluster_gke.go

View workflow job for this annotation

GitHub Actions / build-with-coverage

S1021: should merge variable declaration with assignment on next line (gosimple)
params = clientV1.NewV1CloudConfigsGkeMachinePoolUpdateParamsWithContext(h.ctx).
WithConfigUID(cloudConfigId).
WithMachinePoolName(*machinePool.PoolConfig.Name).
WithBody(machinePool)

_, err := h.GetClusterClient().V1CloudConfigsGkeMachinePoolUpdate(params)
_, err := h.Client.V1CloudConfigsGkeMachinePoolUpdate(params)
return err
}

func (h *V1Client) DeleteMachinePoolGke(cloudConfigId, machinePoolName, ClusterContext string) error {
var params *clusterC.V1CloudConfigsGkeMachinePoolDeleteParams
switch ClusterContext {
case "project":
params = clusterC.NewV1CloudConfigsGkeMachinePoolDeleteParamsWithContext(h.Ctx).WithConfigUID(cloudConfigId).WithMachinePoolName(machinePoolName)
case "tenant":
params = clusterC.NewV1CloudConfigsGkeMachinePoolDeleteParams().WithConfigUID(cloudConfigId).WithMachinePoolName(machinePoolName)
}

_, err := h.GetClusterClient().V1CloudConfigsGkeMachinePoolDelete(params)
func (h *V1Client) DeleteMachinePoolGke(cloudConfigId string, machinePoolName string) error {
var params *clientV1.V1CloudConfigsGkeMachinePoolDeleteParams

Check failure on line 50 in client/cluster_gke.go

View workflow job for this annotation

GitHub Actions / build-with-coverage

S1021: should merge variable declaration with assignment on next line (gosimple)
params = clientV1.NewV1CloudConfigsGkeMachinePoolDeleteParamsWithContext(h.ctx).WithConfigUID(cloudConfigId).WithMachinePoolName(machinePoolName)
_, err := h.Client.V1CloudConfigsGkeMachinePoolDelete(params)
return err
}

func (h *V1Client) GetNodeStatusMapGke(configUID, machinePoolName, ClusterContext string) (map[string]models.V1CloudMachineStatus, error) {
var params *clusterC.V1CloudConfigsGkePoolMachinesListParams
switch ClusterContext {
case "project":
params = clusterC.NewV1CloudConfigsGkePoolMachinesListParamsWithContext(h.Ctx).WithConfigUID(configUID).WithMachinePoolName(machinePoolName)
case "tenant":
params = clusterC.NewV1CloudConfigsGkePoolMachinesListParams().WithConfigUID(configUID).WithMachinePoolName(machinePoolName)
}
func (h *V1Client) GetNodeStatusMapGke(configUID string, machinePoolName string) (map[string]models.V1CloudMachineStatus, error) {
var params *clientV1.V1CloudConfigsGkePoolMachinesListParams

Check failure on line 57 in client/cluster_gke.go

View workflow job for this annotation

GitHub Actions / build-with-coverage

S1021: should merge variable declaration with assignment on next line (gosimple)
params = clientV1.NewV1CloudConfigsGkePoolMachinesListParamsWithContext(h.ctx).WithConfigUID(configUID).WithMachinePoolName(machinePoolName)

mpList, err := h.GetClusterClient().V1CloudConfigsGkePoolMachinesList(params)
mpList, err := h.Client.V1CloudConfigsGkePoolMachinesList(params)
nMap := map[string]models.V1CloudMachineStatus{}
if len(mpList.Payload.Items) > 0 {
for _, node := range mpList.Payload.Items {
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ require (
github.com/go-openapi/strfmt v0.21.7
github.com/pkg/errors v0.9.1
github.com/spectrocloud/gomi v1.14.0
github.com/spectrocloud/hapi v1.14.0
github.com/spectrocloud/palette-api-go v0.2.3
github.com/stretchr/testify v1.8.4
)
Expand Down
Loading

0 comments on commit 84bccbb

Please sign in to comment.