diff --git a/client/cluster.go b/client/cluster.go index 535178f2..2f03f443 100644 --- a/client/cluster.go +++ b/client/cluster.go @@ -1,6 +1,7 @@ package client import ( + "errors" "fmt" "strings" @@ -183,7 +184,7 @@ func (h *V1Client) GetClusterByName(name, clusterContext string) (*models.V1Spec return nil, nil } -func (h *V1Client) GetClusterKubeConfig(uid string) (string, error) { +func (h *V1Client) GetClusterKubeConfig(uid string, ClusterContext string) (string, error) { if h.GetClusterKubeConfigFn != nil { return h.GetClusterKubeConfigFn(uid) } @@ -192,20 +193,18 @@ func (h *V1Client) GetClusterKubeConfig(uid string) (string, error) { return "", err } - builder := new(strings.Builder) + var params *clusterC.V1SpectroClustersUIDKubeConfigParams + switch ClusterContext { + case "project": + params = clusterC.NewV1SpectroClustersUIDKubeConfigParamsWithContext(h.Ctx).WithUID(uid) + case "tenant": + params = clusterC.NewV1SpectroClustersUIDKubeConfigParams().WithUID(uid) + default: + return "", errors.New("invalid cluster scope specified") + } - params := clusterC.NewV1SpectroClustersUIDKubeConfigParamsWithContext(h.Ctx).WithUID(uid) + builder := new(strings.Builder) _, err = client.V1SpectroClustersUIDKubeConfig(params, builder) - // handle tenant context here cluster may be a tenant cluster - if e, ok := err.(*transport.TransportError); ok && e.HttpCode == 404 { - params := clusterC.NewV1SpectroClustersUIDKubeConfigParams().WithUID(uid) - _, err = client.V1SpectroClustersUIDKubeConfig(params, builder) - if e, ok := err.(*transport.TransportError); ok && e.HttpCode == 404 { - return "", nil - } else if err != nil { - return "", err - } - } if err != nil { if herr.IsNotFound(err) { return "", nil diff --git a/client/cluster_aws.go b/client/cluster_aws.go index 4fe37470..09d86835 100644 --- a/client/cluster_aws.go +++ b/client/cluster_aws.go @@ -6,13 +6,20 @@ import ( clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" ) -func (h *V1Client) CreateClusterAws(cluster *models.V1SpectroAwsClusterEntity) (string, error) { +func (h *V1Client) CreateClusterAws(cluster *models.V1SpectroAwsClusterEntity, ClusterContext string) (string, error) { client, err := h.GetClusterClient() if err != nil { return "", err } - params := clusterC.NewV1SpectroClustersAwsCreateParamsWithContext(h.Ctx).WithBody(cluster) + var params *clusterC.V1SpectroClustersAwsCreateParams + switch ClusterContext { + case "project": + params = clusterC.NewV1SpectroClustersAwsCreateParamsWithContext(h.Ctx).WithBody(cluster) + case "tenant": + params = clusterC.NewV1SpectroClustersAwsCreateParams().WithBody(cluster) + } + success, err := client.V1SpectroClustersAwsCreate(params) if err != nil { return "", err diff --git a/client/cluster_backup_config.go b/client/cluster_backup_config.go index 538b95a1..3574c2a1 100644 --- a/client/cluster_backup_config.go +++ b/client/cluster_backup_config.go @@ -1,12 +1,15 @@ package client import ( + "errors" + "github.com/spectrocloud/hapi/models" clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1" + "github.com/spectrocloud/palette-sdk-go/client/herr" ) -func (h *V1Client) GetClusterBackupConfig(uid string) (*models.V1ClusterBackup, error) { +func (h *V1Client) GetClusterBackupConfig(uid, ClusterContext string) (*models.V1ClusterBackup, error) { if h.GetClusterBackupConfigFn != nil { return h.GetClusterBackupConfigFn(uid) } @@ -15,7 +18,17 @@ func (h *V1Client) GetClusterBackupConfig(uid string) (*models.V1ClusterBackup, return nil, err } - params := clusterC.NewV1ClusterFeatureBackupGetParamsWithContext(h.Ctx).WithUID(uid) + var params *clusterC.V1ClusterFeatureBackupGetParams + switch ClusterContext { + case "project": + params = clusterC.NewV1ClusterFeatureBackupGetParamsWithContext(h.Ctx).WithUID(uid) + case "tenant": + params = clusterC.NewV1ClusterFeatureBackupGetParams().WithUID(uid) + default: + return nil, errors.New("invalid cluster scope specified") + + } + success, err := client.V1ClusterFeatureBackupGet(params) if err != nil { if herr.IsNotFound(err) || herr.IsBackupNotConfigured(err) { @@ -48,13 +61,3 @@ func (h *V1Client) UpdateClusterBackupConfig(uid string, config *models.V1Cluste _, err = client.V1ClusterFeatureBackupUpdate(params) return err } - -func (h *V1Client) ApplyClusterBackupConfig(uid string, config *models.V1ClusterBackupConfig) error { - if policy, err := h.GetClusterBackupConfig(uid); err != nil { - return err - } else if policy == nil { - return h.CreateClusterBackupConfig(uid, config) - } else { - return h.UpdateClusterBackupConfig(uid, config) - } -} diff --git a/client/cluster_vsphere.go b/client/cluster_vsphere.go index 020ae34e..ef65a31a 100644 --- a/client/cluster_vsphere.go +++ b/client/cluster_vsphere.go @@ -8,7 +8,7 @@ import ( // Cluster -func (h *V1Client) CreateClusterVsphere(cluster *models.V1SpectroVsphereClusterEntity) (string, error) { +func (h *V1Client) CreateClusterVsphere(cluster *models.V1SpectroVsphereClusterEntity, ClusterContext string) (string, error) { if h.CreateClusterVsphereFn != nil { return h.CreateClusterVsphereFn(cluster) } @@ -17,7 +17,14 @@ func (h *V1Client) CreateClusterVsphere(cluster *models.V1SpectroVsphereClusterE return "", err } - params := clusterC.NewV1SpectroClustersVsphereCreateParamsWithContext(h.Ctx).WithBody(cluster) + var params *clusterC.V1SpectroClustersVsphereCreateParams + switch ClusterContext { + case "project": + params = clusterC.NewV1SpectroClustersVsphereCreateParamsWithContext(h.Ctx).WithBody(cluster) + case "tenant": + params = clusterC.NewV1SpectroClustersVsphereCreateParams().WithBody(cluster) + } + success, err := client.V1SpectroClustersVsphereCreate(params) if err != nil { return "", err