Code Monkey home page Code Monkey logo

Comments (6)

ahmsay avatar ahmsay commented on August 23, 2024 1

A lifecycle hook would work for me. Thanks for the clarification.

from charts.

jotamartos avatar jotamartos commented on August 23, 2024

Hi @ahmsay,

The default config we mount in the container already includes the usage of env variables, did you take a look at that? As you can see here, we are exporting the APISIX_ADMIN_API_TOKEN env var in the init container that takes care of rendering the configuration. That env var is not used later in the apisix container.

https://github.com/bitnami/charts/blob/main/bitnami/apisix/templates/_helpers.tpl#L357
https://github.com/bitnami/charts/blob/main/bitnami/apisix/values.yaml#L1104

You will need to modify the extraEnvVars parameter to be able to mount that env var during that step so the configuration is updated.

from charts.

ahmsay avatar ahmsay commented on August 23, 2024

Hello @jotamartos,

What step are you referring to?

I am following this page: https://artifacthub.io/packages/helm/bitnami/apisix#additional-environment-variables

Neither extraEnvVars nor extraEnvVarsSecret are working as expected. This time i tried on my local device. I can see the environment variables inside the container when i type env. And I have an environment variable called CLIENT_SECRET that is meant to be injected in my apisix.yaml file. But i have an error and it says that the environment variable is not found (as mentioned above).

Please note that I don't have an error when i use the official image with the same configuration.

from charts.

jotamartos avatar jotamartos commented on August 23, 2024

Hi @ahmsay

What step are you referring to?

I did a quick test to include a new parameter in the configuration based on the env var and everything worked as expected. I made these changes in the dataPlane object

diff --git a/bitnami/apisix/values.yaml b/bitnami/apisix/values.yaml
index 6918ae517b..0fb56c4e65 100644
--- a/bitnami/apisix/values.yaml
+++ b/bitnami/apisix/values.yaml
@@ -343,6 +343,8 @@ dataPlane:
           token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
 
         default_weight: 50 # weight assigned to each discovered endpoint. default 50, minimum 0
+    # Testing line
+    # new-parameter: "{{ print "{{NEW_APISIX_ENV_VAR}}" }}"
   ## @param dataPlane.extraConfig [object] extra configuration parameters to add to the config.yaml file in APISIX Data plane
   ##
   extraConfig: {}
@@ -468,7 +470,9 @@ dataPlane:
   ##   - name: FOO
   ##     value: "bar"
   ##
-  extraEnvVars: []
+  extraEnvVars:
+    - name: NEW_APISIX_ENV_VAR
+      value: "new-value"
   ## @param dataPlane.extraEnvVarsCM Name of existing ConfigMap containing extra env vars for APISIX nodes
   ##
   extraEnvVarsCM: ""

and deployed the chart. Once all pods were running, I confirmed that the new parameter was added to the configuration and it used the env var value I configured

➜  apisix git:(main) k exec -it apisix-data-plane-79d784b689-cbxz5 -- env | grep -i new                      
Defaulted container "apisix" out of: apisix, wait-for-control-plane (init), prepare-apisix (init)
NEW_APISIX_ENV_VAR=new-value
➜  apisix git:(main) k exec -it apisix-data-plane-79d784b689-cbxz5 -- tail /usr/local/apisix/conf/config.yaml
Defaulted container "apisix" out of: apisix, wait-for-control-plane (init), prepare-apisix (init)
      # apiserver host, options [ipv4, ipv6, domain, environment variable]
      host: ${KUBERNETES_SERVICE_HOST} #default ${KUBERNETES_SERVICE_HOST}
      # apiserver port, options [port number, environment variable]
      port: ${KUBERNETES_SERVICE_PORT} #default ${KUBERNETES_SERVICE_PORT}
    client:
      # serviceaccount token or token_file
      token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
    default_weight: 50 # weight assigned to each discovered endpoint. default 50, minimum 0
# Testing line
# new-parameter: "new-value"

As you can see, I modified the configuration using the dataPlane.defaultConfig parameter, but you can also mount your own config map and the prepare-apisix init container will take care of evaluating the configuration and creating the necessary files in the system.

from charts.

ahmsay avatar ahmsay commented on August 23, 2024

Hello @jotamartos ,

In your example you modified the config.yaml file. I am trying to modify the apisix.yaml file. I also noticed that after I run apisix reload command inside the container the error is gone.

Is there a way to automate this in the helm chart definition, like a post-start lifecycle hook?

from charts.

jotamartos avatar jotamartos commented on August 23, 2024

You can mount your apisix.yaml file and make any necessary change in a new initContainer, similar to the changes that I mentioned above. That way, once the container is running, the configuration is the one you expect and do not need to run that extra command. Would that work for you?

As you mention, you can also try setting a lifecycle hook

https://github.com/bitnami/charts/blob/main/bitnami/apisix/templates/control-plane/dep-ds.yaml#L170

from charts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.