From 749290a3aea33027ff5c58eca012a7bde4493429 Mon Sep 17 00:00:00 2001 From: gatici Date: Wed, 24 Jul 2024 15:49:26 +0300 Subject: [PATCH] refactor(application): Rename argument names in addPendingResources and processResources functions This commit renames the arguments in two functions as existing arguments does not identify the correct resource types withing this change.: - func processResources: - resources -> resourcesToUse Argument "resources" are too generic and it is renamed to resourcesToUse. - In addPendingResources: - resourcesToBeAdded -> charmResources resourcesToBeAdded indicates the resources which are available in the charm.Hence charmResources are used to indicate this map. - resourcesRevisions -> resourcesToUse resourceRevisions does not cover the OCI resources, however this map could include resource revisions from CharmHub and custom OCI images. Signed-off-by: gatici --- internal/juju/applications.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/internal/juju/applications.go b/internal/juju/applications.go index 788beb04..338bad13 100644 --- a/internal/juju/applications.go +++ b/internal/juju/applications.go @@ -741,14 +741,14 @@ func splitCommaDelimitedList(list string) []string { // processResources is a helper function to process the charm // metadata and request the download of any additional resource. -func (c applicationsClient) processResources(charmsAPIClient *apicharms.Client, conn api.Connection, charmID apiapplication.CharmID, appName string, resources map[string]string) (map[string]string, error) { +func (c applicationsClient) processResources(charmsAPIClient *apicharms.Client, conn api.Connection, charmID apiapplication.CharmID, appName string, resourcesToUse map[string]string) (map[string]string, error) { charmInfo, err := charmsAPIClient.CharmInfo(charmID.URL) if err != nil { return nil, typedError(err) } // check if we have resources to request - if len(charmInfo.Meta.Resources) == 0 && len(resources) == 0 { + if len(charmInfo.Meta.Resources) == 0 && len(resourcesToUse) == 0 { return nil, nil } @@ -757,7 +757,7 @@ func (c applicationsClient) processResources(charmsAPIClient *apicharms.Client, return nil, err } - return addPendingResources(appName, charmInfo.Meta.Resources, resources, charmID, resourcesAPIClient) + return addPendingResources(appName, charmInfo.Meta.Resources, resourcesToUse, charmID, resourcesAPIClient) } // ReadApplicationWithRetryOnNotFound calls ReadApplication until @@ -1452,14 +1452,14 @@ func (c applicationsClient) updateResources(appName string, resources map[string return addPendingResources(appName, filtered, resources, charmID, resourcesAPIClient) } -func addPendingResources(appName string, resourcesToBeAdded map[string]charmresources.Meta, resourcesRevisions map[string]string, +func addPendingResources(appName string, charmResources map[string]charmresources.Meta, resourcesToUse map[string]string, charmID apiapplication.CharmID, resourcesAPIClient ResourceAPIClient) (map[string]string, error) { pendingResourcesforAdd := []charmresources.Resource{} toReturn := map[string]string{} - for _, resourceMeta := range resourcesToBeAdded { - if resourcesRevisions != nil { - if deployValue, ok := resourcesRevisions[resourceMeta.Name]; ok { + for _, resourceMeta := range charmResources { + if resourcesToUse != nil { + if deployValue, ok := resourcesToUse[resourceMeta.Name]; ok { if isInt(deployValue) { // A resource revision is provided providedRev, err := strconv.Atoi(deployValue)