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

PLT-1279:Fixed VSphere cluster day 2 operation on control plane node p… #480

Merged
merged 3 commits into from
Jul 5, 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
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
Loading