# Merge lists in optionalValues

**URL:** https://community.replicated.com/t/merge-lists-in-optionalvalues/1284
**Category:** How do I?
**Tags:** kots, replicated-classic
**Created:** [August 22, 2023, 4:10pm UTC](https://community.replicated.com/t/merge-lists-in-optionalvalues/1284 "2023-08-22T16:10:57Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Lukasz\_Werenkowicz](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.replicated.com/lukasz_werenkowicz/32/694_2.png) [@Lukasz\_Werenkowicz](https://community.replicated.com/u/Lukasz_Werenkowicz)
#### Post date: [August 22, 2023, 4:10pm UTC](https://community.replicated.com/t/merge-lists-in-optionalvalues/1284/1 "2023-08-22T16:10:57Z")

</div>

hi team! Is it possible to recursively merge lists in optionalValues ? Or maybe there is another mechanizm I can use instead?  
eg

```auto
    - when: <CONDITIOAN A>
      recursiveMerge: true
      values:
        config:
          navLinks:
            - label: "App1"
              url: 'url1'

    - when: <CONDITIOAN B>
      recursiveMerge: true
      values:
        config:
          navLinks:
            - label: "App2"
              url: 'url2'
    - when: <CONDITIOAN C>
      recursiveMerge: true
      values:
        config:
          navLinks:
            - label: "App3"
              url: 'url3'

```

the expected result (if all conditions true):  
config:

```auto
          navLinks:
            - label: "App1"
              url: 'url1'
            - label: "App2"
              url: 'url2'    
            - label: "App3" 
              url: 'url3'

```

I’m looking for a way to build a list based on a set of conditions and pass as helm value. Thanks!

---

<div class="post-metadata">

### Author: ![craig](https://avatars.discourse-cdn.com/v4/letter/c/ed8c4c/32.png) [@craig](https://community.replicated.com/u/craig)
#### Post date: [August 22, 2023, 8:11pm UTC](https://community.replicated.com/t/merge-lists-in-optionalvalues/1284/2 "2023-08-22T20:11:19Z")

</div>

Hi @Lukasz_Werenkowicz, I don’t believe this is possible today with optional values that are arrays, though it does seem like a reasonable feature request. Let me see if I can find a workaround for you in the meantime and I’ll share it here.

---

<div class="post-metadata">

### Author: ![craig](https://avatars.discourse-cdn.com/v4/letter/c/ed8c4c/32.png) [@craig](https://community.replicated.com/u/craig)
#### Post date: [August 22, 2023, 8:38pm UTC](https://community.replicated.com/t/merge-lists-in-optionalvalues/1284/3 "2023-08-22T20:38:25Z")

</div>

Certainly not the cleanest, but here is a potential workaround that might get you the resulting values that you are looking for. If you do find a cleaner solution, please do share it here.

In this case, I define some config items that are of type `bool`. These will represent the conditionals for each of the nav items you want to render out. Additionally I’ve also added some `hidden` config items that contain the resulting yaml that I want rendered for each.

```yaml
    - name: app_1_enabled
      title: Enable App 1
      type: bool
    - name: app_1_nav_value
      title: App 1 Nav Value
      type: text
      hidden: true
      value: |
        - name: "App1"
          url: "url1"
    - name: app_2_enabled
      title: Enable App 2
      type: bool
    - name: app_2_nav_value
      title: App 2 Nav Value
      type: text
      hidden: true
      value: |
        - name: "App2"
          url: "url2"

```

In the `HelmChart` custom resource, you can use the the `ConfigOption` combined with `nindent` to render each value accordingly.

```yaml
values:
  config:
    navLinks: repl{{ if ConfigOptionEquals "app_1_enabled" "1" }}repl{{ ConfigOption "app_1_nav_value" | nindent 6 }}repl{{ end }}repl{{ if ConfigOptionEquals "app_2_enabled" "1" }}repl{{ ConfigOption "app_2_nav_value" | nindent 6 }}repl{{ end }}

```

This would result in the following values if both checkboxes were selected by the user:

```yaml
config:
  navLinks:
  - name: App1
    url: url1
  - name: App2
    url: url2

```

---

<div class="post-metadata">

### Author: ![Lukasz\_Werenkowicz](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.replicated.com/lukasz_werenkowicz/32/694_2.png) [@Lukasz\_Werenkowicz](https://community.replicated.com/u/Lukasz_Werenkowicz)
#### Post date: [August 23, 2023, 11:34am UTC](https://community.replicated.com/t/merge-lists-in-optionalvalues/1284/4 "2023-08-23T11:34:40Z")

</div>

Thank you, @craig!  
The workaround works very well.  
As for now, I only have 3 items in my list (but each condition contains 2 checks) so, the code is still maintainable… but with more variables it may be problematic.

Having and additional param to control the merge strategy would be a really nice feature. Thanks!
