Create configmap from existing file #277
-
Hi there, is there a way to use ytt to create a config map from an existing file, e.g. like so: configmap.yaml ---
apiVersion: v1
kind: ConfigMap
metadata:
name: renovate-config
namespace: renovate
annotations:
kapp.k14s.io/versioned: ""
kapp.k14s.io/num-versions: "10"
data:
config.js: <✨magically import config.js here ✨> config.js module.exports = {
platform: "gitlab",
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi! 👋 From what I gather, you're looking for a way to import a JS file into a YAML file. There's a (probably not what you want) way of simply importing the file as a string, which can be done with the #@ load("@ytt:data", "data")
---
apiVersion: v1
kind: ConfigMap
metadata:
name: renovate-config
namespace: renovate
annotations:
kapp.k14s.io/versioned: ""
kapp.k14s.io/num-versions: "10"
data:
config.js: #@ data.read("config.js") Resulting in: apiVersion: v1
kind: ConfigMap
metadata:
name: renovate-config
namespace: renovate
annotations:
kapp.k14s.io/versioned: ""
kapp.k14s.io/num-versions: "10"
data:
config.js: |-
module.exports = {
platform: "gitlab",
} What I think is more likely though, you're asking how to get the values of that JS object into the YAML map. To do that, you'll need to export the object as JSON (with JSON.stringify), then ytt can decode it with #@ load("@ytt:data", "data")
#@ load("@ytt:json", "json")
---
apiVersion: v1
kind: ConfigMap
metadata:
name: renovate-config
namespace: renovate
annotations:
kapp.k14s.io/versioned: ""
kapp.k14s.io/num-versions: "10"
data:
config.js: #@ json.decode(data.read("config.json"))["exports"] config.json {"exports":{"platform":"gitlab"}} which results in: apiVersion: v1
kind: ConfigMap
metadata:
name: renovate-config
namespace: renovate
annotations:
kapp.k14s.io/versioned: ""
kapp.k14s.io/num-versions: "10"
data:
config.js:
platform: gitlab |
Beta Was this translation helpful? Give feedback.
Hi! 👋
From what I gather, you're looking for a way to import a JS file into a YAML file.
There's a (probably not what you want) way of simply importing the file as a string, which can be done with the
data.read
function.Resulting in: