* relocated shared libraries from `kraken` to `krkn` folder Signed-off-by: Tullio Sebastiani <tsebasti@redhat.com> * AbstractScenarioPlugin and ScenarioPluginFactory Signed-off-by: Tullio Sebastiani <tsebasti@redhat.com> * application_outage porting Signed-off-by: Tullio Sebastiani <tsebasti@redhat.com> * arcaflow_scenarios porting Signed-off-by: Tullio Sebastiani <tsebasti@redhat.com> * managedcluster_scenarios porting Signed-off-by: Tullio Sebastiani <tsebasti@redhat.com> * network_chaos porting Signed-off-by: Tullio Sebastiani <tsebasti@redhat.com> * node_actions porting Signed-off-by: Tullio Sebastiani <tsebasti@redhat.com> * plugin_scenarios porting Signed-off-by: Tullio Sebastiani <tsebasti@redhat.com> * pvc_scenarios porting Signed-off-by: Tullio Sebastiani <tsebasti@redhat.com> * service_disruption porting Signed-off-by: Tullio Sebastiani <tsebasti@redhat.com> * service_hijacking porting Signed-off-by: Tullio Sebastiani <tsebasti@redhat.com> * cluster_shut_down_scenarios porting Signed-off-by: Tullio Sebastiani <tsebasti@redhat.com> * syn_flood porting Signed-off-by: Tullio Sebastiani <tsebasti@redhat.com> * time_scenarios porting Signed-off-by: Tullio Sebastiani <tsebasti@redhat.com> * zone_outages porting Signed-off-by: Tullio Sebastiani <tsebasti@redhat.com> * ScenarioPluginFactory tests Signed-off-by: Tullio Sebastiani <tsebasti@redhat.com> * unit tests update Signed-off-by: Tullio Sebastiani <tsebasti@redhat.com> * pod_scenarios and post actions deprecated Signed-off-by: Tullio Sebastiani <tsebasti@redhat.com> scenarios post_actions Signed-off-by: Tullio Sebastiani <tsebasti@redhat.com> * funtests and config update Signed-off-by: Tullio Sebastiani <tsebasti@redhat.com> * run_krkn.py update Signed-off-by: Tullio Sebastiani <tsebasti@redhat.com> * utils porting Signed-off-by: Tullio Sebastiani <tsebasti@redhat.com> * API Documentation Signed-off-by: Tullio Sebastiani <tsebasti@redhat.com> * container_scenarios porting Signed-off-by: Tullio Sebastiani <tsebasti@redhat.com> fix Signed-off-by: Tullio Sebastiani <tsebasti@redhat.com> * funtest fix Signed-off-by: Tullio Sebastiani <tsebasti@redhat.com> * document gif update Signed-off-by: Tullio Sebastiani <tsebasti@redhat.com> * Documentation + tests update Signed-off-by: Tullio Sebastiani <tsebasti@redhat.com> * removed example plugin Signed-off-by: Tullio Sebastiani <tsebasti@redhat.com> * global renaming Signed-off-by: Tullio Sebastiani <tsebasti@redhat.com> test fix Signed-off-by: Tullio Sebastiani <tsebasti@redhat.com> test fix Signed-off-by: Tullio Sebastiani <tsebasti@redhat.com> * config.yaml typos Signed-off-by: Tullio Sebastiani <tsebasti@redhat.com> typos Signed-off-by: Tullio Sebastiani <tsebasti@redhat.com> * removed `plugin_scenarios` from NativScenarioPlugin class Signed-off-by: Tullio Sebastiani <tsebasti@redhat.com> * pod_network_scenarios type added Signed-off-by: Tullio Sebastiani <tsebasti@redhat.com> * documentation update Signed-off-by: Tullio Sebastiani <tsebasti@redhat.com> * krkn-lib update Signed-off-by: Tullio Sebastiani <tsebasti@redhat.com> typo Signed-off-by: Tullio Sebastiani <tsebasti@redhat.com> --------- Signed-off-by: Tullio Sebastiani <tsebasti@redhat.com>
6.8 KiB
Scenario Plugin API:
This API enables seamless integration of Scenario Plugins for Krkn. Plugins are automatically
detected and loaded by the plugin loader, provided they extend the AbstractPluginScenario
abstract class, implement the required methods, and adhere to the specified naming conventions.
Plugin folder:
The plugin loader automatically loads plugins found in the krkn/scenario_plugins directory,
relative to the Krkn root folder. Each plugin must reside in its own directory and can consist
of one or more Python files. The entry point for each plugin is a Python class that extends the
AbstractPluginScenario abstract class and implements its required methods.
AbstractPluginScenario abstract class:
This abstract class defines the contract between the plugin and krkn. It consists of two methods:
run(...)get_scenario_type()
Most IDEs can automatically suggest and implement the abstract methods defined in AbstractPluginScenario:
(IntelliJ PyCharm)
run(...)
def run(
self,
run_uuid: str,
scenario: str,
krkn_config: dict[str, any],
lib_telemetry: KrknTelemetryOpenshift,
scenario_telemetry: ScenarioTelemetry,
) -> int:
This method represents the entry point of the plugin and the first method that will be executed.
Parameters:
run_uuid:- the uuid of the chaos run generated by krkn for every single run.
scenario:- the config file of the scenario that is currently executed
krkn_config:- the full dictionary representation of the
config.yaml
- the full dictionary representation of the
lib_telemetry- it is a composite object of all the krkn-lib objects and methods needed by a krkn plugin to run.
scenario_telemetry- the
ScenarioTelemetryobject of the scenario that is currently executed
- the
Return value:
Returns 0 if the scenario succeeds and 1 if it fails.
Warning
All the exception must be handled inside the run method and not propagated.
get_scenario_types():
python def get_scenario_types(self) -> list[str]:
Indicates the scenario types specified in the config.yaml. For the plugin to be properly
loaded, recognized and executed, it must be implemented and must return one or more
strings matching scenario_type strings set in the config.
Warning
Multiple strings can map to a single
ScenarioPluginbut the same string cannot map to different plugins, an exception will be thrown for scenario_type redefinition.
Note
The
scenario_typestrings must be unique across all plugins; otherwise, an exception will be thrown.
Naming conventions:
A key requirement for developing a plugin that will be properly loaded by the plugin loader is following the established naming conventions. These conventions are enforced to maintain a uniform and readable codebase, making it easier to onboard new developers from the community.
plugin folder:
- the plugin folder must be placed in the
krkn/scenario_pluginfolder starting from the krkn root folder - the plugin folder cannot contain the words
pluginscenario
plugin file name and class name:
- the plugin file containing the main plugin class must be named in snake case and must have the suffix
_scenario_plugin:example_scenario_plugin.py
- the main plugin class must named in capital camel case and must have the suffix
ScenarioPlugin:ExampleScenarioPlugin
- the file name must match the class name in the respective syntax:
example_scenario_plugin.py->ExampleScenarioPlugin
scenario type:
- the scenario type must be unique between all the scenarios.
logging:
If your new scenario does not adhere to the naming conventions, an error log will be generated in the Krkn standard output, providing details about the issue:
2024-10-03 18:06:31,136 [INFO] 📣 `ScenarioPluginFactory`: types from config.yaml mapped to respective classes for execution:
2024-10-03 18:06:31,136 [INFO] ✅ type: application_outages_scenarios ➡️ `ApplicationOutageScenarioPlugin`
2024-10-03 18:06:31,136 [INFO] ✅ types: [hog_scenarios, arcaflow_scenario] ➡️ `ArcaflowScenarioPlugin`
2024-10-03 18:06:31,136 [INFO] ✅ type: container_scenarios ➡️ `ContainerScenarioPlugin`
2024-10-03 18:06:31,136 [INFO] ✅ type: managedcluster_scenarios ➡️ `ManagedClusterScenarioPlugin`
2024-10-03 18:06:31,137 [INFO] ✅ types: [pod_disruption_scenarios, pod_network_scenario, vmware_node_scenarios, ibmcloud_node_scenarios] ➡️ `NativeScenarioPlugin`
2024-10-03 18:06:31,137 [INFO] ✅ type: network_chaos_scenarios ➡️ `NetworkChaosScenarioPlugin`
2024-10-03 18:06:31,137 [INFO] ✅ type: node_scenarios ➡️ `NodeActionsScenarioPlugin`
2024-10-03 18:06:31,137 [INFO] ✅ type: pvc_scenarios ➡️ `PvcScenarioPlugin`
2024-10-03 18:06:31,137 [INFO] ✅ type: service_disruption_scenarios ➡️ `ServiceDisruptionScenarioPlugin`
2024-10-03 18:06:31,137 [INFO] ✅ type: service_hijacking_scenarios ➡️ `ServiceHijackingScenarioPlugin`
2024-10-03 18:06:31,137 [INFO] ✅ type: cluster_shut_down_scenarios ➡️ `ShutDownScenarioPlugin`
2024-10-03 18:06:31,137 [INFO] ✅ type: syn_flood_scenarios ➡️ `SynFloodScenarioPlugin`
2024-10-03 18:06:31,137 [INFO] ✅ type: time_scenarios ➡️ `TimeActionsScenarioPlugin`
2024-10-03 18:06:31,137 [INFO] ✅ type: zone_outages_scenarios ➡️ `ZoneOutageScenarioPlugin`
2024-09-18 14:48:41,735 [INFO] Failed to load Scenario Plugins:
2024-09-18 14:48:41,735 [ERROR] ⛔ Class: ExamplePluginScenario Module: krkn.scenario_plugins.example.example_scenario_plugin
2024-09-18 14:48:41,735 [ERROR] ⚠️ scenario plugin class name must start with a capital letter, end with `ScenarioPlugin`, and cannot be just `ScenarioPlugin`.
Note
If you're trying to understand how the scenario types in the config.yaml are mapped to their corresponding plugins, this log will guide you! Each scenario plugin class mentioned can be found in the
krkn/scenario_pluginfolder simply convert the camel case notation and remove the ScenarioPlugin suffix from the class name e.gShutDownScenarioPluginclass can be found in thekrkn/scenario_plugin/shut_downfolder.
ExampleScenarioPlugin
The ExampleScenarioPlugin class included in the tests folder can be used as a scaffolding for new plugins and it is considered part of the documentation.
For any questions or further guidance, feel free to reach out to us on the
Kubernetes workspace in the #krkn channel.
We’re happy to assist. Now, release the Krkn!