Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use overlay annotation with plain yaml objects #839

Closed
Hugal31 opened this issue May 25, 2023 · 2 comments
Closed

How to use overlay annotation with plain yaml objects #839

Hugal31 opened this issue May 25, 2023 · 2 comments

Comments

@Hugal31
Copy link
Contributor

Hugal31 commented May 25, 2023

My goal is to have overlayed data/values that result in a dictionary of objects. Then, I apply an operation to replace missing fields in each of those sub-objects by a default object, also defined in the overlayed data/values. It works well, however I can't specify the usual overlay annotations, as #@overlay/replace for the arrays.

I have those two files:

test.values.yaml

#@ load("@ytt:overlay", "overlay")
#@data/values
#@overlay/match-child-defaults missing_ok=True
---
root:
  default:
    x: 1
    'y': 2
    array: [300, 400]

  high:
    x: 5
    array: [600]

  low:
    'y': -1

and test.yaml:

#@ load("@ytt:data", "data")
#@ load("@ytt:overlay", "overlay")
#@ default = data.values.root.default
root: #@ {k: overlay.apply(default, v) for k, v in dict(data.values.root).items() if k != "default"}

The result :

root:
  high:
    x: 5
    "y": 2
    array:
    # Here the items are appended
    - 300
    - 400
    - 600
  low:
    x: 1
    "y": -1
    array:
    - 300
    - 400

Expected result:

root:
  high:
    x: 5
    "y": 2
    array:
    - 600
  low:
    x: 1
    "y": -1
    array:
    - 300
    - 400

How can I achieve this?

@Hugal31 Hugal31 added the carvel triage This issue has not yet been triaged for relevance label May 25, 2023
@vmunishwar
Copy link
Contributor

@Hugal31 Hi, sorry for the late reply. Just curious, do you still need help to resolve this issue or you found a workaround? Kindly let us know. Thanks

@Hugal31
Copy link
Contributor Author

Hugal31 commented Jun 14, 2023

Yes, but I had to create my own overlay function. Since I was only merging on one level, this was easy:

def merge(left, right):
    result = dict(left)
    for k, v in dict(right).items():
        result[k] = v
    end
    return result
end

Edit: I think using overlay for this kind of task is not doable. The overlay annotation are consumed by the first overlay application (when merging my *.values.yaml). I'll close the issue.

@Hugal31 Hugal31 closed this as completed Jun 14, 2023
@github-actions github-actions bot removed the carvel triage This issue has not yet been triaged for relevance label Jun 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

2 participants