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

Reference Data in Data Values #882

Closed
antwacky opened this issue Nov 21, 2023 · 3 comments
Closed

Reference Data in Data Values #882

antwacky opened this issue Nov 21, 2023 · 3 comments
Assignees
Labels
discussion This issue is not a bug or feature and a conversation is needed to find an appropriate resolution

Comments

@antwacky
Copy link

I know there is a work around for this, however I don't think it fits my particular use case very nicely, and wondering if there's a better solution.

So consider my schema:

environment: development
domain: localhost

apps:
  - name: app1
    mountFiles:
      - name: app-config
        mountPath: /app/config.json
        content: |
          environment: #@ data.values.environment
          url: #@ "https://app1-{}".format(data.values.domain)

Then in a deployment template:

#@ for file in app.mountFiles:
- mountPath: #@ file.mountPath
   name: #@ file.name.split('.')[0]
   subPath: #@ file.name
#@ end

I can then mount files to the various application deployments with variable content as needed. Obviously, this isn't possible, as it is not possible to use data values within a data values file.

If I were to use a function, then this gets messy, quickly, as I then have to put the file content in a lib/function, and then I have to put the mountPath somewhere seperate.

For example, I then will have a lib:

#@ def getApp1Config():
environment: #@ data.values.environment
url: #@ "https://app1-{}".format(data.values.domain)
#@ end

And my deployment becomes:

#@ if app.name == "app1":
- mountPath: /app/config.json
   name: config
   subPath: config.json
#@ end

Clearly this is not nice at all, and inflexible. How is it recommended to handle this situation?

Thanks

@antwacky antwacky added the carvel triage This issue has not yet been triaged for relevance label Nov 21, 2023
@prembhaskal
Copy link
Member

Will check today.

@prembhaskal prembhaskal self-assigned this Dec 5, 2023
@prembhaskal
Copy link
Member

prembhaskal commented Dec 5, 2023

sorry for delay.
I think you can achieve what you want in 2 steps.

cat schema-values.yml.
note here we are making use of https://carvel.dev/ytt/#example:example-text-template

#@ load("@ytt:data", "data")

---
environment: development
domain: localhost

apps:
  - name: app1
    mountFiles:
      - name: app-config
        mountPath: /app/config.json
        #@yaml/text-templated-strings
        content: |
          environment: (@= data.values.environment @)
          url: (@= "https://app1-{}".format(data.values.domain) @)
      - name: app-config
        mountPath: /app/config.json
        #@yaml/text-templated-strings
        content: |
          environment: (@= data.values.environment @)
          url: (@= "https://app2-{}".format(data.values.domain) @)

cat values.yml

#@data/values
---
domain: somedomain
environment: someenv

cat deployment.yml

#@ load("@ytt:data", "data")

#@ apps = data.values.apps

---
topnode:
  #@ for app in apps:
    #@ for file in app.mountFiles:
     - mountPath: #@ file.mountPath
       name: #@ file.name.split('.')[0]
       subPath: #@ file.name
    #@ end
  #@ end

and do 2 step ytt to achieve what you want.
first ytt to generate the actual values and
2nd ytt to generate the final deployment

 % ytt -f values.yml -f schema-values.yml | ytt --data-values-file - -f deployment.yml
topnode:
- mountPath: /app/config.json
  name: app-config
  subPath: app-config
- mountPath: /app/config.json
  name: app-config
  subPath: app-config

@prembhaskal prembhaskal added discussion This issue is not a bug or feature and a conversation is needed to find an appropriate resolution and removed carvel triage This issue has not yet been triaged for relevance labels Dec 5, 2023
@antwacky
Copy link
Author

antwacky commented Dec 7, 2023

Thanks!

@antwacky antwacky closed this as completed Dec 7, 2023
@github-project-automation github-project-automation bot moved this to Closed in Carvel Dec 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion This issue is not a bug or feature and a conversation is needed to find an appropriate resolution
Projects
Archived in project
Development

No branches or pull requests

2 participants