Not able to read int values from Kubernetese config maps

1.1k views Asked by At

I am trying to deploy a springboot application on kubernetese. I have stored all environment variable in config map and trying to read value from there. There are certain properties where we need to read int values.

In our code, it looks something like this :

application.properties :

TOKEN_RETRY_COUNT=3

As we have to read it from ConfigMap, we have updated our application.properties as mentioned below:

Update application.properties :

TOKEN_RETRY_COUNT=${STARGATE_TOKEN_RETRY_LIMIT}

Config Maps

The values are configured are like this in the Config Maps. I had to put double quotes as it wasn't allowed without any quote.

"STARGATE_TOKEN_RETRY_LIMIT": "3",

Now, when I am trying to read these values after deploying it on kubernetese, I am getting below error :

For STARGATE_TOKEN_RETRY_LIMIT :

Failed to convert value of type 'java.lang.String' to required type 'int'; nested exception is java.lang.NumberFormatException: For input string: "STARGATE_TOKEN_RETRY_LIMIT"

For now, I had updated code to take this value as String and then parse it as int but this is not ideal way. There should be some standard way to take different types.

If we can't handle different type in Config Maps, then what what would be ideal way to pass different application properties for Springboot application on kubernetese ?

1

There are 1 answers

0
Mafor On BEST ANSWER

I don't think the issue is related to the property value (3) being specified as a string ("3"). If you read the error message carefully you will see that the NumberFormatException is caused by an attempt to parse STARGATE_TOKEN_RETRY_LIMIT (literally) to a an int. Probably there is something wrong with the way the config map is passed to the application/container.