Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: validation during merging node_listen configuration #4881

Merged
merged 3 commits into from
Aug 27, 2021

Conversation

wayne-cheng
Copy link
Contributor

Signed-off-by: wayne-cheng [email protected]
This PR is used to solve a bug found in another PR (#4856).

When the conifg apisix.node_liste is set to a array in the conifg-default.yaml, but the user's config.yaml use the type number,
a error will occur.

More detail, Please see #4856 (comment)

PTAL @spacewander

You can use the existing test cases for testing, since the vaule type of the config apisix.node_listen in the config-default.yaml is changed to the type array.

Pre-submission checklist:

  • Did you explain what problem does this PR solve? Or what new features have been added?
  • Have you added corresponding test cases?
  • Have you modified the corresponding document?
  • Is this PR backward compatible? If it is not backward compatible, please discuss on the mailing list first

Copy link
Member

@spacewander spacewander left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a test in t/cli/test_validate_config.sh?

@wayne-cheng
Copy link
Contributor Author

OK, Please retest. @spacewander


echo '
apisix:
node_listen:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we keep the table in conf/config-default.yaml and use number in config.yaml? Better to avoid touching config-default.yaml in the test.

Copy link
Contributor Author

@wayne-cheng wayne-cheng Aug 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous existing test cases which use number in config.yaml have achieved this goal you said.
Take an example from the file t/cli/test_main.sh:

echo "
apisix:
  node_listen:
    - 9080
    - 9081
    - 9082
  ssl:
    listen_port:
      - 9443
      - 9444
      - 9445
" > conf/config.yaml

make init

This test that I added in t/cli/test_validate_config.sh is used to test the case that the config-default.yaml use number. In fact, the config-default.yaml hasn’t changed because the test case exec git chekout conf/config-default.yaml in the end.
What do you think? @spacewander

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see.

@spacewander spacewander changed the title fix: bug about merge config node_listen fix: validation during merging node_listen configuration Aug 24, 2021
return true
end

if path == "apisix->ssl->listen" and type_val == "number" then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what apisix->ssl->listen it is?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tzssangglass The config apisix.ssl.listen will be used in another PR (#4856). This will not affect the current code, do I remove it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think remove it is better and add it to the PRs that need it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I have removed it, please retest. @tzssangglass

if (ppath == "nginx_config" or str_sub(ppath, 1, 14) == "nginx_config->") and
(type_val == "number" or type_val == "string")
then
local path = ppath == "" and key or ppath .. "->" .. key
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use JSON schema to check it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@membphis The old code has been the schema like ppath .. "->" .. key,and it used to print log. If change this to JSON,many test cases could be affected.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, got it. thx

@spacewander spacewander merged commit b1a9114 into apache:master Aug 27, 2021
@wayne-cheng wayne-cheng deleted the fix-merge-conf branch September 2, 2021 03:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants