You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2022/03/03 15:40:31 UTC

[GitHub] [apisix] wilson-1024 opened a new pull request #6505: feat: support for reading environment variables from yaml configuration files #5244

wilson-1024 opened a new pull request #6505:
URL: https://github.com/apache/apisix/pull/6505


   
   ### What this PR does / why we need it:
   <!--- Why is this change required? What problem does it solve? -->
   <!--- If it fixes an open issue, please link to the issue here. -->
   Support for reading environment variables from yaml configuration files.
   
   resolve https://github.com/apache/apisix/issues/5244
   ### Pre-submission checklist:
   
   <!--
   Please follow the PR manners:
   1. Use Draft if the PR is not ready to be reviewed
   2. Test is required for the feat/fix PR, unless you have a good reason
   3. Doc is required for the feat PR
   4. Use a new commit to resolve review instead of `push -f`
   5. If you need to resolve merge conflicts after the PR is reviewed, please merge master but do not rebase
   6. Use "request review" to notify the reviewer once you have resolved the review
   7. Only reviewer can click "Resolve conversation" to mark the reviewer's review resolved
   -->
   
   * [x] Did you explain what problem does this PR solve? Or what new features have been added?
   * [x] Have you added corresponding test cases?
   * [x] Have you modified the corresponding document?
   * [ ] Is this PR backward compatible? **If it is not backward compatible, please discuss on the [mailing list](https://github.com/apache/apisix/tree/master#community) first**
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] spacewander merged pull request #6505: feat: support for reading environment variables from yaml configuration files #5244

Posted by GitBox <gi...@apache.org>.
spacewander merged pull request #6505:
URL: https://github.com/apache/apisix/pull/6505


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] spacewander commented on a change in pull request #6505: feat: support for reading environment variables from yaml configuration files #5244

Posted by GitBox <gi...@apache.org>.
spacewander commented on a change in pull request #6505:
URL: https://github.com/apache/apisix/pull/6505#discussion_r819310976



##########
File path: t/cli/test_yaml_config_variables.sh
##########
@@ -0,0 +1,70 @@
+#!/usr/bin/env bash
+
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+. ./t/cli/common.sh
+
+# check supported environment variables in apisix.yaml
+
+yaml_config_variables_clean_up() {
+    git checkout conf/config.yaml

Review comment:
       We can use the original clean up like:
   https://github.com/apache/apisix/blob/380f762f30fb845893c1f46393c4de6e57b808a6/t/cli/test_serverless.sh#L21-L25

##########
File path: apisix/cli/file.lua
##########
@@ -234,6 +237,20 @@ function _M.read_yaml_conf(apisix_home)
         end
     end
 
+    if default_conf.apisix.config_center == "yaml" then

Review comment:
       Can we put this in apisix/core/config_yaml.lua?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] wilson-1024 commented on a change in pull request #6505: feat: support for reading environment variables from yaml configuration files #5244

Posted by GitBox <gi...@apache.org>.
wilson-1024 commented on a change in pull request #6505:
URL: https://github.com/apache/apisix/pull/6505#discussion_r819564535



##########
File path: t/cli/test_yaml_config_variables.sh
##########
@@ -0,0 +1,70 @@
+#!/usr/bin/env bash
+
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+. ./t/cli/common.sh
+
+# check supported environment variables in apisix.yaml
+
+yaml_config_variables_clean_up() {
+    git checkout conf/config.yaml

Review comment:
       Fixed. Please review it again.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] wilson-1024 commented on a change in pull request #6505: feat: support for reading environment variables from yaml configuration files #5244

Posted by GitBox <gi...@apache.org>.
wilson-1024 commented on a change in pull request #6505:
URL: https://github.com/apache/apisix/pull/6505#discussion_r819565071



##########
File path: apisix/cli/file.lua
##########
@@ -234,6 +237,20 @@ function _M.read_yaml_conf(apisix_home)
         end
     end
 
+    if default_conf.apisix.config_center == "yaml" then

Review comment:
       At first I wanted to put this in apisix/core/config_yaml.lua, but because the file loads ngx variables, it needs to be loaded in the openresty environment. Can't run in CLI mode, so we can't put this in apisix/core/config_yaml.lua




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] wilson-1024 commented on pull request #6505: feat: support for reading environment variables from yaml configuration files #5244

Posted by GitBox <gi...@apache.org>.
wilson-1024 commented on pull request #6505:
URL: https://github.com/apache/apisix/pull/6505#issuecomment-1059952349


   @spacewander @tokers Test file renamed.Please review it again.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] spacewander commented on a change in pull request #6505: feat: support for reading environment variables from yaml configuration files #5244

Posted by GitBox <gi...@apache.org>.
spacewander commented on a change in pull request #6505:
URL: https://github.com/apache/apisix/pull/6505#discussion_r820220524



##########
File path: t/cli/test_yaml_config_variables.sh
##########
@@ -0,0 +1,68 @@
+#!/usr/bin/env bash

Review comment:
       Let's rename it to test_standalone.sh, so it can be used in other places later.

##########
File path: t/cli/test_yaml_config_variables.sh
##########
@@ -0,0 +1,68 @@
+#!/usr/bin/env bash
+
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+. ./t/cli/common.sh
+
+# check supported environment variables in apisix.yaml
+
+yaml_config_variables_clean_up() {

Review comment:
       And so.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] tzssangglass commented on a change in pull request #6505: feat: support for reading environment variables from yaml configuration files #5244

Posted by GitBox <gi...@apache.org>.
tzssangglass commented on a change in pull request #6505:
URL: https://github.com/apache/apisix/pull/6505#discussion_r820352908



##########
File path: t/cli/test_standalone.sh
##########
@@ -0,0 +1,67 @@
+#!/usr/bin/env bash
+
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+. ./t/cli/common.sh
+
+standalone() {
+    clean_up
+    git checkout conf/apisix.yaml
+}
+
+trap standalone EXIT
+
+# support environment variables
+echo '
+apisix:
+  enable_admin: false
+  config_center: yaml
+' > conf/config.yaml
+
+echo '
+routes:
+  -
+    uri: ${{var_test_path}}
+    plugins:
+      proxy-rewrite:
+        uri: ${{var_test_proxy_rewrite_uri:=/apisix/nginx_status}}
+    upstream:
+      nodes:
+        "127.0.0.1:9091": 1
+      type: roundrobin
+#END
+' > conf/apisix.yaml
+
+# check for resolve variables
+var_test_path=/test make init
+
+if ! grep "env var_test_path=/test;" conf/nginx.conf > /dev/null; then
+    echo "failed: failed to resolve variables"
+    exit 1
+fi
+
+# variable is valid
+var_test_path=/test make run
+sleep 0.1
+code=$(curl -o /dev/null -s -m 5 -w %{http_code} http://127.0.0.1:9080/test)
+if [ ! $code -eq 200 ]; then
+    echo "failed: variable is not valid"

Review comment:
       ```suggestion
       echo "failed: esolve variables in apisix.yaml conf failed"
   ```
   
   is better?

##########
File path: t/cli/test_standalone.sh
##########
@@ -0,0 +1,67 @@
+#!/usr/bin/env bash
+
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+. ./t/cli/common.sh
+
+standalone() {
+    clean_up
+    git checkout conf/apisix.yaml
+}
+
+trap standalone EXIT
+
+# support environment variables
+echo '
+apisix:
+  enable_admin: false
+  config_center: yaml
+' > conf/config.yaml
+
+echo '
+routes:
+  -
+    uri: ${{var_test_path}}
+    plugins:
+      proxy-rewrite:
+        uri: ${{var_test_proxy_rewrite_uri:=/apisix/nginx_status}}
+    upstream:
+      nodes:
+        "127.0.0.1:9091": 1
+      type: roundrobin
+#END
+' > conf/apisix.yaml
+
+# check for resolve variables
+var_test_path=/test make init
+
+if ! grep "env var_test_path=/test;" conf/nginx.conf > /dev/null; then
+    echo "failed: failed to resolve variables"
+    exit 1
+fi
+
+# variable is valid
+var_test_path=/test make run
+sleep 0.1
+code=$(curl -o /dev/null -s -m 5 -w %{http_code} http://127.0.0.1:9080/test)
+if [ ! $code -eq 200 ]; then
+    echo "failed: variable is not valid"
+    exit 1
+fi
+
+echo "passed: resolve variables"

Review comment:
       ```suggestion
   echo "passed: resolve variables in apisix.yaml conf success"
   ```
   
   is better?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] wilson-1024 commented on a change in pull request #6505: feat: support for reading environment variables from yaml configuration files #5244

Posted by GitBox <gi...@apache.org>.
wilson-1024 commented on a change in pull request #6505:
URL: https://github.com/apache/apisix/pull/6505#discussion_r820225347



##########
File path: t/cli/test_yaml_config_variables.sh
##########
@@ -0,0 +1,68 @@
+#!/usr/bin/env bash
+
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+. ./t/cli/common.sh
+
+# check supported environment variables in apisix.yaml
+
+yaml_config_variables_clean_up() {

Review comment:
       OK. Thank you for your patient guidance




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org