Skip to content

Commit

Permalink
[Refactor] Refactor accoring to changes in Gopher
Browse files Browse the repository at this point in the history
  • Loading branch information
muneeb-jan committed Dec 18, 2024
1 parent 71cc77a commit bb47778
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func dataSourceCceAddonTemplateV3Read(_ context.Context, d *schema.ResourceData,
return fmterr.Errorf(cceClientError, err)
}

addonTemplates, err := addons.GetTemplates(client).Extract()
addonTemplates, err := addons.GetTemplates(client)
if err != nil {
return fmterr.Errorf("unable to retrieve templates: %s", err)
}
Expand Down Expand Up @@ -96,7 +96,7 @@ func dataSourceCceAddonTemplateV3Read(_ context.Context, d *schema.ResourceData,
log.Printf("[DEBUG] Retrieved Template using given filter: %s", template.Metadata.Id)
d.SetId(template.Metadata.Id)

inputData := result.Input["basic"].(map[string]interface{})
inputData := result.Input.Basic
mErr := multierror.Append(
d.Set("cluster_ip", inputData["cluster_ip"]),
d.Set("image_version", inputData["image_version"]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func dataSourceCceAddonTemplatesV3Read(_ context.Context, d *schema.ResourceData
return fmterr.Errorf(cceClientError, err)
}

addonTemplates, err := addons.GetTemplates(client).Extract()
addonTemplates, err := addons.GetTemplates(client)
if err != nil {
return fmterr.Errorf("unable to retrieve templates: %s", err)
}
Expand Down Expand Up @@ -141,7 +141,7 @@ func dataSourceCceAddonTemplatesV3Read(_ context.Context, d *schema.ResourceData

result := make([]map[string]interface{}, len(templates))
for i, item := range templates {
inputData := item.Input["basic"].(map[string]interface{})
inputData := item.Input.Basic
addon := map[string]interface{}{
"addon_version": item.Version,
"cluster_ip": inputData["cluster_ip"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func resourceCCEAddonV3Create(ctx context.Context, d *schema.ResourceData, meta
Flavor: flavor,
},
},
}, clusterID).Extract()
}, clusterID)

if err != nil {
errMsg := logHttpError(err)
Expand Down Expand Up @@ -171,7 +171,7 @@ func resourceCCEAddonV3Read(ctx context.Context, d *schema.ResourceData, meta in
}

clusterID := d.Get("cluster_id").(string)
addon, err := addons.Get(client, d.Id(), clusterID).Extract()
addon, err := addons.Get(client, d.Id(), clusterID)
if err != nil {
if _, ok := err.(golangsdk.ErrDefault404); ok {
d.SetId("")
Expand Down Expand Up @@ -228,7 +228,7 @@ func resourceCCEAddonV3Delete(ctx context.Context, d *schema.ResourceData, meta

clusterID := d.Get("cluster_id").(string)

if err := addons.Delete(client, d.Id(), clusterID).ExtractErr(); err != nil {
if err := addons.Delete(client, d.Id(), clusterID); err != nil {
return fmterr.Errorf("error deleting CCE addon : %w", err)
}

Expand All @@ -250,7 +250,7 @@ func resourceCCEAddonV3Delete(ctx context.Context, d *schema.ResourceData, meta
}

func getAddonTemplateSpec(client *golangsdk.ServiceClient, clusterID, templateName string) (string, error) {
templates, err := addons.ListTemplates(client, clusterID, addons.ListOpts{Name: templateName}).Extract()
templates, err := addons.ListTemplates(client, clusterID, addons.ListOpts{Name: templateName})
if err != nil {
return "", err
}
Expand Down Expand Up @@ -300,7 +300,7 @@ func unStringMap(src map[string]interface{}) map[string]interface{} {

func waitForCCEAddonDelete(client *golangsdk.ServiceClient, addonID, clusterID string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
addon, err := addons.Get(client, addonID, clusterID).Extract()
addon, err := addons.Get(client, addonID, clusterID)
if err != nil {
if _, ok := err.(golangsdk.ErrDefault404); ok {
return addon, "deleted", nil
Expand Down Expand Up @@ -328,7 +328,7 @@ func resourceCCEAddonV3Import(_ context.Context, d *schema.ResourceData, meta in
return nil, fmt.Errorf("error creating CCE client: %w", logHttpError(err))
}

addon, err := addons.Get(client, d.Id(), clusterID).Extract()
addon, err := addons.Get(client, d.Id(), clusterID)
if err != nil {
if _, ok := err.(golangsdk.ErrDefault404); ok {
d.SetId("")
Expand All @@ -355,7 +355,7 @@ func resourceCCEAddonV3Import(_ context.Context, d *schema.ResourceData, meta in

func waitForCCEAddonActive(cceAddonClient *golangsdk.ServiceClient, id, clusterID string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
n, err := addons.Get(cceAddonClient, id, clusterID).Extract()
n, err := addons.Get(cceAddonClient, id, clusterID)
if err != nil {
return nil, "", err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ func resourceCCEClusterV3Read(ctx context.Context, d *schema.ResourceData, meta
}
installedAddons := make([]string, len(instances.Items))
for i, instance := range instances.Items {
installedAddons[i] = instance.Metadata.ID
installedAddons[i] = instance.Metadata.Id
}
if err := d.Set("installed_addons", installedAddons); err != nil {
return fmterr.Errorf("error setting installed addons: %w", err)
Expand Down Expand Up @@ -844,7 +844,7 @@ func listInstalledAddons(d *schema.ResourceData, config *cfg.Config) (*addons.Ad
if err != nil {
return nil, fmt.Errorf("error creating CCE Addon client: %w", logHttpError(err))
}
return addons.ListAddonInstances(client, d.Id()).Extract()
return addons.ListAddonInstances(client, d.Id())
}

func waitForInstalledAddons(ctx context.Context, d *schema.ResourceData, config *cfg.Config) error {
Expand Down Expand Up @@ -875,12 +875,12 @@ func removeAddons(ctx context.Context, d *schema.ResourceData, config *cfg.Confi
return fmt.Errorf("error creating CCE Addon client: %w", logHttpError(err))
}

instances, err := addons.ListAddonInstances(client, d.Id()).Extract()
instances, err := addons.ListAddonInstances(client, d.Id())
if err != nil {
return fmt.Errorf("error listing cluster addons: %w", err)
}
for _, addon := range instances.Items {
addonID := addon.Metadata.ID
addonID := addon.Metadata.Id
stateConfAddonReady := &resource.StateChangeConf{
Pending: []string{"installing"},
Target: []string{"running", "available", "abnormal"},
Expand All @@ -895,8 +895,8 @@ func removeAddons(ctx context.Context, d *schema.ResourceData, config *cfg.Confi
}

for _, instance := range instances.Items {
addonID := instance.Metadata.ID
if err := addons.Delete(client, addonID, d.Id()).ExtractErr(); err != nil {
addonID := instance.Metadata.Id
if err := addons.Delete(client, addonID, d.Id()); err != nil {
return fmt.Errorf("error deleting cluster addon %s/%s: %w", d.Id(), addonID, err)
}
}
Expand All @@ -919,7 +919,7 @@ func removeAddons(ctx context.Context, d *schema.ResourceData, config *cfg.Confi

func waitForCCEClusterAddonsState(client *golangsdk.ServiceClient, clusterID string) resource.StateRefreshFunc {
return func() (r interface{}, s string, err error) {
instances, err := addons.ListAddonInstances(client, clusterID).Extract()
instances, err := addons.ListAddonInstances(client, clusterID)
if err != nil {
return nil, "", fmt.Errorf("error listing cluster addons: %w", err)
}
Expand All @@ -932,7 +932,7 @@ func waitForCCEClusterAddonsState(client *golangsdk.ServiceClient, clusterID str

func waitForCCEClusterAddonActive(client *golangsdk.ServiceClient, id, clusterID string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
n, err := addons.Get(client, id, clusterID).Extract()
n, err := addons.Get(client, id, clusterID)
if err != nil {
return nil, "", err
}
Expand Down

0 comments on commit bb47778

Please sign in to comment.