0

I am new to helm charts and have a problem in getting a key from a list. I am trying to parse the following structure:

operation:map[initiatedBy:map[username:admin] retry:map[] sync:map[resources:[map[group:apps kind:Deployment name:dev-refresh-service namespace:dev-apps]]

I am able to get the value of username inside the initiatedBy key using: {{.operation.initiatedBy.username}}

However I am not able to get the value for the name key from inside the list - resources

I am using the following syntax: {{ operation.sync.resources.name }}

Following is the error I get: can't evaluate field name in type interface {}

Any way around for this?? I am not really sure is this a helm issue or golang issue

Thanks in advance

user517696
  • 2,472
  • 7
  • 24
  • 35
  • try {{ operation.sync.resources[0].name }} – taleodor May 04 '21 at 12:36
  • @taleodor Getting a new error: ```msg="Failed to parse new settings: template: app-sync-succeeded:1: bad character U+005B '['"``` – user517696 May 04 '21 at 12:38
  • 2
    Actually look at this SO - https://stackoverflow.com/questions/52682621/how-to-access-value-of-first-index-of-array-in-go-templates - if you play around a bit, should get it done; essentially looks like the issue is that resources is an array in your case, so you need 1st element of that – taleodor May 04 '21 at 12:43
  • @taleodor Will give it a try. Thank you :) – user517696 May 04 '21 at 12:44
  • 1
    @taleodor It worked bro. Thanks a ton for this :) – user517696 May 04 '21 at 12:47

1 Answers1

-1

The most common reason I have found for this error in Helm is that there is no key in the Values.yaml

You are probably looking for something like (assuming that operation.sync.resources.name currently has no value)

operation:
  sync:
    resources:
      name: {}

Note: I have not filled out the entire structure of operation: This can also happen if the values are for a sub-chart, in which case the top of that structure should begin with the chart name