Skip to content

Commit

Permalink
feat: Mount ConfigMaps as a Volume. (#69)
Browse files Browse the repository at this point in the history
* feat: Mount ConfigMaps as a Volume.

* This is the recommended way of using/accessing a config map.

Note that even though we don't have to redeploy the pod to get the new config map changes, it does take a few seconds for them to show up

Also downgrade the version of winston to 2.4.4
  • Loading branch information
lholmquist authored Nov 16, 2018
1 parent 0a2281d commit c50465d
Show file tree
Hide file tree
Showing 10 changed files with 1,405 additions and 2,314 deletions.
20 changes: 19 additions & 1 deletion .nodeshift/deployment.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
spec:
template:
spec:
# Declare a volume mounting the config map
volumes:
- configMap:
# Name of the config map
name: app-config
optional: true
# Define the items from the config map to mount
items:
- key: app-config.yml
path: app-config.yml
# Volume name (used as reference below)
name: config
containers:
- readinessProbe:
- env:
- name: NODE_CONFIGMAP_PATH
value: /app/config/app-config.yml
readinessProbe:
httpGet:
path: /api/health/readiness
port: 8080
Expand All @@ -14,3 +29,6 @@ spec:
scheme: HTTP
initialDelaySeconds: 60
periodSeconds: 30
volumeMounts:
- mountPath: /app/config
name: config
15 changes: 14 additions & 1 deletion .openshiftio/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,18 @@ objects:
spec:
template:
spec:
volumes:
- configMap:
name: app-config
items:
- key: "app-config.yml"
path: "app-config.yml"
name: config
containers:
- readinessProbe:
- env:
- name: NODE_CONFIGMAP_PATH
value: /app/config/app-config.yml
readinessProbe:
httpGet:
path: /api/health/readiness
port: 8080
Expand All @@ -121,6 +131,9 @@ objects:
name: nodejs-configmap
securityContext:
privileged: false
volumeMounts:
- name: config
mountPath: /app/config
ports:
- containerPort: 8080
name: http
Expand Down
21 changes: 8 additions & 13 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@
*/

const path = require('path');
const fs = require('fs');
const {promisify} = require('util');
const express = require('express');
const bodyParser = require('body-parser');

const readFile = promisify(fs.readFile);
// Setup logging
const logger = require('winston');

Expand Down Expand Up @@ -78,23 +82,14 @@ setInterval(() => {
}, 2000);

// Get ConfigMap Stuff
const openshiftRestClient = require('openshift-rest-client');
const jsyaml = require('js-yaml');

// Find the Config Map
function retrieveConfigfMap () {
const settings = {
request: {
strictSSL: false
}
};

return openshiftRestClient(settings).then(client => {
const configMapName = 'app-config';
return client.configmaps.find(configMapName).then(configMap => {
const configMapParsed = jsyaml.safeLoad(configMap.data['app-config.yml']);
return configMapParsed;
});
return readFile(process.env.NODE_CONFIGMAP_PATH, {encoding: 'utf8'}).then(configMap => {
// Parse the configMap, which is yaml
const configMapParsed = jsyaml.safeLoad(configMap);
return configMapParsed;
});
}

Expand Down
19 changes: 0 additions & 19 deletions licenses/DEBUG_MIT.TXT

This file was deleted.

190 changes: 0 additions & 190 deletions licenses/LICENSE-REPORTER_APACHE-2.0.TXT

This file was deleted.

16 changes: 1 addition & 15 deletions licenses/licenses.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ <h2>nodejs-configmap</h2>
</tr>
<tr>
<td>N/A</td>
<td>debug</td>
<td>4.0.1</td>
<td>http:&#x2F;&#x2F;www.opensource.org&#x2F;licenses&#x2F;MIT</td>
<td><a href=DEBUG_MIT.TXT>DEBUG_MIT.TXT</a></td>
</tr>
<tr>
<td>N/A</td>
<td>express</td>
<td>4.16.0</td>
<td>http:&#x2F;&#x2F;www.opensource.org&#x2F;licenses&#x2F;MIT</td>
Expand All @@ -43,15 +36,8 @@ <h2>nodejs-configmap</h2>
</tr>
<tr>
<td>N/A</td>
<td>license-reporter</td>
<td>1.2.0</td>
<td>http:&#x2F;&#x2F;www.apache.org&#x2F;licenses&#x2F;LICENSE-2.0</td>
<td><a href=LICENSE-REPORTER_APACHE-2.0.TXT>LICENSE-REPORTER_APACHE-2.0.TXT</a></td>
</tr>
<tr>
<td>N/A</td>
<td>winston</td>
<td>3.0.0</td>
<td>2.4.4</td>
<td>http:&#x2F;&#x2F;www.opensource.org&#x2F;licenses&#x2F;MIT</td>
<td><a href=WINSTON_MIT.TXT>WINSTON_MIT.TXT</a></td>
</tr>
Expand Down
22 changes: 1 addition & 21 deletions licenses/licenses.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,6 @@
</license>
</licenses>
</dependency>
<dependency>
<packageName>debug</packageName>
<version>4.0.1</version>
<licenses>
<license>
<name>MIT License</name>
<url>http://www.opensource.org/licenses/MIT</url>
</license>
</licenses>
</dependency>
<dependency>
<packageName>express</packageName>
<version>4.16.0</version>
Expand All @@ -44,19 +34,9 @@
</license>
</licenses>
</dependency>
<dependency>
<packageName>license-reporter</packageName>
<version>1.2.0</version>
<licenses>
<license>
<name>Apache License 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0</url>
</license>
</licenses>
</dependency>
<dependency>
<packageName>winston</packageName>
<version>3.0.0</version>
<version>2.4.4</version>
<licenses>
<license>
<name>MIT License</name>
Expand Down
Loading

0 comments on commit c50465d

Please sign in to comment.