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

feat(plugin config): add dependency for delete plugin config #6092

Merged
merged 8 commits into from
Jan 18, 2022
Merged

feat(plugin config): add dependency for delete plugin config #6092

merged 8 commits into from
Jan 18, 2022

Conversation

zaunist
Copy link
Contributor

@zaunist zaunist commented Jan 13, 2022

What this PR does / why we need it:

fix #5917

When a plugin config is referencing by any route, it should not be deleted.

example:

create plugin config:

curl http://127.0.0.1:9180/apisix/admin/plugin_configs/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d '
{                                                                                                                                                                                                         
    "desc": "吾乃插件配置1",                                                                                                                                                                              
    "plugins": {                                                                                                                                                                                          
        "limit-count": {                                                                                                                                                                                  
            "count": 2,                                                                                                                                                                                   
            "time_window": 60,                                                                                                                                                                            
            "rejected_code": 503                                                                                                                                                                          
        }                                                                                            
    }                                                                                                                                                                                                     
}' 

bounding route to plugin config:

curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d '
{
    "uris": ["/index.html"],
    "plugin_config_id": 1,
    "upstream": {
        "type": "roundrobin",
        "nodes": {
            "39.97.63.215:80": 1
        }
    }
}'

Then, delete plugin config, apisix will return 400 error.

▶ curl -X DELETE http://127.0.0.1:9080/apisix/admin/plugin_configs/1  -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1'
{"error_msg":"can not delete this plugin config, route [1] is still using it now"}

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

@zaunist zaunist marked this pull request as ready for review January 16, 2022 10:16
@zaunist
Copy link
Contributor Author

zaunist commented Jan 16, 2022

cc @tzssangglass

@@ -0,0 +1,174 @@
#
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 add it to t/admin/plugin-configs.t?

Copy link
Member

Choose a reason for hiding this comment

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

We should not add more new delete-* files. For example, the new case in #4575 is added in proto3.t.
I also submit a PR to remove the stale cases: #6121

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it.

}
}
}]],
[[{
Copy link
Member

Choose a reason for hiding this comment

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

We don't need to check the response in every test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it.

end

local routes, routes_ver = get_routes()
core.log.info("routes: ", core.json.delay_encode(routes, true))
Copy link
Member

Choose a reason for hiding this comment

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

Is it necessary to dump all the routes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did it with reference to the processing of upstream. At the same time, I also considered whether to logging all route information. If it is not log here, does it also need to be modified in upstream?

core.log.info("routes: ", core.json.delay_encode(routes, true))

Copy link
Member

Choose a reason for hiding this comment

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

As the size of Nginx log is limited, we can't log all the routes. Let's remove it.

@zaunist zaunist requested a review from spacewander January 17, 2022 03:00
end

local routes, routes_ver = get_routes()
core.log.info("routes: ", core.json.delay_encode(routes, true))
Copy link
Member

Choose a reason for hiding this comment

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

As the size of Nginx log is limited, we can't log all the routes. Let's remove it.

ngx.say(body)
}
}
--- request
Copy link
Member

Choose a reason for hiding this comment

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

We can remove the duplicate sections which are set in the beginning.

GET /t
--- response_body
passed
--- no_error_log
Copy link
Member

Choose a reason for hiding this comment

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

Ditto

Copy link
Member

@bisakhmondal bisakhmondal left a comment

Choose a reason for hiding this comment

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

lgtm%nits

--- config
location /t {
content_by_lua_block {
ngx.sleep(0.3)
Copy link
Member

Choose a reason for hiding this comment

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

Hi, is there any reason for which we need to add this 0.3-sec sleep?
Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The current step depends on the previous steps, so set a short time for etcd to sync data.

--- config
location /t {
content_by_lua_block {
ngx.sleep(0.3)
Copy link
Member

Choose a reason for hiding this comment

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

ditto

--- config
location /t {
content_by_lua_block {
ngx.sleep(0.3)
Copy link
Member

Choose a reason for hiding this comment

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

ditto

@zaunist zaunist requested a review from spacewander January 17, 2022 06:40
@spacewander
Copy link
Member

I found the CI is broken with msg:

nginx: [emerg] "listen" directive is not allowed here in /home/runner/work/apisix/apisix/t/servroot/conf/nginx.conf:202

https://github.com/apache/apisix/runs/4836910403?check_suite_focus=true

@zaunist
Copy link
Contributor Author

zaunist commented Jan 17, 2022

I found the CI is broken with msg:

nginx: [emerg] "listen" directive is not allowed here in /home/runner/work/apisix/apisix/t/servroot/conf/nginx.conf:202

https://github.com/apache/apisix/runs/4836910403?check_suite_focus=true

Thanks for your careful, but I don't know how to slove this problem. Any one can help me to do this ?

@spacewander
Copy link
Member

Usually, it is because of a malformed config section. Could you check the t/servroot/conf/nginx.conf?

@zaunist
Copy link
Contributor Author

zaunist commented Jan 18, 2022

Usually, it is because of a malformed config section. Could you check the t/servroot/conf/nginx.conf?

Got it, and CI passed now.

@spacewander spacewander merged commit 3773f26 into apache:master Jan 18, 2022
@zaunist zaunist deleted the feat/delete_plugin_dependency branch January 18, 2022 07:01
@zaunist zaunist mentioned this pull request Jan 19, 2022
4 tasks
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.

bug: APISIX did not check whether it was referenced when deleting PluginConfig
5 participants