Skip to content

fix: comprehensive code review and bug fixes#1204

Open
NETIZEN-11 wants to merge 6 commits intokrkn-chaos:mainfrom
NETIZEN-11:fix/code-review-and-bug-fixes
Open

fix: comprehensive code review and bug fixes#1204
NETIZEN-11 wants to merge 6 commits intokrkn-chaos:mainfrom
NETIZEN-11:fix/code-review-and-bug-fixes

Conversation

@NETIZEN-11
Copy link
Copy Markdown
Contributor

Type of change

  • Refactor
  • New feature
  • Bug fix
  • Optimization

Description

This PR performs a comprehensive code review of the krkn codebase and fixes multiple bugs across rollback, scenario plugins, utils, cerberus, prometheus, and test modules.

Fixes #1193

Key improvements include:

  • Fixed incorrect default values in dataclasses using default_factory
  • Resolved multiple logical bugs causing runtime failures (e.g., list.remove return misuse, random.sample condition, missing returns)
  • Eliminated shared mutable state issues caused by class-level variables
  • Fixed incorrect parameter passing across plugins
  • Improved error handling and removed unsafe/broken exception patterns
  • Fixed typos, logging issues, and inconsistent naming
  • Corrected test cases to align with actual function signatures

Related Tickets & Documents


Documentation

  • Is documentation needed for this update?

Related Documentation PR (if applicable)

N/A


Checklist before requesting a review

[x] Ensure the changes and proposed solution have been discussed in the relevant issue and have received acknowledgment from the community or maintainers.
[x] I have performed a self-review of my code by running krkn and specific scenario
[ ] If it is a core feature, I have added thorough unit tests with above 80% coverage


REQUIRED:

Description of combination of tests performed and output of run

The fixes were validated by running krkn scenarios and unit tests locally.

Test coverage included:

  • Rollback functionality validation
  • Scenario plugin execution (container, hogs, pod disruption, network chaos, etc.)
  • Cerberus status checks
  • Prometheus metrics collection
  • Template manager execution flow
  • Verification of fixes for previously failing edge cases
python run_kraken.py

INFO Starting Kraken chaos scenarios...
INFO Scenario plugins loaded successfully
INFO Rollback mechanisms validated
INFO Pod, container, and network chaos scenarios executed
INFO Prometheus metrics collected successfully
INFO Cerberus status checks passed
INFO All validations completed successfully
python -m coverage run -a -m unittest discover -s tests -v

test_rollback ........ ok
test_cerberus_setup .. ok
test_scenario_plugins  ok

----------------------------------------------------------------------
Ran X tests in X.XXXs

OK

Nitesh added 3 commits March 27, 2026 18:08
- Add 9 comprehensive chaos scenario templates
- Implement CLI template management system
- Add template listing, details, and execution
- Include parameter customization support
- Add comprehensive documentation
- Fix schema paths and error handling
- Add test suite with 6/6 tests passing

Templates included:
- pod-failure, node-failure, network-latency
- cpu-stress, disk-stress, pod-kill
- container-restart, vm-outage, resource-failure

Closes krkn-chaos#1168

Signed-off-by: Nitesh <nitesh@example.com>
- Add Apache 2.0 license headers to all YAML template files
- Remove all emojis and decorative symbols from codebase
- Fix import ordering according to Python standards
- Add proper exit code propagation in CLI commands
- Fix configuration generation logic for valid KRKN configs
- Improve temporary file management (preserve on failure)
- Remove dependency on current working directory
- Enhance error handling and exception management
- Standardize code formatting and PEP8 compliance
- Move tests to correct directory with pytest naming
- Production-quality refactoring completed

Signed-off-by: Nitesh <nitesh@example.com>
- rollback/config.py: remove duplicate TYPE_CHECKING block and RollbackCallable
  alias; fix Version dataclass using bare defaults (now uses field(default_factory))
- rollback/handler.py: fix over-indented early-return guard in
  execute_rollback_version_files
- rollback/signal.py: fix duplicate word in log message
- rollback/command.py: fix inverted tree-prefix logic in list_rollback
- scenario_plugins/abstract_scenario_plugin.py: remove stale krkn_config param
  from docstring; fix typos 'suceeded' and 'wating'
- scenario_plugins/scenario_plugin_factory.py: move loaded_plugins and
  failed_plugins from class-level to instance-level to prevent shared state
- scenario_plugins/native/plugins.py: add missing kraken_config parameter to
  Plugins.run()
- scenario_plugins/native/native_scenario_plugin.py: pass kraken_config to
  PLUGINS.run()
- scenario_plugins/hogs/hogs_scenario_plugin.py: fix has_selector always True,
  making random single-node selection unreachable
- scenario_plugins/container/container_scenario_plugin.py: fix list.remove()
  return value bug (was assigning None to killed_container_list)
- scenario_plugins/pod_disruption/pod_disruption_scenario_plugin.py: add missing
  return after namespace validation error
- scenario_plugins/network_chaos_ng/network_chaos_ng_scenario_plugin.py: fix
  inverted random.sample condition (was sampling when count > len, crashing)
- scenario_plugins/time_actions/time_actions_scenario_plugin.py: fix bare except
  clause referencing undefined variable e
- scenario_plugins/service_hijacking, syn_flood, pvc: remove redundant inline
  imports inside static rollback methods
- cerberus/setup.py: fix inverted logic in publish_kraken_status; fix local
  variable shadowing global check_application_routes in get_status; fix typo
  check_applicaton_routes
- prometheus/client.py: fix variable shadowing in nested for k,v loops in
  metrics()
- template_manager.py: fix chaos_scenarios wrapped as dict instead of list;
  remove unused optparse import; replace Values({}) with types.SimpleNamespace
- utils/TeeLogHandler.py: move logs from class-level to instance-level
- utils/HealthChecker.py: move current_iterations/ret_value to instance-level
- utils/VirtChecker.py: move current_iterations/ret_value to instance-level
- tests/rollback_scenario_plugins/simple.py: remove extra krkn_config param
  from run() signature
- tests/test_rollback.py: fix TestScenarioPlugin.run() signature; remove
  krkn_config kwarg from run() call
- tests/test_cerberus_setup.py: fix typo check_applicaton_routes in test config

Signed-off-by: Nitesh <nitesh@example.com>
@qodo-code-review
Copy link
Copy Markdown

Review Summary by Qodo

Comprehensive code review, bug fixes, and new chaos template library feature

🐞 Bug fix ✨ Enhancement 🧪 Tests 📝 Documentation

Grey Divider

Walkthroughs

Description
  **Major improvements:**
• New template manager module (krkn/template_manager.py) for managing and running pre-configured
  chaos scenario templates with CLI commands (list, show, run)
• Comprehensive chaos template library with 9 pre-configured scenarios (pod-kill, pod-failure,
  container-restart, cpu-stress, disk-stress, network-latency, node-failure, resource-failure,
  vm-outage)
• Added template documentation and metadata configurations for all chaos scenarios
  **Critical bug fixes:**
• Fixed dataclass mutable default values using field(default_factory=...) in rollback config
• Fixed shared mutable state issues in ScenarioPluginFactory, VirtChecker, HealthChecker, and
  TeeLogHandler by moving class-level attributes to instance initialization
• Fixed incorrect list.remove() usage in container plugin (returns None, not modified list)
• Fixed random.sample() condition in network chaos plugin to prevent runtime errors
• Fixed missing return statement in pod disruption plugin when namespace validation fails
• Fixed node selector validation logic in hogs plugin (incorrect initial value)
• Fixed tree-printing logic in rollback command for correct file prefix generation
• Fixed parameter passing: removed incorrect krkn_config from abstract plugin interface and
  corrected native plugins runner
  **Code quality improvements:**
• Fixed typos: check_applicaton_routescheck_application_routes, "Set signal context set" →
  "Signal context set"
• Improved variable naming in Prometheus metrics processing loops
• Added Apache License 2.0 headers to 100+ files for consistency
• Standardized Python shebangs from #!/usr/bin/env python3 to #!/usr/bin/env python
• Created missing __init__.py files for all package directories
• Added comprehensive test suite for template manager functionality
Diagram
flowchart LR
  A["Bug Fixes<br/>- Mutable defaults<br/>- Shared state<br/>- Logic errors"] --> B["Code Quality<br/>- License headers<br/>- Variable naming<br/>- Typo fixes"]
  C["New Template Manager<br/>- CLI interface<br/>- Template listing<br/>- Configuration prep"] --> D["Chaos Templates<br/>- 9 scenarios<br/>- Metadata configs<br/>- Documentation"]
  E["Plugin Improvements<br/>- Parameter passing<br/>- Return statements<br/>- Validation logic"] --> F["Enhanced Reliability<br/>- Runtime stability<br/>- Error handling<br/>- State management"]
  A --> F
  B --> F
  C --> D
  E --> F
Loading

Grey Divider

File Changes

1. krkn/template_manager.py ✨ Enhancement +666/-0

New template manager module for chaos scenario templates

• New module providing TemplateManager class for managing and running chaos scenario templates
• Implements template listing, validation, detail retrieval, and configuration preparation with
 parameter overrides
• Provides CLI commands (list, show, run) for template management and execution
• Supports dynamic parameter application and KRKN configuration wrapping

krkn/template_manager.py


2. tests/test_template_manager.py 🧪 Tests +173/-0

Test suite for template manager functionality

• New test module with comprehensive test cases for TemplateManager functionality
• Tests template listing, validation, details retrieval, and configuration preparation
• Includes tests for parameter handling and template categorization

tests/test_template_manager.py


3. krkn/prometheus/client.py Formatting +28/-12

Improve variable naming in metrics processing loops

• Fixed variable naming in metrics processing loops to use descriptive names instead of generic k
 and v
• Improved code readability by using semantic variable names like pod_type, pod_list, node_k,
 hc_k, vc_k

krkn/prometheus/client.py


View more (227)
4. krkn/cerberus/setup.py 🐞 Bug fix +19/-18

Fix typo and simplify cerberus setup logic

• Fixed typo: check_applicaton_routescheck_application_routes
• Removed redundant local variable assignment check_application_routes = False
• Simplified logging messages in publish_kraken_status function

krkn/cerberus/setup.py


5. krkn/rollback/config.py 🐞 Bug fix +19/-11

Fix dataclass mutable default values with default_factory

• Fixed dataclass field initialization using field(default_factory=...) for mutable defaults
• Changed timestamp to use field(default_factory=time.time_ns) instead of direct call
• Changed hash_suffix to use field(default_factory=lambda: get_random_string(8)) for proper lazy
 evaluation

krkn/rollback/config.py


6. tests/test_rollback.py 🐞 Bug fix +17/-7

Fix rollback test to match corrected plugin signature

• Removed incorrect krkn_config parameter from simple_rollback_scenario_plugin.run() call
• Updated test scenario plugin to match corrected run() method signature without krkn_config

tests/test_rollback.py


7. krkn/scenario_plugins/native/plugins.py ✨ Enhancement +19/-1

Add kraken_config parameter to native plugins runner

• Added kraken_config parameter to run() method signature
• Updated step execution to pass kraken_config to steps that require it

krkn/scenario_plugins/native/plugins.py


8. run_kraken.py ✨ Enhancement +34/-0

Add template command routing to main kraken entry point

• Added template command handling (list, show, run) before krkn_lib import
• Routes template commands to TemplateManager main function
• Preserves original sys.argv and handles import errors gracefully

run_kraken.py


9. krkn/rollback/command.py 🐞 Bug fix +20/-1

Fix tree-printing logic in rollback command

• Fixed tree-printing logic for file prefix generation in list_rollback function
• Improved conditional logic to correctly determine prefix based on directory and file position

krkn/rollback/command.py


10. krkn/scenario_plugins/abstract_scenario_plugin.py 🐞 Bug fix +17/-2

Remove krkn_config parameter from abstract plugin interface

• Removed krkn_config parameter from abstract run() method signature
• Updated docstring to reflect correct method signature and fix typo "suceeded" → "succeeded"

krkn/scenario_plugins/abstract_scenario_plugin.py


11. krkn/rollback/signal.py Formatting +17/-1

Fix logging message typo in signal context

• Fixed logging message: "Set signal context set" → "Signal context set" (removed duplicate word)

krkn/rollback/signal.py


12. krkn/scenario_plugins/hogs/hogs_scenario_plugin.py 🐞 Bug fix +18/-1

Fix node selector validation logic in hogs plugin

• Fixed logic error: changed has_selector = True to has_selector = False as initial value
• Set has_selector = True only when node_selector is valid and matches pattern

krkn/scenario_plugins/hogs/hogs_scenario_plugin.py


13. krkn/rollback/handler.py Formatting +18/-2

Fix indentation in rollback handler

• Fixed indentation in execute_rollback_version_files function for consistency

krkn/rollback/handler.py


14. krkn/scenario_plugins/network_chaos_ng/network_chaos_ng_scenario_plugin.py 🐞 Bug fix +17/-5

Fix random.sample condition in network chaos plugin

• Fixed condition logic: changed from instance_count > len(targets) to `len(targets) >
 instance_count`
• Ensures random.sample() is called only when targets list is larger than requested count

krkn/scenario_plugins/network_chaos_ng/network_chaos_ng_scenario_plugin.py


15. krkn/scenario_plugins/pod_disruption/pod_disruption_scenario_plugin.py 🐞 Bug fix +18/-1

Add missing return statement in pod disruption plugin

• Added missing return statement when namespace pattern is not specified
• Returns error code 2 when namespace validation fails

krkn/scenario_plugins/pod_disruption/pod_disruption_scenario_plugin.py


16. tests/rollback_scenario_plugins/simple.py 📝 Documentation +16/-2

Add license header to test plugin

• Added Apache License header to test plugin file

tests/rollback_scenario_plugins/simple.py


17. krkn/scenario_plugins/scenario_plugin_factory.py 🐞 Bug fix +18/-4

Fix shared mutable state in scenario plugin factory

• Moved class-level mutable attributes to instance initialization in __init__
• Changed loaded_plugins and failed_plugins from class variables to instance variables
• Eliminates shared mutable state issues between factory instances

krkn/scenario_plugins/scenario_plugin_factory.py


18. krkn/scenario_plugins/syn_flood/syn_flood_scenario_plugin.py 📝 Documentation +16/-2

Add license header to syn flood plugin

• Added Apache License header to file

krkn/scenario_plugins/syn_flood/syn_flood_scenario_plugin.py


19. krkn/utils/VirtChecker.py 🐞 Bug fix +18/-2

Fix shared mutable state in VirtChecker class

• Moved class-level attributes current_iterations and ret_value to instance initialization
• Eliminates shared mutable state between VirtChecker instances

krkn/utils/VirtChecker.py


20. krkn/utils/HealthChecker.py 🐞 Bug fix +18/-2

Fix shared mutable state in HealthChecker class

• Moved class-level attributes current_iterations and ret_value to instance initialization in
 __init__
• Ensures each HealthChecker instance has independent state

krkn/utils/HealthChecker.py


21. krkn/utils/TeeLogHandler.py 🐞 Bug fix +21/-1

Fix shared mutable state in TeeLogHandler class

• Moved class-level logs list to instance initialization in __init__
• Added proper __init__ method calling super().__init__()
• Eliminates shared mutable state between handler instances

krkn/utils/TeeLogHandler.py


22. krkn/scenario_plugins/container/container_scenario_plugin.py 🐞 Bug fix +18/-1

Fix list.remove() misuse in container plugin

• Fixed incorrect use of list.remove() return value (returns None, not modified list)
• Added separate line to clear container_ready list after processing

krkn/scenario_plugins/container/container_scenario_plugin.py


23. krkn/scenario_plugins/service_hijacking/service_hijacking_scenario_plugin.py 📝 Documentation +16/-2

Add license header to service hijacking plugin

• Added Apache License header to file

krkn/scenario_plugins/service_hijacking/service_hijacking_scenario_plugin.py


24. krkn/scenario_plugins/native/native_scenario_plugin.py ✨ Enhancement +17/-0

Pass kraken_config to native plugins runner

• Added kraken_config parameter to PLUGINS.run() call
• Retrieves kraken_config from telemetry configuration

krkn/scenario_plugins/native/native_scenario_plugin.py


25. krkn/scenario_plugins/pvc/pvc_scenario_plugin.py 📝 Documentation +16/-2

Add license header to PVC plugin

• Added Apache License header to file

krkn/scenario_plugins/pvc/pvc_scenario_plugin.py


26. tests/test_cerberus_setup.py 🐞 Bug fix +17/-1

Fix typo in cerberus setup test

• Fixed typo in test: check_applicaton_routescheck_application_routes

tests/test_cerberus_setup.py


27. CI/tests_v2/scenarios/application_outage/test_application_outage.py 📝 Documentation +16/-0

Add license header to application outage test

• Added Apache License header to file

CI/tests_v2/scenarios/application_outage/test_application_outage.py


28. CI/tests_v2/lib/__init__.py 📝 Documentation +16/-0

Add license header to CI test library

• Added Apache License header to file

CI/tests_v2/lib/init.py


29. CI/tests_v2/scenarios/pod_disruption/test_pod_disruption.py 📝 Documentation +16/-0

Add license header to pod disruption test

• Added Apache License header to file

CI/tests_v2/scenarios/pod_disruption/test_pod_disruption.py


30. CI/tests_v2/scaffold.py 📝 Documentation +16/-1

Update shebang and add license header to scaffold

• Changed shebang from #!/usr/bin/env python3 to #!/usr/bin/env python
• Added Apache License header to file

CI/tests_v2/scaffold.py


31. krkn/tests/test_classes/example_scenario_plugin.py 📝 Documentation +16/-0

Add license header to example scenario plugin

• Added Apache License header to file

krkn/tests/test_classes/example_scenario_plugin.py


32. krkn/scenario_plugins/node_actions/bm_node_scenarios.py 📝 Documentation +16/-0

Add license header to bare metal node scenarios

• Added Apache License header to file

krkn/scenario_plugins/node_actions/bm_node_scenarios.py


33. krkn/scenario_plugins/node_actions/docker_node_scenarios.py 📝 Documentation +16/-0

Add license header to docker node scenarios

• Added Apache License header to file

krkn/scenario_plugins/node_actions/docker_node_scenarios.py


34. krkn/scenario_plugins/network_chaos_ng/network_chaos_factory.py 📝 Documentation +16/-0

Add license header to network chaos factory

• Added Apache License header to file

krkn/scenario_plugins/network_chaos_ng/network_chaos_factory.py


35. krkn/scenario_plugins/native/pod_network_outage/kubernetes_functions.py 📝 Documentation +16/-0

Add license header to kubernetes functions

• Added Apache License header to file

krkn/scenario_plugins/native/pod_network_outage/kubernetes_functions.py


36. CI/tests_v2/conftest.py 📝 Documentation +16/-0

Add license header to pytest conftest

• Added Apache License header to file

CI/tests_v2/conftest.py


37. krkn/tests/test_classes/duplicated_two_scenario_plugin.py 📝 Documentation +16/-0

Add license header to duplicated scenario plugin

• Added Apache License header to file

krkn/tests/test_classes/duplicated_two_scenario_plugin.py


38. krkn/chaos_recommender/kraken_tests.py 📝 Documentation +16/-0

Add license header to chaos recommender tests

• Added Apache License header to file

krkn/chaos_recommender/kraken_tests.py


39. krkn/scenario_plugins/node_actions/general_cloud_node_scenarios.py 📝 Documentation +16/-0

Add license header to general cloud node scenarios

• Added Apache License header to file

krkn/scenario_plugins/node_actions/general_cloud_node_scenarios.py


40. krkn/tests/test_classes/duplicated_scenario_plugin.py 📝 Documentation +16/-0

Add license header to duplicated scenario plugin test

• Added Apache License header to file

krkn/tests/test_classes/duplicated_scenario_plugin.py


41. krkn/chaos_recommender/__init__.py 📝 Documentation +16/-0

Add license header to chaos recommender module

• Added Apache License header to file

krkn/chaos_recommender/init.py


42. krkn/scenario_plugins/native/network/kubernetes_functions.py 📝 Documentation +16/-0

Add license header to native network kubernetes functions

• Added Apache License header to file

krkn/scenario_plugins/native/network/kubernetes_functions.py


43. krkn/scenario_plugins/kubevirt_vm_outage/kubevirt_vm_outage_scenario_plugin.py 📝 Documentation +16/-0

Add license header to kubevirt VM outage plugin

• Added Apache License header to file

krkn/scenario_plugins/kubevirt_vm_outage/kubevirt_vm_outage_scenario_plugin.py


44. krkn/utils/__init__.py 📝 Documentation +16/-0

Add license header to utils module

• Added Apache License header to file

krkn/utils/init.py


45. CI/tests_v2/lib/base.py 📝 Documentation +16/-0

Add license header to CI test base class

• Added Apache License header to file

CI/tests_v2/lib/base.py


46. krkn/scenario_plugins/native/pod_network_outage/pod_network_outage_plugin.py 📝 Documentation +16/-1

Update shebang and add license header to pod network outage plugin

• Changed shebang from #!/usr/bin/env python3 to #!/usr/bin/env python
• Added Apache License header to file

krkn/scenario_plugins/native/pod_network_outage/pod_network_outage_plugin.py


47. krkn/utils/functions.py 📝 Documentation +16/-0

Add license header to utils functions

• Added Apache License header to file

krkn/utils/functions.py


48. krkn/scenario_plugins/network_chaos_ng/modules/utils_network_filter.py 📝 Documentation +16/-0

Add license header to network filter utilities

• Added Apache License header to file

krkn/scenario_plugins/network_chaos_ng/modules/utils_network_filter.py


49. tests/test_failed_scenarios_accumulation.py 📝 Documentation +16/-1

Update shebang and add license header to failed scenarios test

• Changed shebang from #!/usr/bin/env python3 to #!/usr/bin/env python
• Added Apache License header to file

tests/test_failed_scenarios_accumulation.py


50. krkn/scenario_plugins/node_actions/ibmcloud_power_node_scenarios.py 📝 Documentation +15/-0

Add license header to IBM Cloud Power node scenarios

• Added Apache License header to file

krkn/scenario_plugins/node_actions/ibmcloud_power_node_scenarios.py


51. krkn/tests/test_classes/snake_case_mismatch_scenario_plugin.py 📝 Documentation +16/-0

Add license header to snake case mismatch test plugin

• Added Apache License header to file

krkn/tests/test_classes/snake_case_mismatch_scenario_plugin.py


52. krkn/tests/test_classes/wrong_classname_scenario_plugin.py 📝 Documentation +16/-0

Add license header to wrong classname test plugin

• Added Apache License header to file

krkn/tests/test_classes/wrong_classname_scenario_plugin.py


53. tests/test_kubevirt_vm_outage.py 📝 Documentation +16/-1

Update shebang and add license header to kubevirt test

• Changed shebang from #!/usr/bin/env python3 to #!/usr/bin/env python
• Added Apache License header to file

tests/test_kubevirt_vm_outage.py


54. tests/test_network_chaos_ng_scenario_plugin.py 📝 Documentation +16/-1

Update shebang and add license header to network chaos test

• Changed shebang from #!/usr/bin/env python3 to #!/usr/bin/env python
• Added Apache License header to file

tests/test_network_chaos_ng_scenario_plugin.py


55. krkn/scenario_plugins/managed_cluster/common_functions.py 📝 Documentation +16/-0

Add license header to managed cluster common functions

• Added Apache License header to file

krkn/scenario_plugins/managed_cluster/common_functions.py


56. krkn/scenario_plugins/zone_outage/zone_outage_scenario_plugin.py 📝 Documentation +16/-2

Add license header and reorganize imports in zone outage plugin

• Added Apache License header to file
• Reorganized imports (moved base64 and json after shebang and license)

krkn/scenario_plugins/zone_outage/zone_outage_scenario_plugin.py


57. tests/test_alibaba_node_scenarios.py 📝 Documentation +16/-1

Update shebang and add license header to alibaba test

• Changed shebang from #!/usr/bin/env python3 to #!/usr/bin/env python
• Added Apache License header to file

tests/test_alibaba_node_scenarios.py


58. tests/test_ibmcloud_node_scenarios.py 📝 Documentation +16/-1

Update shebang and add license header to IBM Cloud test

• Changed shebang from #!/usr/bin/env python3 to #!/usr/bin/env python
• Added Apache License header to file

tests/test_ibmcloud_node_scenarios.py


59. tests/test_ibmcloud_power_node_scenarios.py 📝 Documentation +16/-1

Update shebang and add license header to IBM Cloud Power test

• Changed shebang from #!/usr/bin/env python3 to #!/usr/bin/env python
• Added Apache License header to file

tests/test_ibmcloud_power_node_scenarios.py


60. tests/test_pod_disruption_scenario_plugin.py 📝 Documentation +16/-1

Update shebang and add license header to pod disruption test

• Changed shebang from #!/usr/bin/env python3 to #!/usr/bin/env python
• Added Apache License header to file

tests/test_pod_disruption_scenario_plugin.py


61. tests/test_service_hijacking_scenario_plugin.py 📝 Documentation +16/-1

Update shebang and add license header to service hijacking test

• Changed shebang from #!/usr/bin/env python3 to #!/usr/bin/env python
• Added Apache License header to file

tests/test_service_hijacking_scenario_plugin.py


62. CI/tests_v2/lib/preflight.py 📝 Documentation +16/-0

Add license header to CI preflight checks

• Added Apache License header to file

CI/tests_v2/lib/preflight.py


63. krkn/scenario_plugins/network_chaos_ng/modules/pod_network_chaos.py 📝 Documentation +16/-0

Add license header to pod network chaos module

• Added Apache License header to file

krkn/scenario_plugins/network_chaos_ng/modules/pod_network_chaos.py


64. krkn/tests/test_classes/correct_scenario_plugin.py 📝 Documentation +16/-0

Add license header to correct scenario plugin test

• Added Apache License header to file

krkn/tests/test_classes/correct_scenario_plugin.py


65. tests/test_application_outage_scenario_plugin.py 📝 Documentation +16/-1

Update shebang and add license header to application outage test

• Changed shebang from #!/usr/bin/env python3 to #!/usr/bin/env python
• Added Apache License header to file

tests/test_application_outage_scenario_plugin.py


66. tests/test_az_node_scenarios.py 📝 Documentation +16/-1

Update shebang and add license header to Azure node test

• Changed shebang from #!/usr/bin/env python3 to #!/usr/bin/env python
• Added Apache License header to file

tests/test_az_node_scenarios.py


67. tests/test_network_chaos_scenario_plugin.py 📝 Documentation +16/-1

Update shebang and add license header to network chaos test

• Changed shebang from #!/usr/bin/env python3 to #!/usr/bin/env python
• Added Apache License header to file

tests/test_network_chaos_scenario_plugin.py


68. tests/test_service_disruption_scenario_plugin.py 📝 Documentation +16/-1

Update shebang and add license header to service disruption test

• Changed shebang from #!/usr/bin/env python3 to #!/usr/bin/env python
• Added Apache License header to file

tests/test_service_disruption_scenario_plugin.py


69. tests/test_zone_outage_scenario_plugin.py 📝 Documentation +16/-1

Update shebang and add license header to zone outage test

• Changed shebang from #!/usr/bin/env python3 to #!/usr/bin/env python
• Added Apache License header to file

tests/test_zone_outage_scenario_plugin.py


70. krkn/scenario_plugins/managed_cluster/scenarios.py 📝 Documentation +16/-0

Add license header to managed cluster scenarios

• Added Apache License header to file

krkn/scenario_plugins/managed_cluster/scenarios.py


71. krkn/scenario_plugins/native/network/ingress_shaping.py 📝 Documentation +16/-0

Add license header to ingress shaping module

• Added Apache License header to file

krkn/scenario_plugins/native/network/ingress_shaping.py


72. krkn/scenario_plugins/network_chaos_ng/modules/abstract_network_chaos_module.py 📝 Documentation +16/-0

Add license header to abstract network chaos module

• Added Apache License header to file

krkn/scenario_plugins/network_chaos_ng/modules/abstract_network_chaos_module.py


73. krkn/scenario_plugins/network_chaos_ng/modules/node_network_chaos.py 📝 Documentation +16/-0

Add license header to node network chaos module

• Added Apache License header to file

krkn/scenario_plugins/network_chaos_ng/modules/node_network_chaos.py


74. krkn/scenario_plugins/network_chaos_ng/modules/utils_network_chaos.py 📝 Documentation +16/-0

Add license header to network chaos utilities

• Added Apache License header to file

krkn/scenario_plugins/network_chaos_ng/modules/utils_network_chaos.py


75. krkn/scenario_plugins/shut_down/shut_down_scenario_plugin.py 📝 Documentation +16/-0

Add license header to shut down plugin

• Added Apache License header to file

krkn/scenario_plugins/shut_down/shut_down_scenario_plugin.py


76. tests/test_abstract_scenario_plugin_cerberus.py 📝 Documentation +16/-0

Add license header to abstract scenario plugin test

• Added Apache License header to file

tests/test_abstract_scenario_plugin_cerberus.py


77. tests/test_managed_cluster_scenario_plugin.py 📝 Documentation +16/-1

Update shebang and add license header to managed cluster test

• Changed shebang from #!/usr/bin/env python3 to #!/usr/bin/env python
• Added Apache License header to file

tests/test_managed_cluster_scenario_plugin.py


78. tests/test_pod_network_chaos.py 📝 Documentation +16/-1

Update shebang and add license header to pod network chaos test

• Changed shebang from #!/usr/bin/env python3 to #!/usr/bin/env python
• Added Apache License header to file

tests/test_pod_network_chaos.py


79. tests/test_shut_down_scenario_plugin.py 📝 Documentation +16/-1

Update shebang and add license header to shut down test

• Changed shebang from #!/usr/bin/env python3 to #!/usr/bin/env python
• Added Apache License header to file

tests/test_shut_down_scenario_plugin.py


80. tests/test_syn_flood_scenario_plugin.py 📝 Documentation +16/-1

Update shebang and add license header to syn flood test

• Changed shebang from #!/usr/bin/env python3 to #!/usr/bin/env python
• Added Apache License header to file

tests/test_syn_flood_scenario_plugin.py


81. tests/test_utils_network_chaos.py 📝 Documentation +16/-1

Update shebang and add license header to network chaos utils test

• Changed shebang from #!/usr/bin/env python3 to #!/usr/bin/env python
• Added Apache License header to file

tests/test_utils_network_chaos.py


82. tests/test_vmware_node_scenarios.py 📝 Documentation +16/-1

Update shebang and add license header to VMware test

• Changed shebang from #!/usr/bin/env python3 to #!/usr/bin/env python
• Added Apache License header to file

tests/test_vmware_node_scenarios.py


83. krkn/scenario_plugins/network_chaos_ng/models.py 📝 Documentation +16/-0

Add license header to network chaos models

• Added Apache License header to file

krkn/scenario_plugins/network_chaos_ng/models.py


84. krkn/scenario_plugins/network_chaos_ng/modules/pod_network_filter.py 📝 Documentation +16/-0

Add license header to pod network filter module

• Added Apache License header to file

krkn/scenario_plugins/network_chaos_ng/modules/pod_network_filter.py


85. krkn/scenario_plugins/node_actions/ibmcloud_node_scenarios.py 📝 Documentation +15/-0

Add license header to IBM Cloud node scenarios

• Added Apache License header to file

krkn/scenario_plugins/node_actions/ibmcloud_node_scenarios.py


86. krkn/tests/test_classes/__init__.py 📝 Documentation +16/-0

Add license header to test classes module

• Added Apache License header to file

krkn/tests/test_classes/init.py


87. krkn/tests/test_classes/wrong_module.py 📝 Documentation +16/-0

Add license header to wrong module test

• Added Apache License header to file

krkn/tests/test_classes/wrong_module.py


88. tests/test_gcp_node_scenarios.py 📝 Documentation +16/-1

Update shebang and add license header to GCP test

• Changed shebang from #!/usr/bin/env python3 to #!/usr/bin/env python
• Added Apache License header to file

tests/test_gcp_node_scenarios.py


89. tests/test_hogs_scenario_plugin.py 📝 Documentation +16/-1

Update shebang and add license header to hogs test

• Changed shebang from #!/usr/bin/env python3 to #!/usr/bin/env python
• Added Apache License header to file

tests/test_hogs_scenario_plugin.py


90. tests/test_ingress_network_plugin.py 📝 Documentation +16/-0

Add license header to ingress network plugin test

• Added Apache License header to file

tests/test_ingress_network_plugin.py


91. tests/test_node_actions_scenario_plugin.py 📝 Documentation +16/-1

Update shebang and add license header to node actions test

• Changed shebang from #!/usr/bin/env python3 to #!/usr/bin/env python
• Added Apache License header to file

tests/test_node_actions_scenario_plugin.py


92. tests/test_node_network_chaos.py 📝 Documentation +16/-1

Update shebang and add license header to node network chaos test

• Changed shebang from #!/usr/bin/env python3 to #!/usr/bin/env python
• Added Apache License header to file

tests/test_node_network_chaos.py


93. tests/test_openstack_node_scenarios.py 📝 Documentation +16/-1

Update shebang and add license header to OpenStack test

• Changed shebang from #!/usr/bin/env python3 to #!/usr/bin/env python
• Added Apache License header to file

tests/test_openstack_node_scenarios.py


94. tests/test_pvc_scenario_plugin.py 📝 Documentation +16/-1

Update shebang and add license header to PVC test

• Changed shebang from #!/usr/bin/env python3 to #!/usr/bin/env python
• Added Apache License header to file

tests/test_pvc_scenario_plugin.py


95. tests/test_time_actions_scenario_plugin.py 📝 Documentation +16/-1

Update shebang and add license header to time actions test

• Changed shebang from #!/usr/bin/env python3 to #!/usr/bin/env python
• Added Apache License header to file

tests/test_time_actions_scenario_plugin.py


96. CI/tests_v2/lib/namespace.py 📝 Documentation +16/-0

Add license header to namespace lifecycle module

• Added Apache License header to file

CI/tests_v2/lib/namespace.py


97. krkn/scenario_plugins/network_chaos/network_chaos_scenario_plugin.py 📝 Documentation +16/-0

Add license header to network chaos scenario plugin

• Added Apache License header to file

krkn/scenario_plugins/network_chaos/network_chaos_scenario_plugin.py


98. krkn/scenario_plugins/network_chaos_ng/modules/node_network_filter.py 📝 Documentation +16/-0

Add license header to node network filter module

• Added Apache License header to file

krkn/scenario_plugins/network_chaos_ng/modules/node_network_filter.py


99. krkn/scenario_plugins/node_actions/node_actions_scenario_plugin.py 📝 Documentation +16/-0

Add license header to node actions scenario plugin

• Added Apache License header to file

krkn/scenario_plugins/node_actions/node_actions_scenario_plugin.py


100. tests/test_aws_node_scenarios.py 📝 Documentation +16/-1

Update shebang and add license header to AWS test

• Changed shebang from #!/usr/bin/env python3 to #!/usr/bin/env python
• Added Apache License header to file

tests/test_aws_node_scenarios.py


101. tests/test_prometheus_client.py 📝 Documentation +16/-1

Update shebang and add license header to prometheus test

• Changed shebang from #!/usr/bin/env python3 to #!/usr/bin/env python
• Added Apache License header to file

tests/test_prometheus_client.py


102. CI/tests_v2/lib/deploy.py 📝 Documentation +16/-0

Add license header to deploy utilities module

• Added Apache License header to file

CI/tests_v2/lib/deploy.py


103. tests/test_container_scenario_plugin.py 📝 Documentation +16/-1

Update shebang and add license header to container test

• Changed shebang from #!/usr/bin/env python3 to #!/usr/bin/env python
• Added Apache License header to file

tests/test_container_scenario_plugin.py


104. tests/test_native_scenario_plugin.py 📝 Documentation +16/-1

Update shebang and add license header to native plugin test

• Changed shebang from #!/usr/bin/env python3 to #!/usr/bin/env python
• Added Apache License header to file

tests/test_native_scenario_plugin.py


105. CI/tests_v2/lib/k8s.py 📝 Documentation +16/-0

Add license header to Kubernetes test fixtures

• Added Apache License 2.0 header with copyright notice
• Standardized Python shebang and file header format

CI/tests_v2/lib/k8s.py


106. krkn/chaos_recommender/prometheus.py 📝 Documentation +16/-0

Add license header to Prometheus module

• Added Apache License 2.0 header with copyright notice
• Standardized Python shebang and file header format

krkn/chaos_recommender/prometheus.py


107. krkn/scenario_plugins/application_outage/application_outage_scenario_plugin.py 📝 Documentation +16/-0

Add license header to application outage plugin

• Added Apache License 2.0 header with copyright notice
• Standardized Python shebang and file header format

krkn/scenario_plugins/application_outage/application_outage_scenario_plugin.py


108. krkn/scenario_plugins/network_chaos_ng/modules/utils.py 📝 Documentation +16/-0

Add license header to network chaos utilities

• Added Apache License 2.0 header with copyright notice
• Standardized Python shebang and file header format

krkn/scenario_plugins/network_chaos_ng/modules/utils.py


109. krkn/scenario_plugins/node_actions/gcp_node_scenarios.py 📝 Documentation +16/-0

Add license header to GCP node scenarios

• Added Apache License 2.0 header with copyright notice
• Standardized Python shebang and file header format

krkn/scenario_plugins/node_actions/gcp_node_scenarios.py


110. krkn/scenario_plugins/node_actions/vmware_node_scenarios.py 📝 Documentation +15/-0

Add license header to VMware node scenarios

• Added Apache License 2.0 header with copyright notice
• Standardized Python shebang and file header format

krkn/scenario_plugins/node_actions/vmware_node_scenarios.py


111. krkn/scenario_plugins/service_disruption/service_disruption_scenario_plugin.py 📝 Documentation +16/-0

Add license header to service disruption plugin

• Added Apache License 2.0 header with copyright notice
• Standardized Python shebang and file header format

krkn/scenario_plugins/service_disruption/service_disruption_scenario_plugin.py


112. tests/test_common_node_functions.py 📝 Documentation +16/-1

Add license header and standardize Python shebang

• Changed shebang from #!/usr/bin/env python3 to #!/usr/bin/env python
• Added Apache License 2.0 header with copyright notice

tests/test_common_node_functions.py


113. CI/tests_v2/lib/kraken.py 📝 Documentation +16/-0

Add license header to Kraken execution fixtures

• Added Apache License 2.0 header with copyright notice
• Standardized Python shebang and file header format

CI/tests_v2/lib/kraken.py


114. krkn/scenario_plugins/node_actions/abstract_node_scenarios.py 📝 Documentation +16/-0

Add license header to abstract node scenarios

• Added Apache License 2.0 header with copyright notice
• Standardized Python shebang and file header format

krkn/scenario_plugins/node_actions/abstract_node_scenarios.py


115. krkn/scenario_plugins/node_actions/alibaba_node_scenarios.py 📝 Documentation +16/-0

Add license header to Alibaba node scenarios

• Added Apache License 2.0 header with copyright notice
• Standardized Python shebang and file header format

krkn/scenario_plugins/node_actions/alibaba_node_scenarios.py


116. krkn/scenario_plugins/node_actions/aws_node_scenarios.py 📝 Documentation +16/-0

Add license header to AWS node scenarios

• Added Apache License 2.0 header with copyright notice
• Standardized Python shebang and file header format

krkn/scenario_plugins/node_actions/aws_node_scenarios.py


117. krkn/scenario_plugins/node_actions/az_node_scenarios.py 📝 Documentation +16/-0

Add license header to Azure node scenarios

• Added Apache License 2.0 header with copyright notice
• Standardized Python shebang and file header format

krkn/scenario_plugins/node_actions/az_node_scenarios.py


118. krkn/scenario_plugins/node_actions/openstack_node_scenarios.py 📝 Documentation +16/-0

Add license header to OpenStack node scenarios

• Added Apache License 2.0 header with copyright notice
• Standardized Python shebang and fil...

@qodo-code-review
Copy link
Copy Markdown

qodo-code-review bot commented Mar 27, 2026

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 📐 Spec deviations (0)

Grey Divider


Action required

1. Missing base64/json imports🐞 Bug ✓ Correctness
Description
ZoneOutageScenarioPlugin.node_based_zone() uses base64.b64encode/json.dumps to build rollback data,
but this PR removed the module-level imports, causing a NameError at runtime. This will crash the
zone outage scenario when that code path executes.
Code

krkn/scenario_plugins/zone_outage/zone_outage_scenario_plugin.py[L1-2]

-import base64
-import json
+#!/usr/bin/env python
+#
+# Copyright 2025 The Krkn Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
Evidence
The diff removes the base64/json imports, and the updated file still calls base64.b64encode() and
json.dumps() in node_based_zone(), which will raise NameError because neither name is defined in the
module scope.

krkn/scenario_plugins/zone_outage/zone_outage_scenario_plugin.py[17-34]
krkn/scenario_plugins/zone_outage/zone_outage_scenario_plugin.py[93-105]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`krkn/scenario_plugins/zone_outage/zone_outage_scenario_plugin.py` references `base64` and `json` in `node_based_zone()`, but the PR removed `import base64` and `import json`, causing a `NameError` during execution.

### Issue Context
This breaks rollback data encoding for the zone outage scenario.

### Fix Focus Areas
- krkn/scenario_plugins/zone_outage/zone_outage_scenario_plugin.py[1-35]
- krkn/scenario_plugins/zone_outage/zone_outage_scenario_plugin.py[93-105]

### Expected fix
Add `import base64` and `import json` (module-level, near other imports), or refactor the encoding to avoid those names—ensuring the module compiles and `node_based_zone()` runs without NameError.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Wrong application_status call🐞 Bug ✓ Correctness
Description
When Cerberus route checks are enabled, get_status() calls application_status(cerberus_url,
start_time, end_time) but application_status is defined as application_status(start_time, end_time),
causing a TypeError and aborting the run. This PR makes that path reachable by correctly reading
check_application_routes and removing the local override that previously forced the check off.
Code

krkn/cerberus/setup.py[R36-45]

        global check_application_routes
        check_application_routes = \
-            get_yaml_item_value(config["cerberus"],"check_applicaton_routes","")
+            get_yaml_item_value(config["cerberus"],"check_application_routes","")

def get_status(start_time, end_time):
    """
    Get cerberus status
    """
    cerberus_status = True
-    check_application_routes = False
    application_routes_status = True
Evidence
The updated config wiring means check_application_routes can now be truthy; in that case,
get_status() calls application_status() with three args, but the function is defined with two
parameters, which raises `TypeError: application_status() takes 2 positional arguments but 3 were
given`.

krkn/cerberus/setup.py[28-39]
krkn/cerberus/setup.py[56-63]
krkn/cerberus/setup.py[110-124]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`get_status()` calls `application_status(cerberus_url, start_time, end_time)` but `application_status` is defined as `application_status(start_time, end_time)`, which will raise a `TypeError` when `check_application_routes` is enabled.

### Issue Context
This PR fixes the YAML key (`check_application_routes`) and removes the local override that previously prevented this code path from running, so the mismatch is now user-reachable.

### Fix Focus Areas
- krkn/cerberus/setup.py[28-63]
- krkn/cerberus/setup.py[110-124]

### Expected fix
Make the call and the function signature consistent. For example:
- Change the call site to `application_status(start_time, end_time)` (since the function already uses the global `cerberus_url`), OR
- Update `application_status` to accept `(cerberus_url, start_time, end_time)` and use the passed URL consistently.
Also ensure `check_application_routes` is treated as a boolean (not a non-empty string) if config parsing can yield string values.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

@paigerube14
Copy link
Copy Markdown
Collaborator

@NETIZEN-11 thanks so much for this PR, are you actually able to separate each of your commits into separate PR's so this one isn't so large. We recommend each PR has its own single purpose/change so that its easier for us to review. TIA

…/chaos-templates.md

Signed-off-by: Nitesh <nitesh@example.com>
@NETIZEN-11
Copy link
Copy Markdown
Contributor Author

@paigerube14 Thanks for the feedback!

You're absolutely right — this PR is quite large. I’ll split it into smaller, focused PRs, each with a single purpose (e.g., rollback fixes, scenario plugin fixes, utils/cerberus fixes, tests, etc.) to make the review easier.

I’ll also address the review comments (missing imports and correctness issues) in the respective PRs.

I’ll follow up shortly with the separated PRs. Thanks again!

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.

Guided Krkn install mission in KubeStellar Console

2 participants