If I have a java configuration bean, saying:
package com.mycompany.app.configuration;
// whatever imports
public class MyConfiguration {
private String someConfigurationValue = "defaultValue";
// getters and setters etc
}
If I set that using jetty for local testing I can do so using a config.xml
file in the following form:
<myConfiguration class="com.mycompany.app.configuration.MyConfiguration" context="SomeContextAttribute">
<someConfigurationValue>http://localhost:8080</someConfigurationValue>
</myConfiguration>
However in the deployed environment in which I need to test, I will need to use docker to set these configuration values, we use jboss.
Is there a way to directly set these JNDI values? I’ve been looking for examples for quite a while but cannot find any. This would be in the context of a yaml file which is used to configure a k8 cluster. Apologies for the psuedocode, I would post the real code but it’s all proprietary so I can’t.
What I have so far for the overrides.yaml
snippet is of the form:
env:
'MyConfig.SomeContextAttribute':
class_name: 'com.mycompany.app.configuration.MyConfiguration'
someConfigurationValue: 'http://localhost:8080'
However this is a complete guess.
2
Answers
The way to do this is as follows:
If you are attempting to set a value that looks like this in terms of fully qualified name:
Then that will look like the following in a yaml file:
It really is that simple. It does need to be set as an environment variable in the yaml, but I'm not sure whether it needs to be under
env:
or if that's specific to us.I don't think there's a way of setting something in YAML that in XML would be an attribute, however. I've tried figuring that part out, but I haven't been able to.
You can achieve it by using ConfigMap.
First what you need to create
ConfigMap
from your file using command as below:Where
<map-name>
is the name you want to assign to theConfigMap
and<data-source>
is the directory, file, or literal value to draw the data from. You can read more about it here.Here is an example:
You can check what is inside this file using
cat
command:You will see that there are some variables in this file:
ConfigMap
from this file:You should see output that
ConfigMap
has been created:You can display details of the
ConfigMap
using command below:You will see output as below:
You can also see how
yaml
of thisConfigMap
will look using:The output will be similar:
Next goal is connecting
ConfigMap
toPod
. It could be added in yaml file ofPod
configuration.As you can see under
containers
there isenvFrom
section. Asname
is a name ofConfigMap
which I created in previous step. You can read aboutenvFrom
hereCreate a
Pod
from yaml file using:Final step is checking environment variables in this
Pod
using below command:As you can see below, there are environment variables from simple file which I downloaded in the first step: