Skip to content

Commit

Permalink
refactor(application): Rename argument names in addPendingResources a…
Browse files Browse the repository at this point in the history
…nd 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 <[email protected]>
  • Loading branch information
gatici committed Jul 25, 2024
1 parent 8897908 commit 749290a
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions internal/juju/applications.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 749290a

Please sign in to comment.