3

Following the Quarkus Rest Client tutorial I need to add something similar to this to the application.properties file:

country-api/mp-rest/url=https://restcountries.eu/rest

With Docker it works and I can pass the property value by parameter:

docker run -it --privileged --rm --env country-api/mp-rest/url="https://restcountries.eu/rest" mydockerhost/my-project:SNAPSHOT

The YAML file for Kubernetes looks like this:

apiVersion: "apps/v1"
kind: "Deployment"
metadata:
  labels:
    app.kubernetes.io/name: "my-project"
    app.kubernetes.io/version: "SNAPSHOT"
  name: "my-project-deployment"
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: "my-project"
      app.kubernetes.io/version: "SNAPSHOT"
  template:
    metadata:
      labels:
        app.kubernetes.io/name: "my-project"
        app.kubernetes.io/version: "SNAPSHOT"
    spec:
      containers:
      - env:
        - name: "country-api/mp-rest/url"
          value: "https://restcountries.eu/rest"

However the following error is occurring when executing the command kubectl apply -f my-projetc.yaml

The Deployment "my-project-deployment" is invalid: * spec.template.spec.containers[0].env[1].name: Invalid value: "country-api/mp-rest/url": a valid environment variable name must consist of alphabetic characters, digits, '_', '-', or '.', and must not start with a digit (e.g. 'my.env-name', or 'MY_ENV.NAME', or 'MyEnvName1', regex used for validation is '[-._a-zA-Z][-._a-zA-Z0-9]*')

Quarkus version: 1.3.1.Final

Emerson
  • 428
  • 5
  • 16

1 Answers1

7

You can use environment variables in application.properties so you could do something like:

country-api/mp-rest/url=${MY_SERVICE_URL}

and define MY_SERVICE_URL in your Yaml file.

Also, MicroProfile Config has a way to work around your issue. Using COUNTRY_API_MP_REST_URL as an environment variable should work (uppercase everything, replace anything non alphanumeric with _).

Guillaume Smet
  • 9,921
  • 22
  • 29
  • I named the environment variable replacing "/" to "_" and it worked. I noticed that Quarkus kubernetes extension had already changed "-" to "_" in MP-REST, it only needed to replace the slash. – Emerson Apr 03 '20 at 18:35
  • 1
    so how does your final ENV Variable look like now? – Ross Brigoli Jun 16 '21 at 08:10