<p>Background : I have close to 15 *.properties files in different location. I need to create configmap for each properties files. </p>

<p>Currently I am manually creating configmap yaml files using </p>

<pre><code> kubectl create configmap app-properties --from-file= /path/app.properties.
</code></pre>

<p>Mount and everything thing is working fine. </p>

<p>Requirement : As soon we add any new key/value to properties file, it should get reflected in configmap yaml file. Can I dynamically create configmap yaml using some "include files". </p>

pythonhmmm
<p>You could watch the properties files for modifications and recreate the ConfigMap whenever they change.</p>

<p>To do so, there are different tools for macOS and Linux.</p>

<h2>Linux</h2>

<p>On Linux, you can watch files for changes with <code>inotifywait</code>. You could do something along the following lines:</p>

<p>Create the file <code>monitor.sh</code>:</p>

<pre class="lang-sh prettyprint-override"><code>#!/bin/bash

FILE=$1
inotifywait -m -e modify "$FILE" |
  while read; do
    kubectl create configmap "$(basename $FILE)" --from-file="$FILE" --dry-run -o yaml | kubectl apply -f -
  done
</code></pre>

<p>Then execute it for each properties file:</p>

<pre class="lang-sh prettyprint-override"><code>./monitor.sh /path/app.properties
</code></pre>

<p>This will generate an updated ConfigMap YAML manifest with <code>kubectl create</code> and apply it with <code>kubectl apply</code> every time the <code>/path/app.properties</code> file is modified.</p>

<p>You can install <code>inotifywait</code> with:</p>

<pre class="lang-sh prettyprint-override"><code>sudo apt-get install inotify-tools
</code></pre>

<h2>macOS</h2>

<p>On macOS, you can use <code>fswatch</code> to watch for file modifications.</p>

<p>Create the file <code>monitor.sh</code>:</p>

<pre class="lang-sh prettyprint-override"><code>#!/bin/bash

FILE=$1
fswatch "$FILE" |
  while read; do
    kubectl create configmap "$(basename $FILE)" --from-file="$FILE" --dry-run -o yaml | kubectl apply -f -
  done
</code></pre>

<p>Then execute it for each properties file:</p>

<pre class="lang-sh prettyprint-override"><code>./monitor.sh /path/app.properties
</code></pre>

<p>This will generate an updated ConfigMap YAML manifest with <code>kubectl create</code> and apply it with <code>kubectl apply</code> every time the <code>/path/app.properties</code> file is modified.</p>

<p>You can install <code>fswatch</code> with:</p>

<pre class="lang-sh prettyprint-override"><code>brew install fswatch
</code></pre>

<h2>Note</h2>

<p><code>fswatch</code> might also be available on Linux (<code>sudo apt-get install fswatch</code>), in which case you can use the <code>monitor.sh</code> script for macOS on Linux too. However, you might need to use <code>fswatch -o</code> (with the <code>-o</code> option) to ensure only a single output line.</p>
