Skip to content

Commit

Permalink
PLT-626: Added gpu_device support in libvirt. (#335)
Browse files Browse the repository at this point in the history
* Added gpu_device support in libvirt, MachinePool>Placements

* added unit test for flattenGPUdevices

* added expand method and unittest for same

* PLT-626: add description for cloud account credentials type.

* PLT-626: docs refresh.

* Merging with main.

* PLT-626: docs refresh.

---------

Co-authored-by: nikolay-spectro <[email protected]>
  • Loading branch information
SivaanandM and nikchern authored Oct 3, 2023
1 parent 0ff60c3 commit 01fa2e9
Show file tree
Hide file tree
Showing 18 changed files with 254 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/resources/cloudaccount_aws.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ resource "spectrocloud_cloudaccount_aws" "aws-1" {
Can be 'aws' for standard AWS regions or 'aws-us-gov' for AWS GovCloud (US) regions.
Default is 'aws'.
- `policy_arns` (Set of String) A set of ARNs for the IAM policies that should be associated with the cloud account.
- `type` (String)
- `type` (String) The type of AWS credentials to use. Can be `secret` or `sts`.

### Read-Only

Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_aks.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ resource "spectrocloud_cluster_aks" "cluster" {

- `apply_setting` (String) The setting to apply the cluster profile. `DownloadAndInstall` will download and install packs in one action. `DownloadAndInstallLater` will only download artifact and postpone install for later. Default value is `DownloadAndInstall`.
- `backup_policy` (Block List, Max: 1) (see [below for nested schema](#nestedblock--backup_policy))
- `cluster_meta_attribute` (String) `cluster_meta_attribute` can be used to set additional cluster metadata information, eg `{'nic_name': 'test', 'env': 'stage'}`
- `cluster_profile` (Block List) (see [below for nested schema](#nestedblock--cluster_profile))
- `cluster_rbac_binding` (Block List) (see [below for nested schema](#nestedblock--cluster_rbac_binding))
- `context` (String) The context of the AKS cluster. Can be `project` or `tenant`. Default is `project`.
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_aws.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ resource "spectrocloud_cluster_aws" "cluster" {

- `apply_setting` (String) The setting to apply the cluster profile. `DownloadAndInstall` will download and install packs in one action. `DownloadAndInstallLater` will only download artifact and postpone install for later. Default value is `DownloadAndInstall`.
- `backup_policy` (Block List, Max: 1) (see [below for nested schema](#nestedblock--backup_policy))
- `cluster_meta_attribute` (String) `cluster_meta_attribute` can be used to set additional cluster metadata information, eg `{'nic_name': 'test', 'env': 'stage'}`
- `cluster_profile` (Block List) (see [below for nested schema](#nestedblock--cluster_profile))
- `cluster_rbac_binding` (Block List) (see [below for nested schema](#nestedblock--cluster_rbac_binding))
- `context` (String) The context of the AWS cluster. Can be `project` or `tenant`. Default is `project`.
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_azure.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ resource "spectrocloud_cluster_azure" "cluster" {

- `apply_setting` (String) The setting to apply the cluster profile. `DownloadAndInstall` will download and install packs in one action. `DownloadAndInstallLater` will only download artifact and postpone install for later. Default value is `DownloadAndInstall`.
- `backup_policy` (Block List, Max: 1) (see [below for nested schema](#nestedblock--backup_policy))
- `cluster_meta_attribute` (String) `cluster_meta_attribute` can be used to set additional cluster metadata information, eg `{'nic_name': 'test', 'env': 'stage'}`
- `cluster_profile` (Block List) (see [below for nested schema](#nestedblock--cluster_profile))
- `cluster_rbac_binding` (Block List) (see [below for nested schema](#nestedblock--cluster_rbac_binding))
- `context` (String) The context of the Azure cluster. Can be `project` or `tenant`. Default is `project`.
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_coxedge.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ description: |-

- `apply_setting` (String) The setting to apply the cluster profile. `DownloadAndInstall` will download and install packs in one action. `DownloadAndInstallLater` will only download artifact and postpone install for later. Default value is `DownloadAndInstall`.
- `backup_policy` (Block List, Max: 1) (see [below for nested schema](#nestedblock--backup_policy))
- `cluster_meta_attribute` (String) `cluster_meta_attribute` can be used to set additional cluster metadata information, eg `{'nic_name': 'test', 'env': 'stage'}`
- `cluster_profile` (Block List) (see [below for nested schema](#nestedblock--cluster_profile))
- `cluster_rbac_binding` (Block List) (see [below for nested schema](#nestedblock--cluster_rbac_binding))
- `context` (String) The context of the CoxEdge cluster. Can be `project` or `tenant`. Default is `project`.
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_edge_native.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ description: |-
- `apply_setting` (String) The setting to apply the cluster profile. `DownloadAndInstall` will download and install packs in one action. `DownloadAndInstallLater` will only download artifact and postpone install for later. Default value is `DownloadAndInstall`.
- `backup_policy` (Block List, Max: 1) (see [below for nested schema](#nestedblock--backup_policy))
- `cloud_account_id` (String)
- `cluster_meta_attribute` (String) `cluster_meta_attribute` can be used to set additional cluster metadata information, eg `{'nic_name': 'test', 'env': 'stage'}`
- `cluster_profile` (Block List) (see [below for nested schema](#nestedblock--cluster_profile))
- `cluster_rbac_binding` (Block List) (see [below for nested schema](#nestedblock--cluster_rbac_binding))
- `context` (String) The context of the Edge cluster. Can be `project` or `tenant`. Default is `project`.
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_edge_vsphere.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ description: |-
### Optional

- `backup_policy` (Block List, Max: 1) (see [below for nested schema](#nestedblock--backup_policy))
- `cluster_meta_attribute` (String) `cluster_meta_attribute` can be used to set additional cluster metadata information, eg `{'nic_name': 'test', 'env': 'stage'}`
- `cluster_profile` (Block List) (see [below for nested schema](#nestedblock--cluster_profile))
- `cluster_rbac_binding` (Block List) (see [below for nested schema](#nestedblock--cluster_rbac_binding))
- `context` (String) The context of the Edge cluster. Can be `project` or `tenant`. Default is `project`.
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_eks.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ resource "spectrocloud_cluster_eks" "cluster" {

- `apply_setting` (String) The setting to apply the cluster profile. `DownloadAndInstall` will download and install packs in one action. `DownloadAndInstallLater` will only download artifact and postpone install for later. Default value is `DownloadAndInstall`.
- `backup_policy` (Block List, Max: 1) (see [below for nested schema](#nestedblock--backup_policy))
- `cluster_meta_attribute` (String) `cluster_meta_attribute` can be used to set additional cluster metadata information, eg `{'nic_name': 'test', 'env': 'stage'}`
- `cluster_profile` (Block List) (see [below for nested schema](#nestedblock--cluster_profile))
- `cluster_rbac_binding` (Block List) (see [below for nested schema](#nestedblock--cluster_rbac_binding))
- `context` (String) The context of the EKS cluster. Can be `project` or `tenant`. Default is `project`.
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_gcp.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ resource "spectrocloud_cluster_gcp" "cluster" {

- `apply_setting` (String) The setting to apply the cluster profile. `DownloadAndInstall` will download and install packs in one action. `DownloadAndInstallLater` will only download artifact and postpone install for later. Default value is `DownloadAndInstall`.
- `backup_policy` (Block List, Max: 1) (see [below for nested schema](#nestedblock--backup_policy))
- `cluster_meta_attribute` (String) `cluster_meta_attribute` can be used to set additional cluster metadata information, eg `{'nic_name': 'test', 'env': 'stage'}`
- `cluster_profile` (Block List) (see [below for nested schema](#nestedblock--cluster_profile))
- `cluster_rbac_binding` (Block List) (see [below for nested schema](#nestedblock--cluster_rbac_binding))
- `context` (String) The context of the GCP cluster. Can be `project` or `tenant`. Default is `project`.
Expand Down
15 changes: 15 additions & 0 deletions docs/resources/cluster_libvirt.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ description: |-
- `apply_setting` (String) The setting to apply the cluster profile. `DownloadAndInstall` will download and install packs in one action. `DownloadAndInstallLater` will only download artifact and postpone install for later. Default value is `DownloadAndInstall`.
- `backup_policy` (Block List, Max: 1) (see [below for nested schema](#nestedblock--backup_policy))
- `cloud_account_id` (String)
- `cluster_meta_attribute` (String) `cluster_meta_attribute` can be used to set additional cluster metadata information, eg `{'nic_name': 'test', 'env': 'stage'}`
- `cluster_profile` (Block List) (see [below for nested schema](#nestedblock--cluster_profile))
- `cluster_rbac_binding` (Block List) (see [below for nested schema](#nestedblock--cluster_rbac_binding))
- `context` (String) The context of the Libvirt cluster. Can be `project` or `tenant`. Default is `project`.
Expand Down Expand Up @@ -145,8 +146,22 @@ Required:

Optional:

- `gpu_device` (Block List) (see [below for nested schema](#nestedblock--machine_pool--placements--gpu_device))
- `network` (String)

<a id="nestedblock--machine_pool--placements--gpu_device"></a>
### Nested Schema for `machine_pool.placements.gpu_device`

Required:

- `device_model` (String) DeviceModel `device_model` is the model of GPU, for a given vendor, for eg., TU104GL [Tesla T4]
- `vendor` (String) Vendor `vendor` is the GPU vendor, for eg., NVIDIA or AMD

Optional:

- `addresses` (Map of String) Addresses is a map of PCI device entry name to its addresses.



<a id="nestedblock--machine_pool--node"></a>
### Nested Schema for `machine_pool.node`
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_maas.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ resource "spectrocloud_cluster_maas" "cluster" {
- `apply_setting` (String) The setting to apply the cluster profile. `DownloadAndInstall` will download and install packs in one action. `DownloadAndInstallLater` will only download artifact and postpone install for later. Default value is `DownloadAndInstall`.
- `backup_policy` (Block List, Max: 1) (see [below for nested schema](#nestedblock--backup_policy))
- `cloud_account_id` (String)
- `cluster_meta_attribute` (String) `cluster_meta_attribute` can be used to set additional cluster metadata information, eg `{'nic_name': 'test', 'env': 'stage'}`
- `cluster_profile` (Block List) (see [below for nested schema](#nestedblock--cluster_profile))
- `cluster_rbac_binding` (Block List) (see [below for nested schema](#nestedblock--cluster_rbac_binding))
- `context` (String) The context of the MAAS cluster. Can be `project` or `tenant`. Default is `project`.
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_openstack.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ resource "spectrocloud_cluster_openstack" "cluster" {

- `apply_setting` (String) The setting to apply the cluster profile. `DownloadAndInstall` will download and install packs in one action. `DownloadAndInstallLater` will only download artifact and postpone install for later. Default value is `DownloadAndInstall`.
- `backup_policy` (Block List, Max: 1) (see [below for nested schema](#nestedblock--backup_policy))
- `cluster_meta_attribute` (String) `cluster_meta_attribute` can be used to set additional cluster metadata information, eg `{'nic_name': 'test', 'env': 'stage'}`
- `cluster_profile` (Block List) (see [below for nested schema](#nestedblock--cluster_profile))
- `cluster_rbac_binding` (Block List) (see [below for nested schema](#nestedblock--cluster_rbac_binding))
- `context` (String) The context of the OpenStack cluster. Can be `project` or `tenant`. Default is `project`.
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_tke.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ description: |-

- `apply_setting` (String) The setting to apply the cluster profile. `DownloadAndInstall` will download and install packs in one action. `DownloadAndInstallLater` will only download artifact and postpone install for later. Default value is `DownloadAndInstall`.
- `backup_policy` (Block List, Max: 1) (see [below for nested schema](#nestedblock--backup_policy))
- `cluster_meta_attribute` (String) `cluster_meta_attribute` can be used to set additional cluster metadata information, eg `{'nic_name': 'test', 'env': 'stage'}`
- `cluster_profile` (Block List) (see [below for nested schema](#nestedblock--cluster_profile))
- `cluster_rbac_binding` (Block List) (see [below for nested schema](#nestedblock--cluster_rbac_binding))
- `context` (String) The context of the TKE cluster. Can be `project` or `tenant`. Default is `project`.
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_vsphere.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ description: |-

- `apply_setting` (String) The setting to apply the cluster profile. `DownloadAndInstall` will download and install packs in one action. `DownloadAndInstallLater` will only download artifact and postpone install for later. Default value is `DownloadAndInstall`.
- `backup_policy` (Block List, Max: 1) (see [below for nested schema](#nestedblock--backup_policy))
- `cluster_meta_attribute` (String) `cluster_meta_attribute` can be used to set additional cluster metadata information, eg `{'nic_name': 'test', 'env': 'stage'}`
- `cluster_profile` (Block List) (see [below for nested schema](#nestedblock--cluster_profile))
- `cluster_rbac_binding` (Block List) (see [below for nested schema](#nestedblock--cluster_rbac_binding))
- `context` (String) The context of the VMware cluster. Can be `project` or `tenant`. Default is `project`.
Expand Down
6 changes: 0 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -716,14 +716,8 @@ github.com/soheilhy/cmux v0.1.5/go.mod h1:T7TcVDs9LWfQgPlPsdngu6I6QIoyIFZDDC6sNE
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spectrocloud/gomi v1.14.1-0.20230412095143-b0595c6c6f08 h1:AnOC0U+ExlKBeT5yF2Pg8PPfVOfxwOUBS/5deOl1Q4Y=
github.com/spectrocloud/gomi v1.14.1-0.20230412095143-b0595c6c6f08/go.mod h1:UnhUDpFEvtYh6m384r3xzj8/+Z6/hMp2O8whEMYVHec=
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.20230904045215-e74ab706b811 h1:Ngfc9yyOZ28OpCmE23TuoG9w9VrnhizOKNQ5TOMprNY=
github.com/spectrocloud/hapi v1.14.1-0.20230904045215-e74ab706b811/go.mod h1:O/Bkbw92QPSGPNQPqKt7Qlkn+9BKK/a22KTUlk76KHI=
github.com/spectrocloud/hapi v1.14.1-0.20230928114741-1670ab9a5e2b h1:Ws5/fRo/EDEt1rJgNEtd2E/w/IOOA+jOVWv3tw6aT+s=
github.com/spectrocloud/hapi v1.14.1-0.20230928114741-1670ab9a5e2b/go.mod h1:aI54jbfaSec1ikHSMOJQ7mMOTaRKpQTRCoMKamhBE9s=
github.com/spectrocloud/palette-sdk-go v0.0.0-20230829045040-bf4cc9aa60e1 h1:gqnua/jMzX8fx9yt+niCxQ99XkzKiA+HF+LRbFbWYC8=
github.com/spectrocloud/palette-sdk-go v0.0.0-20230829045040-bf4cc9aa60e1/go.mod h1:xrvueWGPSRdonQkTQvJgDSPe5FRbuqpPJj7Ko0/yxrQ=
github.com/spectrocloud/palette-sdk-go v0.0.0-20230925161114-b76840d1207d h1:4VBWbaMTnMbURawJcOPlDrhNpxj78cxrPwMuh52pegw=
github.com/spectrocloud/palette-sdk-go v0.0.0-20230925161114-b76840d1207d/go.mod h1:Om6X/eH6h787jrynu9NTAeuxFpC15E/Atco5kQwiM90=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
Expand Down
1 change: 1 addition & 0 deletions spectrocloud/resource_cloud_account_aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func resourceCloudAccountAws() *schema.Resource {
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"secret", "sts"}, false),
Default: "secret",
Description: "The type of AWS credentials to use. Can be `secret` or `sts`. ",
},
"arn": {
Type: schema.TypeString,
Expand Down
68 changes: 68 additions & 0 deletions spectrocloud/resource_cluster_libvirt.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,32 @@ func resourceClusterLibvirt() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"gpu_device": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"device_model": {
Type: schema.TypeString,
Required: true,
Description: "DeviceModel `device_model` is the model of GPU, for a given vendor, for eg., TU104GL [Tesla T4]",
},
"vendor": {
Type: schema.TypeString,
Required: true,
Description: "Vendor `vendor` is the GPU vendor, for eg., NVIDIA or AMD",
},
"addresses": {
Type: schema.TypeMap,
Optional: true,
Description: "Addresses is a map of PCI device entry name to its addresses.",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
},
},
},
Expand Down Expand Up @@ -516,6 +542,7 @@ func flattenMachinePoolConfigsLibvirt(machinePools []*models.V1LibvirtMachinePoo
pj["image_storage_pool"] = p.SourceStoragePool
pj["target_storage_pool"] = p.TargetStoragePool
pj["data_storage_pool"] = p.DataStoragePool
pj["gpu_device"] = flattenGpuDevice(p.GpuDevices)
placements[j] = pj
}
oi["placements"] = placements
Expand All @@ -527,6 +554,23 @@ func flattenMachinePoolConfigsLibvirt(machinePools []*models.V1LibvirtMachinePoo
return ois
}

func flattenGpuDevice(gpus []*models.V1GPUDeviceSpec) []interface{} {
if gpus != nil {
dConfig := make([]interface{}, 0)
for _, d := range gpus {
if !(d.Model == "" || d.Vendor == "") {
dElem := make(map[string]interface{})
dElem["device_model"] = d.Model
dElem["vendor"] = d.Vendor
dElem["addresses"] = d.Addresses
dConfig = append(dConfig, dElem)
}
}
return dConfig
}
return make([]interface{}, 0)
}

func resourceClusterVirtUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
c := m.(*client.V1Client)

Expand Down Expand Up @@ -689,12 +733,14 @@ func toMachinePoolLibvirt(machinePool interface{}) (*models.V1LibvirtMachinePool
targetStoragePool := p["target_storage_pool"].(string)
dataStoragePool := p["data_storage_pool"].(string)

gpuDevices := p["gpu_device"]
placements = append(placements, &models.V1LibvirtPlacementEntity{
Networks: networks,
SourceStoragePool: imageStoragePool,
TargetStoragePool: targetStoragePool,
DataStoragePool: dataStoragePool,
HostUID: types.Ptr(p["appliance_id"].(string)),
GpuDevices: getGPUDevices(gpuDevices),
})

}
Expand Down Expand Up @@ -793,6 +839,28 @@ func getGPUConfig(ins map[string]interface{}) *models.V1GPUConfig {
return nil
}

func getGPUDevices(gpuDevice interface{}) []*models.V1GPUDeviceSpec {
if gpuDevice != nil {
gpuDevices := make([]*models.V1GPUDeviceSpec, 0)
for _, t := range gpuDevice.([]interface{}) {
config := t.(map[string]interface{})
mapAddresses := make(map[string]string)
if config["addresses"] != nil && len(config["addresses"].(map[string]interface{})) > 0 {
mapAddresses = expandStringMap(config["addresses"].(map[string]interface{}))
}
if config != nil {
gpuDevices = append(gpuDevices, &models.V1GPUDeviceSpec{
Model: config["device_model"].(string),
Vendor: config["vendor"].(string),
Addresses: mapAddresses,
})
}
}
return gpuDevices
}
return nil
}

func getAdditionalDisks(ins map[string]interface{}) []*models.V1LibvirtDiskSpec {
addDisks := make([]*models.V1LibvirtDiskSpec, 0)

Expand Down
Loading

0 comments on commit 01fa2e9

Please sign in to comment.