How to create a configmap which references the .JS file containing the MongoDB commands?

Viewed 62

In Detail, the .JS file contains MongoDB commands like below,

db = db.getSiblingDB('records')
db.createCollection("collection_new");
db.collection_new.insertMany([
  { capped : true, size : 5242880, max : 5000 },
  { capped : false, size : 5242880, max : 8000 },
  { capped : false, size : 5242880, max : 5000 },
  { capped : true, size : 5242880, max : 8000 }
 ])

Now, instead of converting this .JS file into a standalone .yaml configmap file, I want to create a configmap which refers to the .JS file. Also, I do not want to add the raw data inside the configmap because the above commands are just a small part of the JS file. The main file contains approx. 400-500 lines.

1 Answers

You cannot make reference to a file from a configmap. As suggested in the comments, you can use an Helm template which make reference to a file:

apiVersion: v1
kind: ConfigMap
metadata:
  name: my-configmap
data:
  mongo-commands.js: |-
    {{ .Files.Get "js/mongo_commands.js" }}

Note that:

  • The directory js is at the root of the Helm chart.
  • Charts must be smaller than 1M because of the storage limitations of Kubernetes objects.
  • Files in templates/ cannot be accessed.
  • Files excluded using .helmignore cannot be accessed.
Related