Skip to content

Commit

Permalink
PLT-1449: Added host endpoint support for vsphere cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
SivaanandM committed Oct 25, 2024
1 parent 27b312a commit 17c19c8
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 32 deletions.
1 change: 1 addition & 0 deletions docs/resources/cluster_vsphere.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Required:

Optional:

- `host_endpoint` (String) The host endpoint to use for the cluster. This can be `IP` or `FQDN(External/DDNS)`.
- `image_template_folder` (String) The name of the image template folder in vSphere. This is the name of the folder as it appears in vSphere.
- `network_search_domain` (String) The search domain to use for the cluster in case of DHCP.
- `network_type` (String) The type of network to use for the cluster. This can be `VIP` or `DDNS`.
Expand Down
25 changes: 0 additions & 25 deletions spectrocloud/resource_cluster_edge_vsphere.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,17 +577,6 @@ func toEdgeVsphereCluster(c *client.V1Client, d *schema.ResourceData) (*models.V
return cluster, nil
}

func getSSHKey(cloudConfig map[string]interface{}) []string {

sshKeys, _ := toSSHKeys(cloudConfig)
return sshKeys
}

func getStaticIP(cloudConfig map[string]interface{}) bool {
staticIP := cloudConfig["static_ip"].(bool)
return staticIP
}

func getImageTemplateFolder(cloudConfig map[string]interface{}) string {
imageTemplateFolder := "spectro-templates"
if cloudConfig["image_template_folder"] != nil {
Expand All @@ -596,20 +585,6 @@ func getImageTemplateFolder(cloudConfig map[string]interface{}) string {
return imageTemplateFolder
}

func getClusterConfigEntity(cloudConfig map[string]interface{}) *models.V1VsphereClusterConfigEntity {
clusterConfigEntity := &models.V1VsphereClusterConfigEntity{
NtpServers: toNtpServers(cloudConfig),
Placement: &models.V1VspherePlacementConfigEntity{
Datacenter: cloudConfig["datacenter"].(string),
Folder: cloudConfig["folder"].(string),
ImageTemplateFolder: getImageTemplateFolder(cloudConfig),
},
SSHKeys: getSSHKey(cloudConfig),
StaticIP: getStaticIP(cloudConfig),
}
return clusterConfigEntity
}

func toMachinePoolEdgeVsphere(machinePool interface{}) (*models.V1VsphereMachinePoolConfigEntity, error) {
m := machinePool.(map[string]interface{})

Expand Down
44 changes: 37 additions & 7 deletions spectrocloud/resource_cluster_vsphere.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ func resourceClusterVsphere() *schema.Resource {
Optional: true,
Description: "The type of network to use for the cluster. This can be `VIP` or `DDNS`.",
},
"host_endpoint": {
Type: schema.TypeString,
Optional: true,
Description: "The host endpoint to use for the cluster. This can be `IP` or `FQDN(External/DDNS)`.",
},
"network_search_domain": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -488,6 +493,9 @@ func flattenClusterConfigsVsphere(d *schema.ResourceData, cloudConfig *models.V1
if cpEndpoint.DdnsSearchDomain != "" {
ret["network_search_domain"] = cpEndpoint.DdnsSearchDomain
}
if cpEndpoint.Host != "" {
ret["host_endpoint"] = cpEndpoint.Host
}
}
//Setting up placement attributes if its defined
if cloudConfig.Spec.ClusterConfig.Placement != nil {
Expand Down Expand Up @@ -812,15 +820,12 @@ func toVsphereCluster(c *client.V1Client, d *schema.ResourceData) (*models.V1Spe
}

func toCloudConfigCreate(cloudConfig map[string]interface{}) *models.V1VsphereClusterConfigEntity {
staticIP := cloudConfig["static_ip"].(bool)

V1VsphereClusterConfigEntity := getClusterConfigEntity(cloudConfig)

if !staticIP {
V1VsphereClusterConfigEntity.ControlPlaneEndpoint = &models.V1ControlPlaneEndPoint{
DdnsSearchDomain: cloudConfig["network_search_domain"].(string),
Type: cloudConfig["network_type"].(string),
}
V1VsphereClusterConfigEntity.ControlPlaneEndpoint = &models.V1ControlPlaneEndPoint{
DdnsSearchDomain: cloudConfig["network_search_domain"].(string),
Type: cloudConfig["network_type"].(string),
Host: cloudConfig["host_endpoint"].(string),
}

return V1VsphereClusterConfigEntity
Expand Down Expand Up @@ -920,3 +925,28 @@ func toMachinePoolVsphere(machinePool interface{}) (*models.V1VsphereMachinePool

return mp, nil
}

func getSSHKey(cloudConfig map[string]interface{}) []string {

sshKeys, _ := toSSHKeys(cloudConfig)
return sshKeys
}

func getStaticIP(cloudConfig map[string]interface{}) bool {
staticIP := cloudConfig["static_ip"].(bool)
return staticIP
}

func getClusterConfigEntity(cloudConfig map[string]interface{}) *models.V1VsphereClusterConfigEntity {
clusterConfigEntity := &models.V1VsphereClusterConfigEntity{
NtpServers: toNtpServers(cloudConfig),
Placement: &models.V1VspherePlacementConfigEntity{
Datacenter: cloudConfig["datacenter"].(string),
Folder: cloudConfig["folder"].(string),
ImageTemplateFolder: getImageTemplateFolder(cloudConfig),
},
SSHKeys: getSSHKey(cloudConfig),
StaticIP: getStaticIP(cloudConfig),
}
return clusterConfigEntity
}
2 changes: 2 additions & 0 deletions spectrocloud/resource_cluster_vsphere_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func TestToCloudConfigUpdate(t *testing.T) {
"datacenter": "Datacenter",
"folder": "sc_test/terraform",
"network_type": "DDNS",
"host_endpoint": "tt.tt.test.com",
"network_search_domain": "spectrocloud.dev",
"static_ip": false,
}
Expand All @@ -116,6 +117,7 @@ func TestToCloudConfigUpdate(t *testing.T) {
assert.Equal("sc_test/terraform", cloudEntity.ClusterConfig.Placement.Folder)
assert.Equal("spectro-templates", cloudEntity.ClusterConfig.Placement.ImageTemplateFolder)
assert.Equal("ssh-rsa AAAAB3NzaC1y", cloudEntity.ClusterConfig.SSHKeys[0])
assert.Equal("tt.tt.test.com", cloudEntity.ClusterConfig.ControlPlaneEndpoint.Host)
assert.Equal(false, cloudEntity.ClusterConfig.StaticIP)
}

Expand Down

0 comments on commit 17c19c8

Please sign in to comment.