Skip to content

Commit

Permalink
PLT-1279:Fixed VSphere cluster day 2 operation on control plane node …
Browse files Browse the repository at this point in the history
…p… (#480)

* PLT-1279:Fixed vsphere cluster day 2 operation on controlplane node pool.

* lint fix

* Fixed - description field is not getting populated/synced when running cluster import is done (#481)
  • Loading branch information
SivaanandM authored Jul 5, 2024
1 parent 93046a6 commit bf35f56
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 29 deletions.
38 changes: 38 additions & 0 deletions spectrocloud/cluster_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ func flattenCommonAttributeForClusterImport(c *client.V1Client, d *schema.Resour
return err
}

if cluster.Metadata.Annotations["description"] != "" {
if err := d.Set("description", cluster.Metadata.Annotations["description"]); err != nil {
return err
}
}

if cluster.Status.SpcApply != nil {
err = d.Set("apply_setting", cluster.Status.SpcApply.ActionType)
if err != nil {
Expand Down Expand Up @@ -196,3 +202,35 @@ func flattenCommonAttributeForClusterImport(c *client.V1Client, d *schema.Resour
}
return nil
}

func GetCommonCluster(d *schema.ResourceData, c *client.V1Client) error {
// parse resource ID and scope
scope, clusterID, err := ParseResourceID(d)
if err != nil {
return err
}

// Use the IDs to retrieve the cluster data from the API
cluster, err := c.GetCluster(scope, clusterID)
if err != nil {
return fmt.Errorf("unable to retrieve cluster data: %s", err)
}
if cluster != nil {
err = d.Set("name", cluster.Metadata.Name)
if err != nil {
return err
}
err = d.Set("context", cluster.Metadata.Annotations["scope"])
if err != nil {
return err
}

// Set the ID of the resource in the state. This ID is used to track the
// resource and must be set in the state during the import.
d.SetId(clusterID)
} else {
return fmt.Errorf("couldn’t find cluster. Kindly check the cluster UID and context")
}

return nil
}
28 changes: 0 additions & 28 deletions spectrocloud/resource_cluster_edge_native_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,34 +34,6 @@ func resourceClusterEdgeNativeImport(ctx context.Context, d *schema.ResourceData
return []*schema.ResourceData{d}, nil
}

func GetCommonCluster(d *schema.ResourceData, c *client.V1Client) error {
// parse resource ID and scope
scope, clusterID, err := ParseResourceID(d)
if err != nil {
return err
}

// Use the IDs to retrieve the cluster data from the API
cluster, err := c.GetCluster(scope, clusterID)
if err != nil {
return fmt.Errorf("unable to retrieve cluster data: %s", err)
}

err = d.Set("name", cluster.Metadata.Name)
if err != nil {
return err
}
err = d.Set("context", cluster.Metadata.Annotations["scope"])
if err != nil {
return err
}

// Set the ID of the resource in the state. This ID is used to track the
// resource and must be set in the state during the import.
d.SetId(clusterID)
return nil
}

func ParseResourceID(d *schema.ResourceData) (string, string, error) {
// d.Id() will contain the ID of the resource to import. This ID is provided by the user
// during the import command, and should be parsed to find the existing resource.
Expand Down
7 changes: 6 additions & 1 deletion spectrocloud/resource_cluster_vsphere.go
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,12 @@ func resourceClusterVsphereUpdate(ctx context.Context, d *schema.ResourceData, m
p.UID = oldPlacements[i].UID
}
}

// PEM-5013 For day 2 operation hubble is expecting datacenter and folder in machine pool even though TF maintain in cloud config
if machinePool.PoolConfig.IsControlPlane {
cConfig := d.Get("cloud_config").([]interface{})[0].(map[string]interface{})
machinePool.CloudConfig.Placements[0].Datacenter = cConfig["datacenter"].(string)
machinePool.CloudConfig.Placements[0].Folder = cConfig["folder"].(string)
}
err = c.UpdateMachinePoolVsphere(cloudConfigId, ClusterContext, machinePool)
// Node Maintenance Actions
err := resourceNodeAction(c, ctx, nsMap[name], c.GetNodeMaintenanceStatusVsphere, CloudConfig.Kind, ClusterContext, cloudConfigId, name)
Expand Down

0 comments on commit bf35f56

Please sign in to comment.