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 a4ddbbaf..934b5aab 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}") @@ -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