carvel-dev / ytt

YAML templating tool that works on YAML structure instead of text
https://carvel.dev/ytt
Apache License 2.0
1.68k stars 137 forks source link

Add resource to each namespace #738

Closed mamachanko closed 2 years ago

mamachanko commented 2 years ago

Describe the problem/challenge you have Specifically, I would like to add a resource to all namespace. For that I must be able to set the resources .metadata.name, but its not known.

What I have so far:

#@overlay/match by=overlay.subset({"kind": "Namespace"}), expects="0+"
#@overlay/insert after=True
---
kind: Thing
metadata:
  name: the-thing
  namespace: ?

To be more specific given

#! stuffs.yaml
---
apiVersion: v1
kind: Namespace
metadata:
  name: one
---
apiVersion: v1
kind: Namespace
metadata:
  name: two

want

ytt -f stuffs.yaml -f magic.yaml
---
apiVersion: v1
kind: Namespace
metadata:
  name: one
---
kind: Thing
metadata:
  name: thing
  namespace: one
---
apiVersion: v1
kind: Namespace
metadata:
  name: two
---
kind: Thing
metadata:
  name: thing
  namespace: two

Describe the solution you'd like

Of course, there's a general pattern here, but I am expressing this as the specific use case mentioned ^.

Anything else you would like to add: According to our Slack conversation, this is not easily done yet.


Vote on this request

This is an invitation to the community to vote on issues, to help us prioritize our backlog. Use the "smiley face" up to the right of this comment to vote.

👍 "I would like to see this addressed as soon as possible" 👎 "There are other more important things to focus on right now"

We are also happy to receive and review Pull Requests if you want to help working on this issue.

pivotaljohn commented 2 years ago

Note: the solution to this is likely to also resolve #718

pivotaljohn commented 2 years ago

We've seen multiple situations where a user would love to accept an entire document as an input into a template that results in a new document. Since this is a mere extension of the existing semantics of overlays (i.e. implementing what it means to insert or append a document), this seems like a fine addition the the feature set.