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

Release TF Provider v0.17.5 (custom cloud support) #89

Merged
merged 18 commits into from
Feb 19, 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
137 changes: 137 additions & 0 deletions client/account_custom_cloud.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package client

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

func (h *V1Client) CreateAccountCustomCloud(account *models.V1CustomAccountEntity, cloudType string, accountContext string) (string, error) {
if h.CreateCustomCloudAccountFn != nil {
return h.CreateCustomCloudAccountFn(account, cloudType, accountContext)
}
var params *clusterC.V1CloudAccountsCustomCreateParams

// check PCG
PcgId := account.Metadata.Annotations[OverlordUID]
if err := h.CheckPCG(PcgId); err != nil {
return "", err
}
switch accountContext {
case "project":
params = clusterC.NewV1CloudAccountsCustomCreateParamsWithContext(h.Ctx)
case "tenant":
params = clusterC.NewV1CloudAccountsCustomCreateParams()
}
params = params.WithBody(account).WithCloudType(cloudType)
success, err := h.GetClusterClient().V1CloudAccountsCustomCreate(params)
if err != nil {
return "", err
}

return *success.Payload.UID, nil
}

func (h *V1Client) GetCustomCloudAccount(uid, cloudType string, accountContext string) (*models.V1CustomAccount, error) {
if h.GetCustomCloudAccountFn != nil {
return h.GetCustomCloudAccountFn(uid, cloudType, accountContext)
}
var params *clusterC.V1CloudAccountsCustomGetParams

switch accountContext {
case "project":
params = clusterC.NewV1CloudAccountsCustomGetParamsWithContext(h.Ctx)
case "tenant":
params = clusterC.NewV1CloudAccountsCustomGetParams()
}
params = params.WithCloudType(cloudType).WithUID(uid)
success, err := h.GetClusterClient().V1CloudAccountsCustomGet(params)
if err != nil {
return nil, err
}
return success.Payload, nil
}

func (h *V1Client) UpdateAccountCustomCloud(uid string, account *models.V1CustomAccountEntity, cloudType string, accountContext string) error {
if h.UpdateCustomCloudAccountFn != nil {
return h.UpdateCustomCloudAccountFn(uid, account, cloudType, accountContext)
}
var params *clusterC.V1CloudAccountsCustomUpdateParams

switch accountContext {
case "project":
params = clusterC.NewV1CloudAccountsCustomUpdateParamsWithContext(h.Ctx)
case "tenant":
params = clusterC.NewV1CloudAccountsCustomUpdateParams()
}
params = params.WithBody(account).WithCloudType(cloudType).WithUID(uid)
_, err := h.GetClusterClient().V1CloudAccountsCustomUpdate(params)
if err != nil {
return err
}

return nil
}

func (h *V1Client) DeleteCloudAccountCustomCloud(uid, cloudType string, accountContext string) error {
if h.DeleteCustomCloudAccountFn != nil {
return h.DeleteCustomCloudAccountFn(uid, cloudType, accountContext)
}
var params *clusterC.V1CloudAccountsCustomDeleteParams

switch accountContext {
case "project":
params = clusterC.NewV1CloudAccountsCustomDeleteParamsWithContext(h.Ctx)
case "tenant":
params = clusterC.NewV1CloudAccountsCustomDeleteParams()
}
params = params.WithCloudType(cloudType).WithUID(uid)
_, err := h.GetClusterClient().V1CloudAccountsCustomDelete(params)
return err
}

func (h *V1Client) ValidateCustomCloudType(cloudType string, cloudContext string) error {
if h.ValidateCustomCloudTypeFn != nil {
return h.ValidateCustomCloudTypeFn(cloudType, cloudContext)
}
var params *cloudC.V1CustomCloudTypesGetParams
switch cloudContext {
case "project":
params = cloudC.NewV1CustomCloudTypesGetParamsWithContext(h.Ctx)
case "tenant":
params = cloudC.NewV1CustomCloudTypesGetParams()
}
success, err := h.GetCloudClient().V1CustomCloudTypesGet(params)
if err != nil {
return err
}
customCloudTypes := success.GetPayload().CloudTypes
for _, c := range customCloudTypes {
if c.Name == cloudType {
if c.IsCustom {
return nil
} else {
return fmt.Errorf("cloud - `%s` is not a valid custom cloud", cloudType)
}
}
}
return fmt.Errorf("cloud - `%s` is not a valid cloud", cloudType)
}

func (h *V1Client) GetCustomCloudAccountList(cloudType string) ([]*models.V1CustomAccount, error) {
if h.GetCustomCloudAccountListFn != nil {
return h.GetCustomCloudAccountListFn(cloudType)
}
limit := int64(0)
params := clusterC.NewV1CloudAccountsCustomListParamsWithContext(h.Ctx).WithLimit(&limit).WithCloudType(cloudType)
response, err := h.GetClusterClient().V1CloudAccountsCustomList(params)
if err != nil {
return nil, err
}

accounts := make([]*models.V1CustomAccount, len(response.Payload.Items))
copy(accounts, response.Payload.Items)

return accounts, nil
}
39 changes: 29 additions & 10 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,19 @@ type V1Client struct {
ClusterC clusterC.ClientService

// 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)
GetClusterRbacConfigFn func(uid string) (*models.V1ClusterRbacs, error)
GetClusterNamespaceConfigFn func(uid string) (*models.V1ClusterNamespaceResources, error)
ApproveClusterRepaveFn func(context, clusterUID string) error
GetRepaveReasonsFn func(context, clusterUID string) ([]string, error)
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)
GetClusterRbacConfigFn func(uid string) (*models.V1ClusterRbacs, error)
GetClusterNamespaceConfigFn func(uid string) (*models.V1ClusterNamespaceResources, error)
ApproveClusterRepaveFn func(context, clusterUID string) error
GetRepaveReasonsFn func(context, clusterUID string) ([]string, error)
UpdatePauseAgentUpgradeSettingClusterFn func(upgradeSetting *models.V1ClusterUpgradeSettingsEntity, clusterUID string, context string) error
UpdatePauseAgentUpgradeSettingContextFn func(upgradeSetting *models.V1ClusterUpgradeSettingsEntity, context string) error
GetPauseAgentUpgradeSettingContextFn func(context string) (string, error)

// Cluster Groups
CreateClusterGroupFn func(*models.V1ClusterGroupEntity) (string, error)
Expand Down Expand Up @@ -108,6 +111,22 @@ type V1Client struct {
UpdateMacrosFn func(uid string, macros *models.V1Macros) error
DeleteMacrosFn func(uid string, body *models.V1Macros) error
GetMacrosIdFn func(uid string) (string, error)

// 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
GetCustomCloudAccountListFn func(cloudType string) ([]*models.V1CustomAccount, 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, machinePoolName string, 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
65 changes: 65 additions & 0 deletions client/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,3 +259,68 @@ func (h *V1Client) GetRepaveReasons(context, clusterUID string) ([]string, error
}
return reasons, err
}

func (h *V1Client) UpdatePauseAgentUpgradeSettingCluster(upgradeSetting *models.V1ClusterUpgradeSettingsEntity, clusterUID string, context string) error {
if h.UpdatePauseAgentUpgradeSettingClusterFn != nil {
return h.UpdatePauseAgentUpgradeSettingClusterFn(upgradeSetting, clusterUID, context)
}
var params *clusterC.V1SpectroClustersUIDUpgradeSettingsParams

switch context {
case "project":
params = clusterC.NewV1SpectroClustersUIDUpgradeSettingsParamsWithContext(h.Ctx)
case "tenant":
params = clusterC.NewV1SpectroClustersUIDUpgradeSettingsParams()
default:
return fmt.Errorf("invalid context: %s", context)
}
params = params.WithUID(clusterUID).WithBody(upgradeSetting)
_, err := h.GetClusterClient().V1SpectroClustersUIDUpgradeSettings(params)
if err != nil {
return err
}
return nil
}

func (h *V1Client) UpdatePauseAgentUpgradeSettingContext(upgradeSetting *models.V1ClusterUpgradeSettingsEntity, context string) error {
if h.UpdatePauseAgentUpgradeSettingContextFn != nil {
return h.UpdatePauseAgentUpgradeSettingContextFn(upgradeSetting, context)
}
var params *clusterC.V1SpectroClustersUpgradeSettingsParams

switch context {
case "project":
params = clusterC.NewV1SpectroClustersUpgradeSettingsParamsWithContext(h.Ctx)
case "tenant":
params = clusterC.NewV1SpectroClustersUpgradeSettingsParams()
default:
return fmt.Errorf("invalid context: %s", context)
}
params = params.WithBody(upgradeSetting)
_, err := h.GetClusterClient().V1SpectroClustersUpgradeSettings(params)
if err != nil {
return err
}
return nil
}

func (h *V1Client) GetPauseAgentUpgradeSettingContext(context string) (string, error) {
if h.GetPauseAgentUpgradeSettingContextFn != nil {
return h.GetPauseAgentUpgradeSettingContextFn(context)
}
var params *clusterC.V1SpectroClustersUpgradeSettingsGetParams

switch context {
case "project":
params = clusterC.NewV1SpectroClustersUpgradeSettingsGetParamsWithContext(h.Ctx)
case "tenant":
params = clusterC.NewV1SpectroClustersUpgradeSettingsGetParams()
default:
return "", fmt.Errorf("invalid context: %s", context)
}
resp, err := h.GetClusterClient().V1SpectroClustersUpgradeSettingsGet(params)
if err != nil {
return "", err
}
return resp.Payload.SpectroComponents, nil
}
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, machinePoolName, configUID string, cloudType string, clusterContext string) error {
if h.UpdateMachinePoolCustomCloudFn != nil {
return h.UpdateMachinePoolCustomCloudFn(mpEntity, machinePoolName, 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).WithMachinePoolName(machinePoolName)
_, 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
}
Loading
Loading