From 45a81c8b7558f6b52ceffec730623a7ea63ca628 Mon Sep 17 00:00:00 2001 From: ShuangxueWu Date: Thu, 7 Mar 2024 16:56:07 +0800 Subject: [PATCH 1/2] fix:extend call plugin api timeout Signed-off-by: ShuangxueWu --- kubespider/core/plugin_manager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kubespider/core/plugin_manager.py b/kubespider/core/plugin_manager.py index a4ddbbaf..f6e07493 100644 --- a/kubespider/core/plugin_manager.py +++ b/kubespider/core/plugin_manager.py @@ -151,7 +151,7 @@ def call_api(self, api: str, **kwargs): **kwargs } response = self.request.post( - url=f"http://localhost:{port}", json=body, timeout=1) + url=f"http://localhost:{port}", json=body, timeout=30) if response.status_code != 200: raise Exception( f"Failed to call plugin API: {api}") From bc765ceda0692c5a135add91acdc0c69ba6d9f9d Mon Sep 17 00:00:00 2001 From: ShuangxueWu Date: Thu, 7 Mar 2024 17:10:04 +0800 Subject: [PATCH 2/2] feat: plugin api add up status --- kubespider/api/v2/plugin/views.py | 4 +++- kubespider/core/plugin_manager.py | 8 +++++++- sdk/example/Dockerfile | 5 ----- 3 files changed, 10 insertions(+), 7 deletions(-) delete mode 100644 sdk/example/Dockerfile diff --git a/kubespider/api/v2/plugin/views.py b/kubespider/api/v2/plugin/views.py index 46a490dc..2996c89e 100644 --- a/kubespider/api/v2/plugin/views.py +++ b/kubespider/api/v2/plugin/views.py @@ -8,7 +8,9 @@ @plugin_blu.route('', methods=['GET']) def list_plugin_handler(): plugins = plugin_manager.kubespider_plugin_manager.list_plugin() - return success([plugin.to_dict() for plugin in plugins]) + instances = plugin_manager.kubespider_plugin_manager.list_instance() + instance_plugin = [instance.definition.name for instance in instances] + return success([dict(plugin.to_dict(), **{"up": plugin.name in instance_plugin}) for plugin in plugins]) @plugin_blu.route('', methods=['PUT']) diff --git a/kubespider/core/plugin_manager.py b/kubespider/core/plugin_manager.py index f6e07493..934b5aab 100644 --- a/kubespider/core/plugin_manager.py +++ b/kubespider/core/plugin_manager.py @@ -200,6 +200,9 @@ def __init__(self): def list_plugin(self) -> list[PluginDefinition]: return self.definitions.values() + def list_instance(self) -> list[PluginInstance]: + return self.instances.values() + def get_plugin(self, plugin_name: str) -> PluginDefinition: return self.definitions.get(plugin_name) @@ -255,7 +258,10 @@ def unregister(self, plugin_name: str): definition = self.definitions.get(plugin_name) if not definition: raise Exception(f"Plugin not found: {plugin_name}") - self.disable(plugin_name) + # Disable the plugin if it is enabled + if self.instances.get(plugin_name): + self.disable(plugin_name) + # Remove the plugin definition and binary del self.definitions[plugin_name] os.remove(PLUGIN_DEFINITION_PATH + plugin_name + ".yaml") os.remove(PLUGIN_BINARY_PATH + plugin_name) diff --git a/sdk/example/Dockerfile b/sdk/example/Dockerfile deleted file mode 100644 index 58d9d0d3..00000000 --- a/sdk/example/Dockerfile +++ /dev/null @@ -1,5 +0,0 @@ -FROM kubespider_source_provider_sdk:latest - -WORKDIR /build - -CMD ./build.sh