diff --git a/CI/legacy/tests/test_nodes.sh b/CI/legacy/tests/test_nodes.sh index 64f3d9c7f..b23cd54e8 100755 --- a/CI/legacy/tests/test_nodes.sh +++ b/CI/legacy/tests/test_nodes.sh @@ -1,3 +1,19 @@ +#!/bin/bash +# +# 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. + set -xeEo pipefail source CI/tests/common.sh diff --git a/CI/legacy/tests/test_shut_down.sh b/CI/legacy/tests/test_shut_down.sh index b404bf0a7..7c191fc85 100755 --- a/CI/legacy/tests/test_shut_down.sh +++ b/CI/legacy/tests/test_shut_down.sh @@ -1,3 +1,19 @@ +#!/bin/bash +# +# 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. + set -xeEo pipefail source CI/tests/common.sh diff --git a/CI/legacy/tests/test_zone.sh b/CI/legacy/tests/test_zone.sh index e5d0224e6..6d6a93d3d 100755 --- a/CI/legacy/tests/test_zone.sh +++ b/CI/legacy/tests/test_zone.sh @@ -1,3 +1,19 @@ +#!/bin/bash +# +# 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. + set -xeEo pipefail source CI/tests/common.sh diff --git a/CI/run.sh b/CI/run.sh index 0bf8b73d0..d963dd6ad 100755 --- a/CI/run.sh +++ b/CI/run.sh @@ -1,4 +1,19 @@ #!/bin/bash +# +# 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. + MAX_RETRIES=60 KUBECTL=`which kubectl 2>/dev/null` diff --git a/CI/run_test.sh b/CI/run_test.sh index 7d0d516b2..70113b16e 100755 --- a/CI/run_test.sh +++ b/CI/run_test.sh @@ -1,4 +1,19 @@ #!/bin/bash +# +# 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. + readonly SECONDS_PER_HOUR=3600 readonly SECONDS_PER_MINUTE=60 function get_time_format() { diff --git a/CI/tests/common.sh b/CI/tests/common.sh index e93f390c0..a81edac1c 100644 --- a/CI/tests/common.sh +++ b/CI/tests/common.sh @@ -1,3 +1,19 @@ +#!/bin/bash +# +# 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. + ERRORED=false function finish { diff --git a/CI/tests/test_app_outages.sh b/CI/tests/test_app_outages.sh index 90dfc5849..772e6a10b 100755 --- a/CI/tests/test_app_outages.sh +++ b/CI/tests/test_app_outages.sh @@ -1,3 +1,19 @@ +#!/bin/bash +# +# 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. + set -xeEo pipefail source CI/tests/common.sh diff --git a/CI/tests/test_cerberus_unhealthy.sh b/CI/tests/test_cerberus_unhealthy.sh index 384397a7c..75f0bb2a4 100755 --- a/CI/tests/test_cerberus_unhealthy.sh +++ b/CI/tests/test_cerberus_unhealthy.sh @@ -1,3 +1,19 @@ +#!/bin/bash +# +# 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. + set -xeEo pipefail source CI/tests/common.sh diff --git a/CI/tests/test_container.sh b/CI/tests/test_container.sh index 271b43fae..e74fee918 100755 --- a/CI/tests/test_container.sh +++ b/CI/tests/test_container.sh @@ -1,3 +1,19 @@ +#!/bin/bash +# +# 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. + set -xeEo pipefail source CI/tests/common.sh diff --git a/CI/tests/test_cpu_hog.sh b/CI/tests/test_cpu_hog.sh index c6a648203..707521dfd 100644 --- a/CI/tests/test_cpu_hog.sh +++ b/CI/tests/test_cpu_hog.sh @@ -1,3 +1,19 @@ +#!/bin/bash +# +# 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. + set -xeEo pipefail source CI/tests/common.sh diff --git a/CI/tests/test_customapp_pod.sh b/CI/tests/test_customapp_pod.sh index 6ae39230f..f213ae34b 100755 --- a/CI/tests/test_customapp_pod.sh +++ b/CI/tests/test_customapp_pod.sh @@ -1,3 +1,19 @@ +#!/bin/bash +# +# 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. + set -xeEo pipefail source CI/tests/common.sh diff --git a/CI/tests/test_io_hog.sh b/CI/tests/test_io_hog.sh index 47e702203..2186723ce 100644 --- a/CI/tests/test_io_hog.sh +++ b/CI/tests/test_io_hog.sh @@ -1,3 +1,19 @@ +#!/bin/bash +# +# 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. + set -xeEo pipefail source CI/tests/common.sh diff --git a/CI/tests/test_memory_hog.sh b/CI/tests/test_memory_hog.sh index 02b8d21f1..54bfa17bf 100644 --- a/CI/tests/test_memory_hog.sh +++ b/CI/tests/test_memory_hog.sh @@ -1,3 +1,19 @@ +#!/bin/bash +# +# 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. + set -xeEo pipefail source CI/tests/common.sh diff --git a/CI/tests/test_namespace.sh b/CI/tests/test_namespace.sh index b2a1d578b..087288f14 100755 --- a/CI/tests/test_namespace.sh +++ b/CI/tests/test_namespace.sh @@ -1,3 +1,19 @@ +#!/bin/bash +# +# 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. + set -xeEo pipefail source CI/tests/common.sh diff --git a/CI/tests/test_net_chaos.sh b/CI/tests/test_net_chaos.sh index 767ab0d14..3c5328b5e 100755 --- a/CI/tests/test_net_chaos.sh +++ b/CI/tests/test_net_chaos.sh @@ -1,3 +1,19 @@ +#!/bin/bash +# +# 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. + set -xeEo pipefail source CI/tests/common.sh diff --git a/CI/tests/test_node.sh b/CI/tests/test_node.sh index b0057ed05..f0130d103 100755 --- a/CI/tests/test_node.sh +++ b/CI/tests/test_node.sh @@ -1,3 +1,19 @@ +#!/bin/bash +# +# 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. + uset -xeEo pipefail source CI/tests/common.sh diff --git a/CI/tests/test_node_network_chaos.sh b/CI/tests/test_node_network_chaos.sh index 606c7ecfc..f6c8a6477 100755 --- a/CI/tests/test_node_network_chaos.sh +++ b/CI/tests/test_node_network_chaos.sh @@ -1,3 +1,19 @@ +#!/bin/bash +# +# 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. + set -xeEo pipefail source CI/tests/common.sh diff --git a/CI/tests/test_pod.sh b/CI/tests/test_pod.sh index cd44c21be..bec67aafe 100755 --- a/CI/tests/test_pod.sh +++ b/CI/tests/test_pod.sh @@ -1,3 +1,19 @@ +#!/bin/bash +# +# 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. + set -xeEo pipefail source CI/tests/common.sh diff --git a/CI/tests/test_pod_error.sh b/CI/tests/test_pod_error.sh index 10ea0c74a..54534a16e 100755 --- a/CI/tests/test_pod_error.sh +++ b/CI/tests/test_pod_error.sh @@ -1,3 +1,19 @@ +#!/bin/bash +# +# 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. + source CI/tests/common.sh diff --git a/CI/tests/test_pod_network_chaos.sh b/CI/tests/test_pod_network_chaos.sh index 7c77e484f..bfa825571 100755 --- a/CI/tests/test_pod_network_chaos.sh +++ b/CI/tests/test_pod_network_chaos.sh @@ -1,3 +1,19 @@ +#!/bin/bash +# +# 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. + set -xeEo pipefail source CI/tests/common.sh diff --git a/CI/tests/test_pod_network_filter.sh b/CI/tests/test_pod_network_filter.sh index a183c4f2d..0a77177fb 100755 --- a/CI/tests/test_pod_network_filter.sh +++ b/CI/tests/test_pod_network_filter.sh @@ -1,3 +1,19 @@ +#!/bin/bash +# +# 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. + function functional_pod_network_filter { export SERVICE_URL="http://localhost:8889" export scenario_type="network_chaos_ng_scenarios" diff --git a/CI/tests/test_pod_server.sh b/CI/tests/test_pod_server.sh index 0f9b2c36c..6297a9fcf 100755 --- a/CI/tests/test_pod_server.sh +++ b/CI/tests/test_pod_server.sh @@ -1,3 +1,19 @@ +#!/bin/bash +# +# 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. + set -xeEo pipefail source CI/tests/common.sh diff --git a/CI/tests/test_pvc.sh b/CI/tests/test_pvc.sh index c115716d0..3332ff074 100755 --- a/CI/tests/test_pvc.sh +++ b/CI/tests/test_pvc.sh @@ -1,3 +1,19 @@ +#!/bin/bash +# +# 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. + set -xeEo pipefail source CI/tests/common.sh diff --git a/CI/tests/test_service_hijacking.sh b/CI/tests/test_service_hijacking.sh index 95bdb2d45..d2ab1b2b2 100644 --- a/CI/tests/test_service_hijacking.sh +++ b/CI/tests/test_service_hijacking.sh @@ -1,3 +1,19 @@ +#!/bin/bash +# +# 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. + set -xeEo pipefail source CI/tests/common.sh diff --git a/CI/tests/test_telemetry.sh b/CI/tests/test_telemetry.sh index 0c252e4df..657e6dd8e 100644 --- a/CI/tests/test_telemetry.sh +++ b/CI/tests/test_telemetry.sh @@ -1,3 +1,19 @@ +#!/bin/bash +# +# 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. + set -xeEo pipefail source CI/tests/common.sh diff --git a/CI/tests/test_time.sh b/CI/tests/test_time.sh index 240f8f9a2..279d7e578 100755 --- a/CI/tests/test_time.sh +++ b/CI/tests/test_time.sh @@ -1,3 +1,19 @@ +#!/bin/bash +# +# 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. + set -xeEo pipefail source CI/tests/common.sh diff --git a/CI/tests_v2/conftest.py b/CI/tests_v2/conftest.py index 98aec29b3..c6e67c7a9 100644 --- a/CI/tests_v2/conftest.py +++ b/CI/tests_v2/conftest.py @@ -1,3 +1,19 @@ +#!/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. + """ Shared fixtures for pytest functional tests (CI/tests_v2). Tests must be run from the repository root so run_kraken.py and config paths resolve. diff --git a/CI/tests_v2/lib/__init__.py b/CI/tests_v2/lib/__init__.py index d24e46359..f6c80a050 100644 --- a/CI/tests_v2/lib/__init__.py +++ b/CI/tests_v2/lib/__init__.py @@ -1,3 +1,19 @@ +#!/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. + # Shared framework for CI/tests_v2 functional tests. # base: BaseScenarioTest, timeout constants # utils: assertions, K8s helpers, patch_namespace_in_docs diff --git a/CI/tests_v2/lib/base.py b/CI/tests_v2/lib/base.py index fb4c799da..194405639 100644 --- a/CI/tests_v2/lib/base.py +++ b/CI/tests_v2/lib/base.py @@ -1,3 +1,19 @@ +#!/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. + """ Base class for CI/tests_v2 scenario tests. Encapsulates the shared lifecycle: ephemeral namespace, optional workload deploy, teardown. diff --git a/CI/tests_v2/lib/deploy.py b/CI/tests_v2/lib/deploy.py index 1d6bf796e..b6d981c8b 100644 --- a/CI/tests_v2/lib/deploy.py +++ b/CI/tests_v2/lib/deploy.py @@ -1,3 +1,19 @@ +#!/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. + """ Workload deploy and pod/deployment readiness fixtures for CI/tests_v2. """ diff --git a/CI/tests_v2/lib/k8s.py b/CI/tests_v2/lib/k8s.py index 6b80647ce..cf9b93122 100644 --- a/CI/tests_v2/lib/k8s.py +++ b/CI/tests_v2/lib/k8s.py @@ -1,3 +1,19 @@ +#!/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. + """ Kubernetes client fixtures and cluster context checks for CI/tests_v2. """ diff --git a/CI/tests_v2/lib/kraken.py b/CI/tests_v2/lib/kraken.py index 996128dea..df65c9af8 100644 --- a/CI/tests_v2/lib/kraken.py +++ b/CI/tests_v2/lib/kraken.py @@ -1,3 +1,19 @@ +#!/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. + """ Kraken execution and config building fixtures for CI/tests_v2. """ diff --git a/CI/tests_v2/lib/namespace.py b/CI/tests_v2/lib/namespace.py index e78466ec5..f37bdbf6d 100644 --- a/CI/tests_v2/lib/namespace.py +++ b/CI/tests_v2/lib/namespace.py @@ -1,3 +1,19 @@ +#!/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. + """ Namespace lifecycle fixtures for CI/tests_v2: create, delete, stale cleanup. """ diff --git a/CI/tests_v2/lib/preflight.py b/CI/tests_v2/lib/preflight.py index 83086664f..88fc0e4c7 100644 --- a/CI/tests_v2/lib/preflight.py +++ b/CI/tests_v2/lib/preflight.py @@ -1,3 +1,19 @@ +#!/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. + """ Preflight checks for CI/tests_v2: cluster reachability and test deps at session start. """ diff --git a/CI/tests_v2/lib/utils.py b/CI/tests_v2/lib/utils.py index d2c542b31..69dec5efc 100644 --- a/CI/tests_v2/lib/utils.py +++ b/CI/tests_v2/lib/utils.py @@ -1,3 +1,19 @@ +#!/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. + """ Shared helpers for CI/tests_v2 functional tests. """ diff --git a/CI/tests_v2/scaffold.py b/CI/tests_v2/scaffold.py index d165e28f5..fb9ad9b53 100644 --- a/CI/tests_v2/scaffold.py +++ b/CI/tests_v2/scaffold.py @@ -1,4 +1,19 @@ -#!/usr/bin/env python3 +#!/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. + """ Generate boilerplate for a new scenario test in CI/tests_v2. diff --git a/CI/tests_v2/scenarios/application_outage/test_application_outage.py b/CI/tests_v2/scenarios/application_outage/test_application_outage.py index 5a70a4de4..afcae0165 100644 --- a/CI/tests_v2/scenarios/application_outage/test_application_outage.py +++ b/CI/tests_v2/scenarios/application_outage/test_application_outage.py @@ -1,3 +1,19 @@ +#!/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. + """ Functional test for application outage scenario (block network to target pods, then restore). Equivalent to CI/tests/test_app_outages.sh with proper assertions. diff --git a/CI/tests_v2/scenarios/pod_disruption/test_pod_disruption.py b/CI/tests_v2/scenarios/pod_disruption/test_pod_disruption.py index 5564bd5d3..5c4fa0ef7 100644 --- a/CI/tests_v2/scenarios/pod_disruption/test_pod_disruption.py +++ b/CI/tests_v2/scenarios/pod_disruption/test_pod_disruption.py @@ -1,3 +1,19 @@ +#!/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. + """ Functional test for pod disruption scenario (pod crash and recovery). Equivalent to CI/tests/test_pod.sh with proper before/after assertions. diff --git a/CI/tests_v2/setup_env.sh b/CI/tests_v2/setup_env.sh index 75538e477..c8759bf6c 100755 --- a/CI/tests_v2/setup_env.sh +++ b/CI/tests_v2/setup_env.sh @@ -1,4 +1,19 @@ -#!/usr/bin/env bash +#!/bin/bash +# +# 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. + # Setup environment for CI/tests_v2 pytest functional tests. # Run from the repository root: ./CI/tests_v2/setup_env.sh # diff --git a/README.md b/README.md index 9d9c0ea13..fc1e52d52 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,32 @@ Chaos and resiliency testing tool for Kubernetes. Kraken injects deliberate failures into Kubernetes clusters to check if it is resilient to turbulent conditions. +## 🚀 New: Chaos Template Library + +KRKN now includes a comprehensive **Chaos Template Library** with pre-configured scenarios for quick execution: + +- **Pod Failure**: Test application restart policies +- **Node Failure**: Validate cluster self-healing +- **Network Latency**: Test performance under poor network +- **CPU/Disk Stress**: Identify resource bottlenecks +- **VM Outage**: OpenShift Virtualization testing +- And more! + +### Quick Start with Templates + +```bash +# List available templates +python krkn/template_manager.py list + +# Run a pod failure test +python krkn/template_manager.py run pod-failure + +# Customize with parameters +python krkn/template_manager.py run network-latency --param latency="200ms" +``` + +📖 **[Full Template Documentation](docs/chaos-templates.md)** + ### Workflow ![Kraken workflow](media/kraken-workflow.png) diff --git a/containers/compile_dockerfile.sh b/containers/compile_dockerfile.sh index 3f531eb7b..a6fa9829a 100755 --- a/containers/compile_dockerfile.sh +++ b/containers/compile_dockerfile.sh @@ -1,3 +1,19 @@ +#!/bin/bash +# +# 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. + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cd "$SCRIPT_DIR" export KRKNCTL_INPUT=$(cat krknctl-input.json|tr -d "\n") diff --git a/containers/entrypoint.sh b/containers/entrypoint.sh index 9cb680b49..ef5813bb1 100644 --- a/containers/entrypoint.sh +++ b/containers/entrypoint.sh @@ -1,4 +1,19 @@ #!/bin/bash +# +# 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. + set -e # Run SSH setup ./containers/setup-ssh.sh diff --git a/containers/setup-ssh.sh b/containers/setup-ssh.sh index e6dda6299..737e9aa29 100644 --- a/containers/setup-ssh.sh +++ b/containers/setup-ssh.sh @@ -1,4 +1,19 @@ #!/bin/bash +# +# 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. + # Setup SSH key if mounted # Support multiple mount locations MOUNTED_PRIVATE_KEY_ALT="/secrets/id_rsa" diff --git a/krkn/__init__.py b/krkn/__init__.py index e69de29bb..798fe911f 100644 --- a/krkn/__init__.py +++ b/krkn/__init__.py @@ -0,0 +1,16 @@ +#!/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. + diff --git a/krkn/cerberus/__init__.py b/krkn/cerberus/__init__.py index 9ca22d34b..8d877fc21 100644 --- a/krkn/cerberus/__init__.py +++ b/krkn/cerberus/__init__.py @@ -1 +1,17 @@ +#!/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. + from .setup import * diff --git a/krkn/cerberus/setup.py b/krkn/cerberus/setup.py index c20f2a132..cee535282 100644 --- a/krkn/cerberus/setup.py +++ b/krkn/cerberus/setup.py @@ -1,3 +1,19 @@ +#!/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. + import logging import requests import sys @@ -18,15 +34,26 @@ def set_url(config): global cerberus_url cerberus_url = get_yaml_item_value(config["cerberus"],"cerberus_url", "") global check_application_routes - check_application_routes = \ - get_yaml_item_value(config["cerberus"],"check_applicaton_routes","") + # Read correct key first; fall back to legacy misspelled key for older configs + check_application_routes = get_yaml_item_value( + config["cerberus"], "check_application_routes", "" + ) + if not check_application_routes: + legacy = get_yaml_item_value( + config["cerberus"], "check_applicaton_routes", "" + ) + if legacy: + logging.warning( + "Config key 'check_applicaton_routes' is deprecated and will be " + "removed in a future release. Please rename it to 'check_application_routes'." + ) + check_application_routes = legacy def get_status(start_time, end_time): """ Get cerberus status """ cerberus_status = True - check_application_routes = False application_routes_status = True if cerberus_enabled: if not cerberus_url: @@ -42,7 +69,6 @@ def get_status(start_time, end_time): # experience downtime during the chaos if check_application_routes: application_routes_status, unavailable_routes = application_status( - cerberus_url, start_time, end_time ) @@ -83,26 +109,12 @@ def publish_kraken_status( start_time, end_time): if not cerberus_status: if exit_on_failure: logging.info( - "Cerberus status is not healthy and post action scenarios " - "are still failing, exiting kraken run" - ) - sys.exit(1) - else: - logging.info( - "Cerberus status is not healthy and post action scenarios " - "are still failing" - ) - else: - if exit_on_failure: - logging.info( - "Cerberus status is healthy but post action scenarios " - "are still failing, exiting kraken run" + "Cerberus status is not healthy, exiting kraken run" ) sys.exit(1) else: logging.info( - "Cerberus status is healthy but post action scenarios " - "are still failing" + "Cerberus status is not healthy" ) diff --git a/krkn/chaos_recommender/__init__.py b/krkn/chaos_recommender/__init__.py index 250eef9b2..6151438bd 100644 --- a/krkn/chaos_recommender/__init__.py +++ b/krkn/chaos_recommender/__init__.py @@ -1,3 +1,19 @@ +#!/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. + from .analysis import * from .kraken_tests import * from .prometheus import * \ No newline at end of file diff --git a/krkn/chaos_recommender/analysis.py b/krkn/chaos_recommender/analysis.py index 963616957..62602599c 100644 --- a/krkn/chaos_recommender/analysis.py +++ b/krkn/chaos_recommender/analysis.py @@ -1,3 +1,19 @@ +#!/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. + import logging import pandas as pd diff --git a/krkn/chaos_recommender/kraken_tests.py b/krkn/chaos_recommender/kraken_tests.py index 8909e329f..098ad925e 100644 --- a/krkn/chaos_recommender/kraken_tests.py +++ b/krkn/chaos_recommender/kraken_tests.py @@ -1,3 +1,19 @@ +#!/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. + def get_entries_by_category(filename, category): # Read the file with open(filename, "r") as file: diff --git a/krkn/chaos_recommender/prometheus.py b/krkn/chaos_recommender/prometheus.py index c00f73d34..ad66d2e63 100644 --- a/krkn/chaos_recommender/prometheus.py +++ b/krkn/chaos_recommender/prometheus.py @@ -1,3 +1,19 @@ +#!/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. + import logging from prometheus_api_client import PrometheusConnect diff --git a/krkn/invoke/__init__.py b/krkn/invoke/__init__.py index e69de29bb..798fe911f 100644 --- a/krkn/invoke/__init__.py +++ b/krkn/invoke/__init__.py @@ -0,0 +1,16 @@ +#!/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. + diff --git a/krkn/invoke/command.py b/krkn/invoke/command.py index 5a5433350..7d9535aa5 100644 --- a/krkn/invoke/command.py +++ b/krkn/invoke/command.py @@ -1,3 +1,19 @@ +#!/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. + import subprocess import logging import sys diff --git a/krkn/prometheus/__init__.py b/krkn/prometheus/__init__.py index 4c51a3216..935e0e660 100644 --- a/krkn/prometheus/__init__.py +++ b/krkn/prometheus/__init__.py @@ -1 +1,17 @@ +#!/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. + from .client import * \ No newline at end of file diff --git a/krkn/prometheus/client.py b/krkn/prometheus/client.py index 4e624fc44..2c085a48d 100644 --- a/krkn/prometheus/client.py +++ b/krkn/prometheus/client.py @@ -1,3 +1,19 @@ +#!/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. + from __future__ import annotations import datetime @@ -165,8 +181,10 @@ def critical_alerts( if not firing_alerts: logging.info("No critical alerts are firing!!") - - + + return firing_alerts + + def metrics( prom_cli: KrknPrometheus, elastic: KrknElastic, @@ -243,37 +261,37 @@ def metrics( pass telemetry_json = json.loads(telemetry_json) for scenario in telemetry_json['scenarios']: - for k,v in scenario["affected_pods"].items(): + for pod_type, pod_list in scenario["affected_pods"].items(): metric_name = "affected_pods_recovery" - metric = {"metricName": metric_name, "type": k} - if type(v) is list: - for pod in v: - for k,v in pod.items(): - metric[k] = v + metric = {"metricName": metric_name, "type": pod_type} + if type(pod_list) is list: + for pod in pod_list: + for pod_k, pod_v in pod.items(): + metric[pod_k] = pod_v metric['timestamp'] = str(datetime.datetime.now()) logging.debug("adding pod %s", metric) metrics_list.append(metric.copy()) for affected_node in scenario["affected_nodes"]: metric_name = "affected_nodes_recovery" metric = {"metricName": metric_name} - for k,v in affected_node.items(): - metric[k] = v + for node_k, node_v in affected_node.items(): + metric[node_k] = node_v metric['timestamp'] = str(datetime.datetime.now()) metrics_list.append(metric.copy()) if telemetry_json['health_checks']: for health_check in telemetry_json["health_checks"]: metric_name = "health_check_recovery" metric = {"metricName": metric_name} - for k,v in health_check.items(): - metric[k] = v + for hc_k, hc_v in health_check.items(): + metric[hc_k] = hc_v metric['timestamp'] = str(datetime.datetime.now()) metrics_list.append(metric.copy()) if telemetry_json['virt_checks']: for virt_check in telemetry_json["virt_checks"]: metric_name = "virt_check_recovery" metric = {"metricName": metric_name} - for k,v in virt_check.items(): - metric[k] = v + for vc_k, vc_v in virt_check.items(): + metric[vc_k] = vc_v metric['timestamp'] = str(datetime.datetime.now()) metrics_list.append(metric.copy()) diff --git a/krkn/prometheus/collector.py b/krkn/prometheus/collector.py index 42ee51684..c7737449c 100644 --- a/krkn/prometheus/collector.py +++ b/krkn/prometheus/collector.py @@ -1,3 +1,19 @@ +#!/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. + from __future__ import annotations import datetime diff --git a/krkn/resiliency/__init__.py b/krkn/resiliency/__init__.py index b18b57c2a..7b9634957 100644 --- a/krkn/resiliency/__init__.py +++ b/krkn/resiliency/__init__.py @@ -1,3 +1,17 @@ +# 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. + """krkn.resiliency package public interface.""" from .resiliency import Resiliency # noqa: F401 diff --git a/krkn/resiliency/resiliency.py b/krkn/resiliency/resiliency.py index 367e4e9c4..1ddbfbe82 100644 --- a/krkn/resiliency/resiliency.py +++ b/krkn/resiliency/resiliency.py @@ -1,3 +1,19 @@ +#!/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. + """Resiliency evaluation orchestrator for Krkn chaos runs. This module provides the `Resiliency` class which loads the canonical diff --git a/krkn/resiliency/score.py b/krkn/resiliency/score.py index 811ed2162..1b53c3ff8 100644 --- a/krkn/resiliency/score.py +++ b/krkn/resiliency/score.py @@ -1,3 +1,19 @@ +#!/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. + from __future__ import annotations from typing import Dict, List, Tuple diff --git a/krkn/rollback/__init__.py b/krkn/rollback/__init__.py index e69de29bb..798fe911f 100644 --- a/krkn/rollback/__init__.py +++ b/krkn/rollback/__init__.py @@ -0,0 +1,16 @@ +#!/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. + diff --git a/krkn/rollback/command.py b/krkn/rollback/command.py index 506edf20e..fed3e620c 100644 --- a/krkn/rollback/command.py +++ b/krkn/rollback/command.py @@ -1,3 +1,19 @@ +#!/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. + import os import logging from typing import Optional, TYPE_CHECKING @@ -72,7 +88,10 @@ def list_rollback(run_uuid: Optional[str]=None, scenario_type: Optional[str]=Non files.sort() for j, file in enumerate(files): is_last_file = (j == len(files) - 1) - file_prefix = " └── " if is_last_dir else "│ └── " if is_last_file else ("│ ├── " if not is_last_dir else " ├── ") + if is_last_dir: + file_prefix = " └── " if is_last_file else " ├── " + else: + file_prefix = "│ └── " if is_last_file else "│ ├── " print(f"{file_prefix}{file}") except PermissionError: diff --git a/krkn/rollback/config.py b/krkn/rollback/config.py index 03455c5cf..b37b0b17b 100644 --- a/krkn/rollback/config.py +++ b/krkn/rollback/config.py @@ -1,6 +1,22 @@ +#!/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. + from __future__ import annotations -from dataclasses import dataclass +from dataclasses import dataclass, field from typing import Callable, TYPE_CHECKING, Optional from typing_extensions import TypeAlias import time @@ -19,14 +35,6 @@ ] -if TYPE_CHECKING: - from krkn_lib.telemetry.ocp import KrknTelemetryOpenshift - -RollbackCallable: TypeAlias = Callable[ - ["RollbackContent", "KrknTelemetryOpenshift"], None -] - - class SingletonMeta(type): _instances = {} @@ -227,8 +235,8 @@ def search_rollback_version_files(cls, run_uuid: str | None = None, scenario_typ class Version: scenario_type: str rollback_context: RollbackContext - timestamp: int = time.time_ns() # Get current timestamp in nanoseconds - hash_suffix: str = get_random_string(8) # Generate a random string of 8 characters + timestamp: int = field(default_factory=time.time_ns) + hash_suffix: str = field(default_factory=lambda: get_random_string(8)) @property def version_file_name(self) -> str: diff --git a/krkn/rollback/handler.py b/krkn/rollback/handler.py index cd6712014..ec402f9a6 100644 --- a/krkn/rollback/handler.py +++ b/krkn/rollback/handler.py @@ -1,3 +1,19 @@ +#!/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. + from __future__ import annotations import logging @@ -131,9 +147,9 @@ def execute_rollback_version_files( :param scenario_type: Type of the scenario being rolled back. :param ignore_auto_rollback_config: Flag to ignore auto rollback configuration. Will be set to True for manual execute-rollback calls. """ - if not ignore_auto_rollback_config and RollbackConfig().auto is False: - logger.warning(f"Auto rollback is disabled, skipping execution for run_uuid={run_uuid or '*'}, scenario_type={scenario_type or '*'}") - return + if not ignore_auto_rollback_config and RollbackConfig().auto == False: + logger.warning(f"Auto rollback is disabled, skipping execution for run_uuid={run_uuid or '*'}, scenario_type={scenario_type or '*'}") + return # Get the rollback versions directory version_files = RollbackConfig.search_rollback_version_files(run_uuid, scenario_type) diff --git a/krkn/rollback/serialization.py b/krkn/rollback/serialization.py index f59e35497..1213e1559 100644 --- a/krkn/rollback/serialization.py +++ b/krkn/rollback/serialization.py @@ -1,3 +1,19 @@ +#!/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. + import inspect import os import logging diff --git a/krkn/rollback/signal.py b/krkn/rollback/signal.py index 54ac13e10..f00c2e201 100644 --- a/krkn/rollback/signal.py +++ b/krkn/rollback/signal.py @@ -1,3 +1,19 @@ +#!/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. + from typing import Dict, Any, Optional import threading import signal @@ -26,7 +42,7 @@ def _set_context(cls, run_uuid: str, scenario_type: str, telemetry_ocp: KrknTele cls._local.run_uuid = run_uuid cls._local.scenario_type = scenario_type cls._local.telemetry_ocp = telemetry_ocp - logger.debug(f"Set signal context set for thread {threading.current_thread().name} - run_uuid={run_uuid}, scenario_type={scenario_type}") + logger.debug(f"Signal context set for thread {threading.current_thread().name} - run_uuid={run_uuid}, scenario_type={scenario_type}") @classmethod def _get_context(cls) -> tuple[Optional[str], Optional[str], Optional[KrknTelemetryOpenshift]]: diff --git a/krkn/scenario_plugins/__init__.py b/krkn/scenario_plugins/__init__.py index e69de29bb..798fe911f 100644 --- a/krkn/scenario_plugins/__init__.py +++ b/krkn/scenario_plugins/__init__.py @@ -0,0 +1,16 @@ +#!/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. + diff --git a/krkn/scenario_plugins/abstract_scenario_plugin.py b/krkn/scenario_plugins/abstract_scenario_plugin.py index 291822db5..8995fcc32 100644 --- a/krkn/scenario_plugins/abstract_scenario_plugin.py +++ b/krkn/scenario_plugins/abstract_scenario_plugin.py @@ -1,3 +1,19 @@ +#!/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. + import logging import time from abc import ABC, abstractmethod @@ -40,11 +56,10 @@ def run( :param run_uuid: the uuid of the chaos run generated by krkn for every single run :param scenario: the config file of the scenario that is currently executed - :param krkn_config: the full dictionary representation of the `config.yaml` :param lib_telemetry: it is a composite object of all the krkn-lib objects and methods needed by a krkn plugin to run. :param scenario_telemetry: the `ScenarioTelemetry` object of the scenario that is currently executed - :return: 0 if the scenario suceeded 1 if failed + :return: 0 if the scenario succeeded 1 if failed """ pass diff --git a/krkn/scenario_plugins/application_outage/__init__.py b/krkn/scenario_plugins/application_outage/__init__.py index e69de29bb..798fe911f 100644 --- a/krkn/scenario_plugins/application_outage/__init__.py +++ b/krkn/scenario_plugins/application_outage/__init__.py @@ -0,0 +1,16 @@ +#!/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. + diff --git a/krkn/scenario_plugins/application_outage/application_outage_scenario_plugin.py b/krkn/scenario_plugins/application_outage/application_outage_scenario_plugin.py index a7c0d51ba..08f400d43 100644 --- a/krkn/scenario_plugins/application_outage/application_outage_scenario_plugin.py +++ b/krkn/scenario_plugins/application_outage/application_outage_scenario_plugin.py @@ -1,3 +1,19 @@ +#!/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. + import logging import time import yaml diff --git a/krkn/scenario_plugins/container/__init__.py b/krkn/scenario_plugins/container/__init__.py index e69de29bb..798fe911f 100644 --- a/krkn/scenario_plugins/container/__init__.py +++ b/krkn/scenario_plugins/container/__init__.py @@ -0,0 +1,16 @@ +#!/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. + diff --git a/krkn/scenario_plugins/container/container_scenario_plugin.py b/krkn/scenario_plugins/container/container_scenario_plugin.py index e079f6b6c..f2640bd62 100644 --- a/krkn/scenario_plugins/container/container_scenario_plugin.py +++ b/krkn/scenario_plugins/container/container_scenario_plugin.py @@ -1,3 +1,19 @@ +#!/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. + import logging import random import time @@ -225,7 +241,8 @@ def check_failed_containers( container_ready.append(killed_container) if len(container_ready) != 0: for item in container_ready: - killed_container_list = killed_container_list.remove(item) + killed_container_list.remove(item) + container_ready = [] if killed_container_list is None or len(killed_container_list) == 0: return [] timer += 5 diff --git a/krkn/scenario_plugins/hogs/__init__.py b/krkn/scenario_plugins/hogs/__init__.py index e69de29bb..798fe911f 100644 --- a/krkn/scenario_plugins/hogs/__init__.py +++ b/krkn/scenario_plugins/hogs/__init__.py @@ -0,0 +1,16 @@ +#!/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. + diff --git a/krkn/scenario_plugins/hogs/hogs_scenario_plugin.py b/krkn/scenario_plugins/hogs/hogs_scenario_plugin.py index 929d68751..06e9b9f84 100644 --- a/krkn/scenario_plugins/hogs/hogs_scenario_plugin.py +++ b/krkn/scenario_plugins/hogs/hogs_scenario_plugin.py @@ -1,3 +1,19 @@ +#!/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. + import copy import logging import queue @@ -33,13 +49,14 @@ def run(self, run_uuid: str, scenario: str, lib_telemetry: KrknTelemetryOpenshif # Get node-name if provided node_name = scenario.get('node-name') - has_selector = True + has_selector = False if not scenario_config.node_selector or not re.match("^.+=.*$", scenario_config.node_selector): if scenario_config.node_selector: logging.warning(f"node selector {scenario_config.node_selector} not in right format (key=value)") node_selector = "" else: node_selector = scenario_config.node_selector + has_selector = True if node_name: logging.info(f"Using specific node: {node_name}") diff --git a/krkn/scenario_plugins/kubevirt_vm_outage/__init__.py b/krkn/scenario_plugins/kubevirt_vm_outage/__init__.py index e69de29bb..798fe911f 100644 --- a/krkn/scenario_plugins/kubevirt_vm_outage/__init__.py +++ b/krkn/scenario_plugins/kubevirt_vm_outage/__init__.py @@ -0,0 +1,16 @@ +#!/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. + diff --git a/krkn/scenario_plugins/kubevirt_vm_outage/kubevirt_vm_outage_scenario_plugin.py b/krkn/scenario_plugins/kubevirt_vm_outage/kubevirt_vm_outage_scenario_plugin.py index f8e30779d..066f469ff 100644 --- a/krkn/scenario_plugins/kubevirt_vm_outage/kubevirt_vm_outage_scenario_plugin.py +++ b/krkn/scenario_plugins/kubevirt_vm_outage/kubevirt_vm_outage_scenario_plugin.py @@ -1,3 +1,19 @@ +#!/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. + import logging import time from typing import Dict, Any diff --git a/krkn/scenario_plugins/managed_cluster/__init__.py b/krkn/scenario_plugins/managed_cluster/__init__.py index e69de29bb..798fe911f 100644 --- a/krkn/scenario_plugins/managed_cluster/__init__.py +++ b/krkn/scenario_plugins/managed_cluster/__init__.py @@ -0,0 +1,16 @@ +#!/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. + diff --git a/krkn/scenario_plugins/managed_cluster/common_functions.py b/krkn/scenario_plugins/managed_cluster/common_functions.py index 15e73c13d..e9e993b8b 100644 --- a/krkn/scenario_plugins/managed_cluster/common_functions.py +++ b/krkn/scenario_plugins/managed_cluster/common_functions.py @@ -1,3 +1,19 @@ +#!/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. + import random import logging from krkn_lib.k8s import KrknKubernetes diff --git a/krkn/scenario_plugins/managed_cluster/managed_cluster_scenario_plugin.py b/krkn/scenario_plugins/managed_cluster/managed_cluster_scenario_plugin.py index 666c0f13c..7ce9c9926 100644 --- a/krkn/scenario_plugins/managed_cluster/managed_cluster_scenario_plugin.py +++ b/krkn/scenario_plugins/managed_cluster/managed_cluster_scenario_plugin.py @@ -1,3 +1,19 @@ +#!/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. + import logging import yaml diff --git a/krkn/scenario_plugins/managed_cluster/scenarios.py b/krkn/scenario_plugins/managed_cluster/scenarios.py index 5e22a31e3..82bbc942d 100644 --- a/krkn/scenario_plugins/managed_cluster/scenarios.py +++ b/krkn/scenario_plugins/managed_cluster/scenarios.py @@ -1,3 +1,19 @@ +#!/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. + from jinja2 import Environment, FileSystemLoader import os import time diff --git a/krkn/scenario_plugins/native/__init__.py b/krkn/scenario_plugins/native/__init__.py index e69de29bb..798fe911f 100644 --- a/krkn/scenario_plugins/native/__init__.py +++ b/krkn/scenario_plugins/native/__init__.py @@ -0,0 +1,16 @@ +#!/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. + diff --git a/krkn/scenario_plugins/native/native_scenario_plugin.py b/krkn/scenario_plugins/native/native_scenario_plugin.py index 7f3611213..5bdc86b63 100644 --- a/krkn/scenario_plugins/native/native_scenario_plugin.py +++ b/krkn/scenario_plugins/native/native_scenario_plugin.py @@ -1,3 +1,19 @@ +#!/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. + from krkn.scenario_plugins.abstract_scenario_plugin import AbstractScenarioPlugin from krkn.scenario_plugins.native.plugins import PLUGINS from krkn_lib.models.telemetry import ScenarioTelemetry @@ -20,6 +36,7 @@ def run( PLUGINS.run( scenario, lib_telemetry.get_lib_kubernetes().get_kubeconfig_path(), + lib_telemetry.get_telemetry_config().get("kraken_config", ""), run_uuid, ) diff --git a/krkn/scenario_plugins/native/network/ingress_shaping.py b/krkn/scenario_plugins/native/network/ingress_shaping.py index afc71b5e2..a3fef98af 100644 --- a/krkn/scenario_plugins/native/network/ingress_shaping.py +++ b/krkn/scenario_plugins/native/network/ingress_shaping.py @@ -1,3 +1,19 @@ +#!/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. + from dataclasses import dataclass, field import yaml import logging diff --git a/krkn/scenario_plugins/native/network/kubernetes_functions.py b/krkn/scenario_plugins/native/network/kubernetes_functions.py index ff91d5296..e595ab881 100644 --- a/krkn/scenario_plugins/native/network/kubernetes_functions.py +++ b/krkn/scenario_plugins/native/network/kubernetes_functions.py @@ -1,3 +1,19 @@ +#!/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. + from kubernetes import config, client from kubernetes.client.rest import ApiException from kubernetes.stream import stream diff --git a/krkn/scenario_plugins/native/plugins.py b/krkn/scenario_plugins/native/plugins.py index 96b050d98..ca9dcf6dc 100644 --- a/krkn/scenario_plugins/native/plugins.py +++ b/krkn/scenario_plugins/native/plugins.py @@ -1,3 +1,19 @@ +#!/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. + import dataclasses import json import logging @@ -49,7 +65,7 @@ def __init__(self, steps: List[PluginStep]): def unserialize_scenario(self, file: str) -> Any: return serialization.load_from_file(abspath(file)) - def run(self, file: str, kubeconfig_path: str, run_uuid: str): + def run(self, file: str, kubeconfig_path: str, kraken_config: str, run_uuid: str): """ Run executes a series of steps """ @@ -93,6 +109,8 @@ def run(self, file: str, kubeconfig_path: str, run_uuid: str): unserialized_input = step.schema.input.unserialize(entry["config"]) if "kubeconfig_path" in step.schema.input.properties: unserialized_input.kubeconfig_path = kubeconfig_path + if "kraken_config" in step.schema.input.properties: + unserialized_input.kraken_config = kraken_config output_id, output_data = step.schema( params=unserialized_input, run_id=run_uuid ) diff --git a/krkn/scenario_plugins/native/pod_network_outage/kubernetes_functions.py b/krkn/scenario_plugins/native/pod_network_outage/kubernetes_functions.py index aaa4b4e76..fed1faf59 100644 --- a/krkn/scenario_plugins/native/pod_network_outage/kubernetes_functions.py +++ b/krkn/scenario_plugins/native/pod_network_outage/kubernetes_functions.py @@ -1,3 +1,19 @@ +#!/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. + from kubernetes import config, client from kubernetes.client.rest import ApiException from kubernetes.stream import stream diff --git a/krkn/scenario_plugins/native/pod_network_outage/pod_network_outage_plugin.py b/krkn/scenario_plugins/native/pod_network_outage/pod_network_outage_plugin.py index 80dd3df43..f489f0e30 100755 --- a/krkn/scenario_plugins/native/pod_network_outage/pod_network_outage_plugin.py +++ b/krkn/scenario_plugins/native/pod_network_outage/pod_network_outage_plugin.py @@ -1,4 +1,19 @@ -#!/usr/bin/env python3 +#!/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. + import sys import os import typing diff --git a/krkn/scenario_plugins/native/run_python_plugin.py b/krkn/scenario_plugins/native/run_python_plugin.py index 357cf7fbb..d99cc6b82 100644 --- a/krkn/scenario_plugins/native/run_python_plugin.py +++ b/krkn/scenario_plugins/native/run_python_plugin.py @@ -1,3 +1,19 @@ +#!/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. + import dataclasses import subprocess import sys diff --git a/krkn/scenario_plugins/network_chaos/__init__.py b/krkn/scenario_plugins/network_chaos/__init__.py index e69de29bb..798fe911f 100644 --- a/krkn/scenario_plugins/network_chaos/__init__.py +++ b/krkn/scenario_plugins/network_chaos/__init__.py @@ -0,0 +1,16 @@ +#!/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. + diff --git a/krkn/scenario_plugins/network_chaos/network_chaos_scenario_plugin.py b/krkn/scenario_plugins/network_chaos/network_chaos_scenario_plugin.py index 80b422e86..c46e408ad 100644 --- a/krkn/scenario_plugins/network_chaos/network_chaos_scenario_plugin.py +++ b/krkn/scenario_plugins/network_chaos/network_chaos_scenario_plugin.py @@ -1,3 +1,19 @@ +#!/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. + import logging import os import random diff --git a/krkn/scenario_plugins/network_chaos_ng/__init__.py b/krkn/scenario_plugins/network_chaos_ng/__init__.py index e69de29bb..798fe911f 100644 --- a/krkn/scenario_plugins/network_chaos_ng/__init__.py +++ b/krkn/scenario_plugins/network_chaos_ng/__init__.py @@ -0,0 +1,16 @@ +#!/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. + diff --git a/krkn/scenario_plugins/network_chaos_ng/models.py b/krkn/scenario_plugins/network_chaos_ng/models.py index 41734143b..cf7ba5d25 100644 --- a/krkn/scenario_plugins/network_chaos_ng/models.py +++ b/krkn/scenario_plugins/network_chaos_ng/models.py @@ -1,3 +1,19 @@ +#!/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. + import re from dataclasses import dataclass from enum import Enum diff --git a/krkn/scenario_plugins/network_chaos_ng/modules/__init__.py b/krkn/scenario_plugins/network_chaos_ng/modules/__init__.py index e69de29bb..798fe911f 100644 --- a/krkn/scenario_plugins/network_chaos_ng/modules/__init__.py +++ b/krkn/scenario_plugins/network_chaos_ng/modules/__init__.py @@ -0,0 +1,16 @@ +#!/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. + diff --git a/krkn/scenario_plugins/network_chaos_ng/modules/abstract_network_chaos_module.py b/krkn/scenario_plugins/network_chaos_ng/modules/abstract_network_chaos_module.py index 8241b0a8c..e1d694ef7 100644 --- a/krkn/scenario_plugins/network_chaos_ng/modules/abstract_network_chaos_module.py +++ b/krkn/scenario_plugins/network_chaos_ng/modules/abstract_network_chaos_module.py @@ -1,3 +1,19 @@ +#!/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. + import abc import logging import queue diff --git a/krkn/scenario_plugins/network_chaos_ng/modules/node_network_chaos.py b/krkn/scenario_plugins/network_chaos_ng/modules/node_network_chaos.py index 0a73417c9..dc80e3103 100644 --- a/krkn/scenario_plugins/network_chaos_ng/modules/node_network_chaos.py +++ b/krkn/scenario_plugins/network_chaos_ng/modules/node_network_chaos.py @@ -1,3 +1,19 @@ +#!/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. + import queue import time from typing import Tuple diff --git a/krkn/scenario_plugins/network_chaos_ng/modules/node_network_filter.py b/krkn/scenario_plugins/network_chaos_ng/modules/node_network_filter.py index 4e79a0600..b789d72b9 100644 --- a/krkn/scenario_plugins/network_chaos_ng/modules/node_network_filter.py +++ b/krkn/scenario_plugins/network_chaos_ng/modules/node_network_filter.py @@ -1,3 +1,19 @@ +#!/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. + import queue import time from typing import Tuple diff --git a/krkn/scenario_plugins/network_chaos_ng/modules/pod_network_chaos.py b/krkn/scenario_plugins/network_chaos_ng/modules/pod_network_chaos.py index caf8db12b..b92312695 100644 --- a/krkn/scenario_plugins/network_chaos_ng/modules/pod_network_chaos.py +++ b/krkn/scenario_plugins/network_chaos_ng/modules/pod_network_chaos.py @@ -1,3 +1,19 @@ +#!/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. + import queue import time from typing import Tuple diff --git a/krkn/scenario_plugins/network_chaos_ng/modules/pod_network_filter.py b/krkn/scenario_plugins/network_chaos_ng/modules/pod_network_filter.py index 8ecf8ddb0..3a232c007 100644 --- a/krkn/scenario_plugins/network_chaos_ng/modules/pod_network_filter.py +++ b/krkn/scenario_plugins/network_chaos_ng/modules/pod_network_filter.py @@ -1,3 +1,19 @@ +#!/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. + import queue import time from typing import Tuple diff --git a/krkn/scenario_plugins/network_chaos_ng/modules/utils.py b/krkn/scenario_plugins/network_chaos_ng/modules/utils.py index c92e9df4a..e9c0a0542 100644 --- a/krkn/scenario_plugins/network_chaos_ng/modules/utils.py +++ b/krkn/scenario_plugins/network_chaos_ng/modules/utils.py @@ -1,3 +1,19 @@ +#!/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. + import logging import os from typing import Tuple diff --git a/krkn/scenario_plugins/network_chaos_ng/modules/utils_network_chaos.py b/krkn/scenario_plugins/network_chaos_ng/modules/utils_network_chaos.py index 689ccb287..a1d022157 100644 --- a/krkn/scenario_plugins/network_chaos_ng/modules/utils_network_chaos.py +++ b/krkn/scenario_plugins/network_chaos_ng/modules/utils_network_chaos.py @@ -1,3 +1,19 @@ +#!/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. + import subprocess import logging from typing import Optional diff --git a/krkn/scenario_plugins/network_chaos_ng/modules/utils_network_filter.py b/krkn/scenario_plugins/network_chaos_ng/modules/utils_network_filter.py index 7677e086a..f2eab1943 100644 --- a/krkn/scenario_plugins/network_chaos_ng/modules/utils_network_filter.py +++ b/krkn/scenario_plugins/network_chaos_ng/modules/utils_network_filter.py @@ -1,3 +1,19 @@ +#!/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. + from typing import Tuple from krkn_lib.k8s import KrknKubernetes diff --git a/krkn/scenario_plugins/network_chaos_ng/network_chaos_factory.py b/krkn/scenario_plugins/network_chaos_ng/network_chaos_factory.py index 3dd043268..c08be253a 100644 --- a/krkn/scenario_plugins/network_chaos_ng/network_chaos_factory.py +++ b/krkn/scenario_plugins/network_chaos_ng/network_chaos_factory.py @@ -1,3 +1,19 @@ +#!/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. + from krkn_lib.telemetry.ocp import KrknTelemetryOpenshift from krkn.scenario_plugins.network_chaos_ng.models import ( diff --git a/krkn/scenario_plugins/network_chaos_ng/network_chaos_ng_scenario_plugin.py b/krkn/scenario_plugins/network_chaos_ng/network_chaos_ng_scenario_plugin.py index eabedcf41..9ab9fe364 100644 --- a/krkn/scenario_plugins/network_chaos_ng/network_chaos_ng_scenario_plugin.py +++ b/krkn/scenario_plugins/network_chaos_ng/network_chaos_ng_scenario_plugin.py @@ -1,3 +1,19 @@ +#!/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. + import logging import queue import random @@ -51,19 +67,15 @@ def run( f"with target type {network_chaos_type}" ) - if ( - network_chaos_config.instance_count != 0 - and network_chaos_config.instance_count > len(targets) - ): + if network_chaos_config.instance_count != 0 and len(targets) > network_chaos_config.instance_count: targets = random.sample( targets, network_chaos_config.instance_count ) - if network_chaos_config.execution == "parallel": self.run_parallel(targets, network_chaos) else: self.run_serial(targets, network_chaos) - if len(config) > 1: + if len(scenario_config) > 1: logging.info( f"waiting {network_chaos_config.wait_duration} seconds before running the next " f"Network Chaos NG Module" diff --git a/krkn/scenario_plugins/node_actions/__init__.py b/krkn/scenario_plugins/node_actions/__init__.py index e69de29bb..798fe911f 100644 --- a/krkn/scenario_plugins/node_actions/__init__.py +++ b/krkn/scenario_plugins/node_actions/__init__.py @@ -0,0 +1,16 @@ +#!/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. + diff --git a/krkn/scenario_plugins/node_actions/abstract_node_scenarios.py b/krkn/scenario_plugins/node_actions/abstract_node_scenarios.py index a86f8e4f6..6bbcfc1cf 100644 --- a/krkn/scenario_plugins/node_actions/abstract_node_scenarios.py +++ b/krkn/scenario_plugins/node_actions/abstract_node_scenarios.py @@ -1,3 +1,19 @@ +#!/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. + import sys import logging import time diff --git a/krkn/scenario_plugins/node_actions/alibaba_node_scenarios.py b/krkn/scenario_plugins/node_actions/alibaba_node_scenarios.py index 39889844d..e9a9adfb6 100644 --- a/krkn/scenario_plugins/node_actions/alibaba_node_scenarios.py +++ b/krkn/scenario_plugins/node_actions/alibaba_node_scenarios.py @@ -1,3 +1,19 @@ +#!/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. + import sys import time import logging diff --git a/krkn/scenario_plugins/node_actions/aws_node_scenarios.py b/krkn/scenario_plugins/node_actions/aws_node_scenarios.py index e11f837bb..2ce01a51c 100644 --- a/krkn/scenario_plugins/node_actions/aws_node_scenarios.py +++ b/krkn/scenario_plugins/node_actions/aws_node_scenarios.py @@ -1,3 +1,19 @@ +#!/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. + import sys import time import boto3 diff --git a/krkn/scenario_plugins/node_actions/az_node_scenarios.py b/krkn/scenario_plugins/node_actions/az_node_scenarios.py index 3caa427c1..7876df0c3 100644 --- a/krkn/scenario_plugins/node_actions/az_node_scenarios.py +++ b/krkn/scenario_plugins/node_actions/az_node_scenarios.py @@ -1,3 +1,19 @@ +#!/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. + import time import os import logging diff --git a/krkn/scenario_plugins/node_actions/bm_node_scenarios.py b/krkn/scenario_plugins/node_actions/bm_node_scenarios.py index f9667c702..767f5aaf0 100644 --- a/krkn/scenario_plugins/node_actions/bm_node_scenarios.py +++ b/krkn/scenario_plugins/node_actions/bm_node_scenarios.py @@ -1,3 +1,19 @@ +#!/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. + import krkn.scenario_plugins.node_actions.common_node_functions as nodeaction from krkn.scenario_plugins.node_actions.abstract_node_scenarios import ( abstract_node_scenarios, diff --git a/krkn/scenario_plugins/node_actions/common_node_functions.py b/krkn/scenario_plugins/node_actions/common_node_functions.py index e4443393b..b263e8202 100644 --- a/krkn/scenario_plugins/node_actions/common_node_functions.py +++ b/krkn/scenario_plugins/node_actions/common_node_functions.py @@ -1,3 +1,19 @@ +#!/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. + import time import random import logging diff --git a/krkn/scenario_plugins/node_actions/docker_node_scenarios.py b/krkn/scenario_plugins/node_actions/docker_node_scenarios.py index 9731883ac..02d37221d 100644 --- a/krkn/scenario_plugins/node_actions/docker_node_scenarios.py +++ b/krkn/scenario_plugins/node_actions/docker_node_scenarios.py @@ -1,3 +1,19 @@ +#!/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. + import krkn.scenario_plugins.node_actions.common_node_functions as nodeaction from krkn.scenario_plugins.node_actions.abstract_node_scenarios import ( abstract_node_scenarios, diff --git a/krkn/scenario_plugins/node_actions/gcp_node_scenarios.py b/krkn/scenario_plugins/node_actions/gcp_node_scenarios.py index cf7d60443..197e8faf2 100644 --- a/krkn/scenario_plugins/node_actions/gcp_node_scenarios.py +++ b/krkn/scenario_plugins/node_actions/gcp_node_scenarios.py @@ -1,3 +1,19 @@ +#!/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. + import time import logging import google.auth diff --git a/krkn/scenario_plugins/node_actions/general_cloud_node_scenarios.py b/krkn/scenario_plugins/node_actions/general_cloud_node_scenarios.py index 830b7d35b..ebf072a58 100644 --- a/krkn/scenario_plugins/node_actions/general_cloud_node_scenarios.py +++ b/krkn/scenario_plugins/node_actions/general_cloud_node_scenarios.py @@ -1,3 +1,19 @@ +#!/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. + import logging from krkn.scenario_plugins.node_actions.abstract_node_scenarios import ( abstract_node_scenarios, diff --git a/krkn/scenario_plugins/node_actions/ibmcloud_node_scenarios.py b/krkn/scenario_plugins/node_actions/ibmcloud_node_scenarios.py index 039d766a0..3a88d7742 100644 --- a/krkn/scenario_plugins/node_actions/ibmcloud_node_scenarios.py +++ b/krkn/scenario_plugins/node_actions/ibmcloud_node_scenarios.py @@ -1,4 +1,19 @@ #!/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. + import time import typing from os import environ diff --git a/krkn/scenario_plugins/node_actions/ibmcloud_power_node_scenarios.py b/krkn/scenario_plugins/node_actions/ibmcloud_power_node_scenarios.py index 80c478be0..836feb81f 100644 --- a/krkn/scenario_plugins/node_actions/ibmcloud_power_node_scenarios.py +++ b/krkn/scenario_plugins/node_actions/ibmcloud_power_node_scenarios.py @@ -1,4 +1,19 @@ #!/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. + import time from os import environ from dataclasses import dataclass diff --git a/krkn/scenario_plugins/node_actions/node_actions_scenario_plugin.py b/krkn/scenario_plugins/node_actions/node_actions_scenario_plugin.py index d981e9640..2a7453a35 100644 --- a/krkn/scenario_plugins/node_actions/node_actions_scenario_plugin.py +++ b/krkn/scenario_plugins/node_actions/node_actions_scenario_plugin.py @@ -1,3 +1,21 @@ +#!/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. + +import base64 +import json import logging import time from multiprocessing.pool import ThreadPool @@ -8,9 +26,11 @@ from krkn_lib.models.telemetry import ScenarioTelemetry from krkn_lib.models.k8s import AffectedNodeStatus from krkn_lib.telemetry.ocp import KrknTelemetryOpenshift -from krkn_lib.utils import get_yaml_item_value, log_exception +from krkn_lib.utils import get_yaml_item_value -from krkn import cerberus, utils +from krkn import cerberus +from krkn.rollback.config import RollbackContent +from krkn.rollback.handler import set_rollback_context_decorator from krkn.scenario_plugins.abstract_scenario_plugin import AbstractScenarioPlugin from krkn.scenario_plugins.node_actions import common_node_functions from krkn.scenario_plugins.node_actions.aws_node_scenarios import aws_node_scenarios @@ -28,14 +48,24 @@ from krkn.scenario_plugins.node_actions.ibmcloud_node_scenarios import ( ibm_node_scenarios, ) - from krkn.scenario_plugins.node_actions.ibmcloud_power_node_scenarios import ( - ibmcloud_power_node_scenarios, + ibmcloud_power_node_scenarios, ) + node_general = False +# Maps each reversible action to its compensating (inverse) action. +# Only these actions register a rollback entry; irreversible actions +# (terminate, crash, reboot, disk-detach) are intentionally excluded. +REVERSIBLE_ACTIONS = { + "node_stop_scenario": "node_start_scenario", + "stop_kubelet_scenario": "restart_kubelet_scenario", +} + class NodeActionsScenarioPlugin(AbstractScenarioPlugin): + + @set_rollback_context_decorator def run( self, run_uuid: str, @@ -67,6 +97,157 @@ def run( return 1 return 0 + def _register_rollback( + self, + action: str, + node: str, + node_scenario: dict, + ) -> None: + """ + Register a rollback callable for a reversible node action. + + Only actions present in REVERSIBLE_ACTIONS are registered. All data + needed by the rollback callable is encoded as base64 JSON in + ``resource_identifier`` so the serialized rollback file is fully + self-contained and requires no external state. + + This must be called *before* the action is executed so that a rollback + entry exists even if the action itself raises an exception mid-flight. + + :param action: The action about to be performed (e.g. "node_stop_scenario"). + :param node: The target node name. + :param node_scenario: The full scenario config dict from the YAML file. + """ + if action not in REVERSIBLE_ACTIONS: + return + + logging.info( + "Registering rollback for action '%s' on node '%s'", action, node + ) + + # Encode all data the rollback callable needs into resource_identifier. + # Explicit type casts guard against get_yaml_item_value returning a + # non-serialisable type in unusual environments (e.g. unit tests). + payload = { + "node": node, + "cloud_type": str(node_scenario.get("cloud_type", "generic")), + "reverse_action": REVERSIBLE_ACTIONS[action], + "timeout": int(get_yaml_item_value(node_scenario, "timeout", 120)), + "poll_interval": int(get_yaml_item_value(node_scenario, "poll_interval", 15)), + "disable_ssl_verification": bool( + get_yaml_item_value(node_scenario, "disable_ssl_verification", True) + ), + } + resource_identifier = base64.b64encode( + json.dumps(payload).encode() + ).decode() + + self.rollback_handler.set_rollback_callable( + NodeActionsScenarioPlugin.rollback_node_action, + RollbackContent(resource_identifier=resource_identifier), + ) + + @staticmethod + def rollback_node_action( + rollback_content: RollbackContent, + lib_telemetry: KrknTelemetryOpenshift, + ) -> None: + """ + Execute the compensating action for a previously performed node action. + + The ``resource_identifier`` field of *rollback_content* holds a + base64-encoded JSON payload written by ``_register_rollback()``. This + method decodes it, reconstructs the appropriate cloud-provider scenario + object, and calls the inverse action (e.g. ``node_start_scenario`` for + a stopped node, ``restart_kubelet_scenario`` for a stopped kubelet). + + WHY local imports? + The rollback framework (``serialization.py`` + ``version_template.j2``) + serialises this function's source verbatim into a standalone Python + script. That script only has ``logging``, ``os``, and ``krkn_lib`` + available at module level. Every other name used here must therefore + be imported *inside* the function body so the serialised script is + self-contained and executable without the rest of krkn on the path. + + :param rollback_content: Contains the base64-encoded node/action metadata. + :param lib_telemetry: Provides access to the Kubernetes client. + """ + # --- local imports (required for serialisation, see docstring) --- + import base64 + import json + from krkn_lib.models.k8s import AffectedNodeStatus + from krkn.scenario_plugins.node_actions.aws_node_scenarios import aws_node_scenarios + from krkn.scenario_plugins.node_actions.az_node_scenarios import azure_node_scenarios + from krkn.scenario_plugins.node_actions.docker_node_scenarios import docker_node_scenarios + from krkn.scenario_plugins.node_actions.gcp_node_scenarios import gcp_node_scenarios + from krkn.scenario_plugins.node_actions.general_cloud_node_scenarios import general_node_scenarios + from krkn.scenario_plugins.node_actions.vmware_node_scenarios import vmware_node_scenarios + from krkn.scenario_plugins.node_actions.ibmcloud_node_scenarios import ibm_node_scenarios + from krkn.scenario_plugins.node_actions.ibmcloud_power_node_scenarios import ibmcloud_power_node_scenarios + + try: + payload = json.loads( + base64.b64decode(rollback_content.resource_identifier).decode() + ) + node = payload["node"] + cloud_type = payload.get("cloud_type", "generic") + reverse_action = payload["reverse_action"] + timeout = payload.get("timeout", 120) + poll_interval = payload.get("poll_interval", 15) + disable_ssl = payload.get("disable_ssl_verification", True) + + logging.info( + "Rollback triggered: executing '%s' on node '%s' (cloud_type='%s')", + reverse_action, node, cloud_type, + ) + + kubecli = lib_telemetry.get_lib_kubernetes() + affected_nodes_status = AffectedNodeStatus() + + # Reconstruct the cloud-provider scenario object. + # Unknown / generic cloud types all fall through to general_node_scenarios. + cloud_type_lower = cloud_type.lower() + known_cloud_types = { + "aws", "gcp", "azure", "az", "docker", + "vsphere", "vmware", "ibm", "ibmcloud", + "ibmpower", "ibmcloudpower", + } + if cloud_type_lower not in known_cloud_types: + scenario_obj = general_node_scenarios(kubecli, True, affected_nodes_status) + elif cloud_type_lower == "aws": + scenario_obj = aws_node_scenarios(kubecli, True, affected_nodes_status) + elif cloud_type_lower == "gcp": + scenario_obj = gcp_node_scenarios(kubecli, True, affected_nodes_status) + elif cloud_type_lower in ("azure", "az"): + scenario_obj = azure_node_scenarios(kubecli, True, affected_nodes_status) + elif cloud_type_lower == "docker": + scenario_obj = docker_node_scenarios(kubecli, True, affected_nodes_status) + elif cloud_type_lower in ("vsphere", "vmware"): + scenario_obj = vmware_node_scenarios(kubecli, True, affected_nodes_status) + elif cloud_type_lower in ("ibm", "ibmcloud"): + scenario_obj = ibm_node_scenarios(kubecli, True, affected_nodes_status, disable_ssl) + else: # ibmpower / ibmcloudpower + scenario_obj = ibmcloud_power_node_scenarios(kubecli, True, affected_nodes_status, disable_ssl) + + # Execute the compensating action. + if reverse_action == "node_start_scenario": + scenario_obj.node_start_scenario(1, node, timeout, poll_interval) + elif reverse_action == "restart_kubelet_scenario": + scenario_obj.restart_kubelet_scenario(1, node, timeout) + else: + logging.warning( + "Rollback: no handler for reverse action '%s' on node '%s', skipping", + reverse_action, node, + ) + return + + logging.info( + "Rollback completed successfully: '%s' on node '%s'", + reverse_action, node, + ) + except Exception as e: + logging.error("Rollback failed for node action: %s", e) + def get_node_scenario_object(self, node_scenario, kubecli: KrknKubernetes): affected_nodes_status = AffectedNodeStatus() @@ -92,7 +273,6 @@ def get_node_scenario_object(self, node_scenario, kubecli: KrknKubernetes): from krkn.scenario_plugins.node_actions.openstack_node_scenarios import ( openstack_node_scenarios, ) - return openstack_node_scenarios( kubecli, node_action_kube_check, affected_nodes_status ) @@ -110,7 +290,6 @@ def get_node_scenario_object(self, node_scenario, kubecli: KrknKubernetes): from krkn.scenario_plugins.node_actions.alibaba_node_scenarios import ( alibaba_node_scenarios, ) - return alibaba_node_scenarios( kubecli, node_action_kube_check, affected_nodes_status ) @@ -118,7 +297,6 @@ def get_node_scenario_object(self, node_scenario, kubecli: KrknKubernetes): from krkn.scenario_plugins.node_actions.bm_node_scenarios import ( bm_node_scenarios, ) - return bm_node_scenarios( node_scenario.get("bmc_info"), node_scenario.get("bmc_user", None), @@ -142,14 +320,22 @@ def get_node_scenario_object(self, node_scenario, kubecli: KrknKubernetes): node_scenario["cloud_type"].lower() == "ibm" or node_scenario["cloud_type"].lower() == "ibmcloud" ): - disable_ssl_verification = get_yaml_item_value(node_scenario, "disable_ssl_verification", True) - return ibm_node_scenarios(kubecli, node_action_kube_check, affected_nodes_status, disable_ssl_verification) + disable_ssl_verification = get_yaml_item_value( + node_scenario, "disable_ssl_verification", True + ) + return ibm_node_scenarios( + kubecli, node_action_kube_check, affected_nodes_status, disable_ssl_verification + ) elif ( node_scenario["cloud_type"].lower() == "ibmpower" or node_scenario["cloud_type"].lower() == "ibmcloudpower" ): - disable_ssl_verification = get_yaml_item_value(node_scenario, "disable_ssl_verification", True) - return ibmcloud_power_node_scenarios(kubecli, node_action_kube_check, affected_nodes_status, disable_ssl_verification) + disable_ssl_verification = get_yaml_item_value( + node_scenario, "disable_ssl_verification", True + ) + return ibmcloud_power_node_scenarios( + kubecli, node_action_kube_check, affected_nodes_status, disable_ssl_verification + ) else: logging.error( "Cloud type " @@ -174,16 +360,13 @@ def inject_node_scenario( kubecli: KrknKubernetes, scenario_telemetry: ScenarioTelemetry, ): - - # Get the node scenario configurations for setting nodes - instance_kill_count = get_yaml_item_value(node_scenario, "instance_count", 1) node_name = get_yaml_item_value(node_scenario, "node_name", "") label_selector = get_yaml_item_value(node_scenario, "label_selector", "") exclude_label = get_yaml_item_value(node_scenario, "exclude_label", "") parallel_nodes = get_yaml_item_value(node_scenario, "parallel", False) - # Get the node to apply the scenario + # Resolve the target node list if node_name: node_name_list = node_name.split(",") nodes = common_node_functions.get_node_by_name(node_name_list, kubecli) @@ -201,20 +384,22 @@ def inject_node_scenario( ) nodes = [node for node in nodes if node not in exclude_nodes] - # GCP api doesn't support multiprocessing calls, will only actually run 1 + # GCP API doesn't support multiprocessing calls; will only actually run 1. + # NOTE: rollback registration is intentionally done inside run_node() rather + # than here so that each node gets its own rollback entry regardless of + # whether nodes are processed sequentially or in parallel. if parallel_nodes: self.multiprocess_nodes(nodes, node_scenario_object, action, node_scenario) else: for single_node in nodes: self.run_node(single_node, node_scenario_object, action, node_scenario) + affected_nodes_status = node_scenario_object.affected_nodes_status scenario_telemetry.affected_nodes.extend(affected_nodes_status.affected_nodes) def multiprocess_nodes(self, nodes, node_scenario_object, action, node_scenario): try: - # pool object with number of element pool = ThreadPool(processes=len(nodes)) - pool.starmap( self.run_node, zip( @@ -224,13 +409,11 @@ def multiprocess_nodes(self, nodes, node_scenario_object, action, node_scenario) repeat(node_scenario), ), ) - pool.close() except Exception as e: logging.info("Error on pool multiprocessing: " + str(e)) def run_node(self, single_node, node_scenario_object, action, node_scenario): - # Get the scenario specifics for running action nodes run_kill_count = get_yaml_item_value(node_scenario, "runs", 1) duration = get_yaml_item_value(node_scenario, "duration", 120) poll_interval = get_yaml_item_value(node_scenario, "poll_interval", 15) @@ -254,6 +437,12 @@ def run_node(self, single_node, node_scenario_object, action, node_scenario): run_kill_count, single_node, timeout, poll_interval ) elif action == "node_stop_scenario": + # Register rollback *before* stopping so a restart entry exists + # even if the stop call itself raises mid-flight. + self._register_rollback(action, single_node, node_scenario) + logging.info( + "Performing '%s' on node '%s'", action, single_node + ) node_scenario_object.node_stop_scenario( run_kill_count, single_node, timeout, poll_interval ) @@ -282,6 +471,12 @@ def run_node(self, single_node, node_scenario_object, action, node_scenario): run_kill_count, single_node, timeout ) elif action == "stop_kubelet_scenario": + # Register rollback *before* stopping so a restart entry exists + # even if the stop call itself raises mid-flight. + self._register_rollback(action, single_node, node_scenario) + logging.info( + "Performing '%s' on node '%s'", action, single_node + ) node_scenario_object.stop_kubelet_scenario( run_kill_count, single_node, timeout ) diff --git a/krkn/scenario_plugins/node_actions/openstack_node_scenarios.py b/krkn/scenario_plugins/node_actions/openstack_node_scenarios.py index 044bae9bf..bf8f9928e 100644 --- a/krkn/scenario_plugins/node_actions/openstack_node_scenarios.py +++ b/krkn/scenario_plugins/node_actions/openstack_node_scenarios.py @@ -1,3 +1,19 @@ +#!/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. + import sys import time import logging diff --git a/krkn/scenario_plugins/node_actions/vmware_node_scenarios.py b/krkn/scenario_plugins/node_actions/vmware_node_scenarios.py index 20ed23c3f..400b3e9f0 100644 --- a/krkn/scenario_plugins/node_actions/vmware_node_scenarios.py +++ b/krkn/scenario_plugins/node_actions/vmware_node_scenarios.py @@ -1,4 +1,19 @@ #!/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. + import logging import random import sys diff --git a/krkn/scenario_plugins/pod_disruption/__init__.py b/krkn/scenario_plugins/pod_disruption/__init__.py index e69de29bb..798fe911f 100644 --- a/krkn/scenario_plugins/pod_disruption/__init__.py +++ b/krkn/scenario_plugins/pod_disruption/__init__.py @@ -0,0 +1,16 @@ +#!/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. + diff --git a/krkn/scenario_plugins/pod_disruption/models/__init__.py b/krkn/scenario_plugins/pod_disruption/models/__init__.py index e69de29bb..798fe911f 100644 --- a/krkn/scenario_plugins/pod_disruption/models/__init__.py +++ b/krkn/scenario_plugins/pod_disruption/models/__init__.py @@ -0,0 +1,16 @@ +#!/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. + diff --git a/krkn/scenario_plugins/pod_disruption/models/models.py b/krkn/scenario_plugins/pod_disruption/models/models.py index b763fdd50..9ec958dc3 100644 --- a/krkn/scenario_plugins/pod_disruption/models/models.py +++ b/krkn/scenario_plugins/pod_disruption/models/models.py @@ -1,3 +1,19 @@ +#!/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. + from dataclasses import dataclass @dataclass diff --git a/krkn/scenario_plugins/pod_disruption/pod_disruption_scenario_plugin.py b/krkn/scenario_plugins/pod_disruption/pod_disruption_scenario_plugin.py index 66a748916..ab6de1645 100644 --- a/krkn/scenario_plugins/pod_disruption/pod_disruption_scenario_plugin.py +++ b/krkn/scenario_plugins/pod_disruption/pod_disruption_scenario_plugin.py @@ -1,3 +1,19 @@ +#!/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. + import logging import random import time @@ -205,8 +221,9 @@ def killing_pods(self, config: InputParams, kubecli: KrknKubernetes): # region Select target pods try: namespace = config.namespace_pattern - if not namespace: + if not namespace: logging.error('Namespace pattern must be specified') + return 2 pods = self.get_pods(config.name_pattern,config.label_selector,config.namespace_pattern, kubecli, field_selector="status.phase=Running", node_label_selector=config.node_label_selector, node_names=config.node_names) exclude_pods = set() diff --git a/krkn/scenario_plugins/pvc/__init__.py b/krkn/scenario_plugins/pvc/__init__.py index e69de29bb..798fe911f 100644 --- a/krkn/scenario_plugins/pvc/__init__.py +++ b/krkn/scenario_plugins/pvc/__init__.py @@ -0,0 +1,16 @@ +#!/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. + diff --git a/krkn/scenario_plugins/pvc/pvc_scenario_plugin.py b/krkn/scenario_plugins/pvc/pvc_scenario_plugin.py index 6bc1f8ce5..a48ce51ee 100644 --- a/krkn/scenario_plugins/pvc/pvc_scenario_plugin.py +++ b/krkn/scenario_plugins/pvc/pvc_scenario_plugin.py @@ -1,3 +1,19 @@ +#!/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. + import base64 import json import logging @@ -343,8 +359,6 @@ def rollback_temp_file( """ try: namespace = rollback_content.namespace - import base64 # noqa - import json # noqa decoded_data = base64.b64decode(rollback_content.resource_identifier.encode('utf-8')).decode('utf-8') rollback_data = json.loads(decoded_data) pod_name = rollback_data["pod_name"] diff --git a/krkn/scenario_plugins/scenario_plugin_factory.py b/krkn/scenario_plugins/scenario_plugin_factory.py index ec791df59..58cec91ea 100644 --- a/krkn/scenario_plugins/scenario_plugin_factory.py +++ b/krkn/scenario_plugins/scenario_plugin_factory.py @@ -1,3 +1,19 @@ +#!/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. + import importlib import inspect import pkgutil @@ -11,11 +27,9 @@ class ScenarioPluginNotFound(Exception): class ScenarioPluginFactory: - loaded_plugins: dict[str, Any] = {} - failed_plugins: list[Tuple[str, str, str]] = [] - package_name = None - def __init__(self, package_name: str = "krkn.scenario_plugins"): + self.loaded_plugins: dict[str, Any] = {} + self.failed_plugins: list[Tuple[str, str, str]] = [] self.package_name = package_name self.__load_plugins(AbstractScenarioPlugin) diff --git a/krkn/scenario_plugins/service_disruption/__init__.py b/krkn/scenario_plugins/service_disruption/__init__.py index e69de29bb..798fe911f 100644 --- a/krkn/scenario_plugins/service_disruption/__init__.py +++ b/krkn/scenario_plugins/service_disruption/__init__.py @@ -0,0 +1,16 @@ +#!/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. + diff --git a/krkn/scenario_plugins/service_disruption/service_disruption_scenario_plugin.py b/krkn/scenario_plugins/service_disruption/service_disruption_scenario_plugin.py index 5816307b8..437a38a91 100644 --- a/krkn/scenario_plugins/service_disruption/service_disruption_scenario_plugin.py +++ b/krkn/scenario_plugins/service_disruption/service_disruption_scenario_plugin.py @@ -1,3 +1,19 @@ +#!/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. + import logging import random import time diff --git a/krkn/scenario_plugins/service_hijacking/__init__.py b/krkn/scenario_plugins/service_hijacking/__init__.py index e69de29bb..798fe911f 100644 --- a/krkn/scenario_plugins/service_hijacking/__init__.py +++ b/krkn/scenario_plugins/service_hijacking/__init__.py @@ -0,0 +1,16 @@ +#!/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. + diff --git a/krkn/scenario_plugins/service_hijacking/service_hijacking_scenario_plugin.py b/krkn/scenario_plugins/service_hijacking/service_hijacking_scenario_plugin.py index c0e8f7f7c..f5506d9a4 100644 --- a/krkn/scenario_plugins/service_hijacking/service_hijacking_scenario_plugin.py +++ b/krkn/scenario_plugins/service_hijacking/service_hijacking_scenario_plugin.py @@ -1,3 +1,19 @@ +#!/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. + import json import logging import time @@ -139,8 +155,6 @@ def rollback_service_hijacking( """ try: namespace = rollback_content.namespace - import json # noqa - import base64 # noqa # Decode rollback data from resource_identifier decoded_data = base64.b64decode(rollback_content.resource_identifier.encode("utf-8")).decode("utf-8") rollback_data = json.loads(decoded_data) diff --git a/krkn/scenario_plugins/shut_down/__init__.py b/krkn/scenario_plugins/shut_down/__init__.py index e69de29bb..798fe911f 100644 --- a/krkn/scenario_plugins/shut_down/__init__.py +++ b/krkn/scenario_plugins/shut_down/__init__.py @@ -0,0 +1,16 @@ +#!/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. + diff --git a/krkn/scenario_plugins/shut_down/shut_down_scenario_plugin.py b/krkn/scenario_plugins/shut_down/shut_down_scenario_plugin.py index df1373a0e..9d00b3c8b 100644 --- a/krkn/scenario_plugins/shut_down/shut_down_scenario_plugin.py +++ b/krkn/scenario_plugins/shut_down/shut_down_scenario_plugin.py @@ -1,3 +1,19 @@ +#!/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. + import logging import time from multiprocessing.pool import ThreadPool diff --git a/krkn/scenario_plugins/syn_flood/__init__.py b/krkn/scenario_plugins/syn_flood/__init__.py index e69de29bb..798fe911f 100644 --- a/krkn/scenario_plugins/syn_flood/__init__.py +++ b/krkn/scenario_plugins/syn_flood/__init__.py @@ -0,0 +1,16 @@ +#!/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. + diff --git a/krkn/scenario_plugins/syn_flood/syn_flood_scenario_plugin.py b/krkn/scenario_plugins/syn_flood/syn_flood_scenario_plugin.py index 3e4b14d80..668e6b00e 100644 --- a/krkn/scenario_plugins/syn_flood/syn_flood_scenario_plugin.py +++ b/krkn/scenario_plugins/syn_flood/syn_flood_scenario_plugin.py @@ -1,3 +1,19 @@ +#!/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. + import base64 import json import logging @@ -162,8 +178,6 @@ def rollback_syn_flood_pods(rollback_content: RollbackContent, lib_telemetry: Kr """ try: namespace = rollback_content.namespace - import base64 # noqa - import json # noqa pod_names = json.loads(base64.b64decode(rollback_content.resource_identifier.encode('utf-8')).decode('utf-8')) logging.info(f"Rolling back syn flood pods: {pod_names} in namespace: {namespace}") for pod_name in pod_names: diff --git a/krkn/scenario_plugins/time_actions/__init__.py b/krkn/scenario_plugins/time_actions/__init__.py index e69de29bb..798fe911f 100644 --- a/krkn/scenario_plugins/time_actions/__init__.py +++ b/krkn/scenario_plugins/time_actions/__init__.py @@ -0,0 +1,16 @@ +#!/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. + diff --git a/krkn/scenario_plugins/time_actions/time_actions_scenario_plugin.py b/krkn/scenario_plugins/time_actions/time_actions_scenario_plugin.py index 2f7802049..5f3d07514 100644 --- a/krkn/scenario_plugins/time_actions/time_actions_scenario_plugin.py +++ b/krkn/scenario_plugins/time_actions/time_actions_scenario_plugin.py @@ -1,3 +1,19 @@ +#!/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. + import datetime import logging import random diff --git a/krkn/scenario_plugins/zone_outage/__init__.py b/krkn/scenario_plugins/zone_outage/__init__.py index e69de29bb..798fe911f 100644 --- a/krkn/scenario_plugins/zone_outage/__init__.py +++ b/krkn/scenario_plugins/zone_outage/__init__.py @@ -0,0 +1,16 @@ +#!/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. + diff --git a/krkn/scenario_plugins/zone_outage/zone_outage_scenario_plugin.py b/krkn/scenario_plugins/zone_outage/zone_outage_scenario_plugin.py index 68c912026..be16d7ff8 100644 --- a/krkn/scenario_plugins/zone_outage/zone_outage_scenario_plugin.py +++ b/krkn/scenario_plugins/zone_outage/zone_outage_scenario_plugin.py @@ -1,7 +1,23 @@ -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. + import logging import time +import base64 +import json import yaml diff --git a/krkn/tests/__init__.py b/krkn/tests/__init__.py index e69de29bb..798fe911f 100644 --- a/krkn/tests/__init__.py +++ b/krkn/tests/__init__.py @@ -0,0 +1,16 @@ +#!/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. + diff --git a/krkn/tests/test_classes/__init__.py b/krkn/tests/test_classes/__init__.py index bd5758667..d605899a3 100644 --- a/krkn/tests/test_classes/__init__.py +++ b/krkn/tests/test_classes/__init__.py @@ -1,3 +1,19 @@ +#!/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. + from typing import List, Tuple from krkn_lib.models.telemetry import ScenarioTelemetry diff --git a/krkn/tests/test_classes/correct_scenario_plugin.py b/krkn/tests/test_classes/correct_scenario_plugin.py index 7b3d6b6c1..65ea08ea6 100644 --- a/krkn/tests/test_classes/correct_scenario_plugin.py +++ b/krkn/tests/test_classes/correct_scenario_plugin.py @@ -1,3 +1,19 @@ +#!/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. + from typing import List, Tuple from krkn_lib.models.telemetry import ScenarioTelemetry diff --git a/krkn/tests/test_classes/duplicated_scenario_plugin.py b/krkn/tests/test_classes/duplicated_scenario_plugin.py index ac25849d8..56838dfc5 100644 --- a/krkn/tests/test_classes/duplicated_scenario_plugin.py +++ b/krkn/tests/test_classes/duplicated_scenario_plugin.py @@ -1,3 +1,19 @@ +#!/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. + from krkn_lib.models.telemetry import ScenarioTelemetry from krkn_lib.telemetry.ocp import KrknTelemetryOpenshift diff --git a/krkn/tests/test_classes/duplicated_two_scenario_plugin.py b/krkn/tests/test_classes/duplicated_two_scenario_plugin.py index da22380e3..787ff186c 100644 --- a/krkn/tests/test_classes/duplicated_two_scenario_plugin.py +++ b/krkn/tests/test_classes/duplicated_two_scenario_plugin.py @@ -1,3 +1,19 @@ +#!/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. + from krkn_lib.models.telemetry import ScenarioTelemetry from krkn_lib.telemetry.ocp import KrknTelemetryOpenshift diff --git a/krkn/tests/test_classes/example_scenario_plugin.py b/krkn/tests/test_classes/example_scenario_plugin.py index 86d642240..d4c40cde7 100644 --- a/krkn/tests/test_classes/example_scenario_plugin.py +++ b/krkn/tests/test_classes/example_scenario_plugin.py @@ -1,3 +1,19 @@ +#!/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. + from krkn_lib.models.telemetry import ScenarioTelemetry from krkn_lib.telemetry.ocp import KrknTelemetryOpenshift from krkn.scenario_plugins.abstract_scenario_plugin import AbstractScenarioPlugin diff --git a/krkn/tests/test_classes/snake_case_mismatch_scenario_plugin.py b/krkn/tests/test_classes/snake_case_mismatch_scenario_plugin.py index 1638163e9..5e2feb8e2 100644 --- a/krkn/tests/test_classes/snake_case_mismatch_scenario_plugin.py +++ b/krkn/tests/test_classes/snake_case_mismatch_scenario_plugin.py @@ -1,3 +1,19 @@ +#!/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. + from typing import List, Tuple from krkn_lib.models.telemetry import ScenarioTelemetry diff --git a/krkn/tests/test_classes/wrong_classname_scenario_plugin.py b/krkn/tests/test_classes/wrong_classname_scenario_plugin.py index 0a6bdd123..3ab2616ce 100644 --- a/krkn/tests/test_classes/wrong_classname_scenario_plugin.py +++ b/krkn/tests/test_classes/wrong_classname_scenario_plugin.py @@ -1,3 +1,19 @@ +#!/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. + from typing import List, Tuple from krkn_lib.models.telemetry import ScenarioTelemetry diff --git a/krkn/tests/test_classes/wrong_module.py b/krkn/tests/test_classes/wrong_module.py index b63cda9f2..979189331 100644 --- a/krkn/tests/test_classes/wrong_module.py +++ b/krkn/tests/test_classes/wrong_module.py @@ -1,3 +1,19 @@ +#!/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. + from typing import List, Tuple from krkn_lib.models.telemetry import ScenarioTelemetry diff --git a/krkn/tests/test_plugin_factory.py b/krkn/tests/test_plugin_factory.py index 29edc88b6..8ceda2bcc 100644 --- a/krkn/tests/test_plugin_factory.py +++ b/krkn/tests/test_plugin_factory.py @@ -1,3 +1,19 @@ +#!/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. + import json import tempfile import unittest diff --git a/krkn/utils/ErrorCollectionHandler.py b/krkn/utils/ErrorCollectionHandler.py index a9263076b..b4e6f10c5 100644 --- a/krkn/utils/ErrorCollectionHandler.py +++ b/krkn/utils/ErrorCollectionHandler.py @@ -1,3 +1,19 @@ +#!/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. + import logging import threading from datetime import datetime, timezone diff --git a/krkn/utils/ErrorLog.py b/krkn/utils/ErrorLog.py index bfb301772..6a2856cc6 100644 --- a/krkn/utils/ErrorLog.py +++ b/krkn/utils/ErrorLog.py @@ -1,3 +1,19 @@ +#!/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. + from dataclasses import dataclass, asdict diff --git a/krkn/utils/HealthChecker.py b/krkn/utils/HealthChecker.py index f8b59e94c..3673e57ee 100644 --- a/krkn/utils/HealthChecker.py +++ b/krkn/utils/HealthChecker.py @@ -1,3 +1,19 @@ +#!/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. + import requests import time import logging @@ -6,10 +22,10 @@ from krkn_lib.models.telemetry.models import HealthCheck class HealthChecker: - current_iterations: int = 0 - ret_value = 0 def __init__(self, iterations): self.iterations = iterations + self.current_iterations: int = 0 + self.ret_value = 0 def make_request(self, url, auth=None, headers=None, verify=True): response_data = {} @@ -50,8 +66,10 @@ def run_health_check(self, health_check_config, health_check_telemetry_queue: qu "start_timestamp": start_timestamp } if response["status_code"] != 200: - if response_tracker[config["url"]] != False: response_tracker[config["url"]] = False - if config["exit_on_failure"] and config["exit_on_failure"] == True and self.ret_value==0: self.ret_value = 2 + if response_tracker[config["url"]] is not False: + response_tracker[config["url"]] = False + if config["exit_on_failure"] is True and self.ret_value == 0: + self.ret_value = 2 else: if response["status_code"] != health_check_tracker[config["url"]]["status_code"]: end_timestamp = datetime.now() @@ -86,4 +104,5 @@ def run_health_check(self, health_check_config, health_check_telemetry_queue: qu health_check_telemetry_queue.put(health_check_telemetry) else: - logging.info("health checks config is not defined, skipping them") \ No newline at end of file + logging.info("health checks config is not defined, skipping them") + return self.ret_value \ No newline at end of file diff --git a/krkn/utils/TeeLogHandler.py b/krkn/utils/TeeLogHandler.py index cf3d501d9..c43a38cb4 100644 --- a/krkn/utils/TeeLogHandler.py +++ b/krkn/utils/TeeLogHandler.py @@ -1,12 +1,32 @@ +#!/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. + import logging class TeeLogHandler(logging.Handler): - logs: list[str] = [] name = "TeeLogHandler" + def __init__(self): + super().__init__() + self.logs: list[str] = [] + def get_output(self) -> str: return "\n".join(self.logs) def emit(self, record): self.logs.append(self.formatter.format(record)) + def __del__(self): pass \ No newline at end of file diff --git a/krkn/utils/VirtChecker.py b/krkn/utils/VirtChecker.py index 08ab41a67..7ad19f023 100644 --- a/krkn/utils/VirtChecker.py +++ b/krkn/utils/VirtChecker.py @@ -1,3 +1,19 @@ +#!/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. + import time import logging @@ -13,9 +29,9 @@ class VirtChecker: - current_iterations: int = 0 - ret_value = 0 def __init__(self, kubevirt_check_config, iterations, krkn_lib: KrknKubernetes, threads_limit=20): + self.current_iterations: int = 0 + self.ret_value = 0 self.iterations = iterations self.namespace = get_yaml_item_value(kubevirt_check_config, "namespace", "") self.vm_list = [] diff --git a/krkn/utils/__init__.py b/krkn/utils/__init__.py index a392e3e08..089aeb6c2 100644 --- a/krkn/utils/__init__.py +++ b/krkn/utils/__init__.py @@ -1,3 +1,19 @@ +#!/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. + from .TeeLogHandler import TeeLogHandler from .ErrorLog import ErrorLog from .ErrorCollectionHandler import ErrorCollectionHandler diff --git a/krkn/utils/functions.py b/krkn/utils/functions.py index 0774865f3..a91f39a73 100644 --- a/krkn/utils/functions.py +++ b/krkn/utils/functions.py @@ -1,3 +1,19 @@ +#!/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. + import krkn_lib.utils from krkn_lib.k8s import KrknKubernetes from krkn_lib.models.telemetry import ScenarioTelemetry diff --git a/run_kraken.py b/run_kraken.py index 4e00c553e..04e5432ec 100644 --- a/run_kraken.py +++ b/run_kraken.py @@ -1,4 +1,19 @@ #!/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. + import datetime import json import os @@ -54,6 +69,25 @@ # Main function def main(options, command: Optional[str]) -> int: + # Handle template commands - check before krkn_lib import + if command in ['list', 'show', 'run']: + try: + from krkn.template_manager import main as template_main + # Override sys.argv to pass template command + import sys + original_argv = sys.argv + sys.argv = ['krkn'] + ([command] + original_argv[2:] if len(original_argv) > 2 else [command]) + try: + return template_main() + finally: + sys.argv = original_argv + except ImportError as e: + print(f"Error: Template manager not available - {e}") + return 1 + except Exception as e: + print(f"Error running template command: {e}") + return 1 + # Start kraken print(pyfiglet.figlet_format("kraken")) logging.info("Starting kraken") diff --git a/server.py b/server.py index 3bbc3a7b7..e003ab080 100644 --- a/server.py +++ b/server.py @@ -1,3 +1,19 @@ +#!/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. + import sys import logging import _thread diff --git a/setup.py b/setup.py index 111ba7ffa..466dd604c 100644 --- a/setup.py +++ b/setup.py @@ -1,3 +1,19 @@ +#!/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. + # -*- coding: utf-8 -*- import sys diff --git a/templates/chaos-scenarios/disk-stress/metadata.yaml b/templates/chaos-scenarios/disk-stress/metadata.yaml new file mode 100644 index 000000000..eeb0f240f --- /dev/null +++ b/templates/chaos-scenarios/disk-stress/metadata.yaml @@ -0,0 +1,59 @@ +# 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. + +name: disk-stress +description: Applies disk I/O stress to test application performance under high disk load +target: kubernetes-node +risk_level: medium +category: performance +version: "1.0" +author: KRKN Team +tags: + - disk + - io + - stress + - performance + - storage +estimated_duration: "2-5 minutes" +dependencies: + - krkn-hog_image # Disk stress container image +parameters: + - name: duration + type: integer + description: Duration of disk stress in seconds + default: 60 + - name: workers + type: integer + description: Number of worker processes for I/O operations + default: 4 + - name: block-size + type: string + description: Block size for I/O operations + default: "4k" + - name: io-size + type: string + description: Total I/O size per worker + default: "1G" + - name: io-type + type: string + description: Type of I/O operation (randread, randwrite, read, write) + default: "randwrite" + - name: number-of-nodes + type: integer + description: Number of nodes to stress + default: 1 + - name: node-selector + type: string + description: Label selector to identify target nodes + default: "node-role.kubernetes.io/worker=" diff --git a/templates/chaos-scenarios/disk-stress/scenario.yaml b/templates/chaos-scenarios/disk-stress/scenario.yaml new file mode 100644 index 000000000..05b082c91 --- /dev/null +++ b/templates/chaos-scenarios/disk-stress/scenario.yaml @@ -0,0 +1,34 @@ +# 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. + +# yaml-language-server: $schema=../../plugin.schema.json +# Disk Stress Chaos Scenario Template +# Applies disk I/O stress to test application performance under high disk load +duration: 60 +workers: 4 +hog-type: io +image: quay.io/krkn-chaos/krkn-hog +namespace: default +block-size: "4k" +io-size: "1G" +io-type: "randwrite" +node-selector: "node-role.kubernetes.io/worker=" +number-of-nodes: 1 +taints: [] +# Optional: Target specific node +# node-name: "worker-0" +# Optional: File system path +# path: "/tmp" +# Optional: Direct I/O +# direct: 1 diff --git a/templates/chaos-scenarios/network-latency/README.md b/templates/chaos-scenarios/network-latency/README.md new file mode 100644 index 000000000..3ab2de766 --- /dev/null +++ b/templates/chaos-scenarios/network-latency/README.md @@ -0,0 +1,83 @@ +# Network Latency Chaos Scenario + +## Description +This scenario introduces network latency to test how applications perform under poor network conditions. It helps identify timeout issues, performance bottlenecks, and resilience problems. + +## Use Cases +- Test application timeout configurations +- Verify retry mechanisms +- Validate circuit breaker patterns +- Test user experience under poor network + +## Risk Level +**Low** - This temporarily degrades network performance but doesn't cause service failures. + +## Prerequisites +- Network chaos injection capabilities +- Appropriate RBAC permissions +- Target applications should be running + +## Usage + +### Basic Usage +```bash +krkn run-template network-latency +``` + +### With Custom Latency +```bash +krkn run-template network-latency \ + --param latency="200ms" \ + --param jitter="20ms" \ + --param duration=120 +``` + +### Target Specific Application +```bash +krkn run-template network-latency \ + --param target_pods="label_selector=app=frontend,namespace=production" +``` + +## Expected Behavior +1. KRKN identifies target pods/services +2. Injects network latency using network chaos engine +3. Maintains latency for specified duration +4. Monitors application behavior +5. Removes latency injection and reports results + +## Performance Impact +- Increased response times +- Potential timeout errors +- Reduced throughput +- User experience degradation + +## Customization +You can customize this scenario by modifying: +- `latency`: Amount of delay to introduce +- `jitter`: Variation in latency +- `duration`: How long latency persists +- `target_pods`: Specific applications to target +- `egress/ingress`: Direction of traffic affected + +## Monitoring Recommendations +- Monitor application response times +- Check error rates and timeouts +- Watch for retry storms +- Monitor user experience metrics + +## Troubleshooting +- Verify network chaos engine is running +- Check RBAC permissions +- Ensure target pods are accessible +- Monitor network interface status + +## Best Practices +- Start with low latency values +- Gradually increase intensity +- Monitor application health +- Have rollback procedures ready + +## Related Scenarios +- [Pod Network Chaos](../pod-network-chaos/) +- [Node Network Chaos](../node-network-chaos/) +- [CPU Stress](../cpu-stress/) diff --git a/templates/chaos-scenarios/network-latency/metadata.yaml b/templates/chaos-scenarios/network-latency/metadata.yaml new file mode 100644 index 000000000..5b0583aaf --- /dev/null +++ b/templates/chaos-scenarios/network-latency/metadata.yaml @@ -0,0 +1,55 @@ +# 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. + +name: network-latency +description: Introduces network latency to test application performance under poor network conditions +target: kubernetes-network +risk_level: low +category: performance +version: "1.0" +author: KRKN Team +tags: + - network + - latency + - performance + - chaos + - testing +estimated_duration: "2-5 minutes" +dependencies: + - network_chaos_engine # Requires network chaos injection capabilities +parameters: + - name: duration + type: integer + description: Duration of latency injection in seconds + default: 60 + - name: latency + type: string + description: Amount of latency to inject (e.g., "100ms") + default: "100ms" + - name: jitter + type: string + description: Jitter variation in latency + default: "10ms" + - name: correlation + type: string + description: Correlation percentage for latency patterns + default: "25%" + - name: egress + type: boolean + description: Apply latency to outgoing traffic + default: true + - name: ingress + type: boolean + description: Apply latency to incoming traffic + default: true diff --git a/templates/chaos-scenarios/network-latency/scenario.yaml b/templates/chaos-scenarios/network-latency/scenario.yaml new file mode 100644 index 000000000..661832c2e --- /dev/null +++ b/templates/chaos-scenarios/network-latency/scenario.yaml @@ -0,0 +1,39 @@ +# 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. + +# yaml-language-server: $schema=../../plugin.schema.json +# Network Latency Chaos Scenario Template +# Introduces network latency to test application performance under poor network conditions +network_chaos: + duration: 60 + node_name: "" # Leave empty to use label selector + label_selector: "app=nginx" + instance_count: 1 + interfaces: + - "eth0" + execution: serial + egress: + latency: "100ms" + loss: 0 + jitter: "10ms" + correlation: "25%" + ingress: + latency: "100ms" + loss: 0 + jitter: "10ms" + correlation: "25%" +# Optional: Target specific node +# node_name: "worker-0" +# Optional: Network interface +# interface: "eth0" diff --git a/templates/chaos-scenarios/node-failure/README.md b/templates/chaos-scenarios/node-failure/README.md new file mode 100644 index 000000000..5d30cdded --- /dev/null +++ b/templates/chaos-scenarios/node-failure/README.md @@ -0,0 +1,76 @@ +# Node Failure Chaos Scenario + +## Description +This scenario simulates node failures by stopping/terminating nodes in the cluster. It tests the cluster's ability to handle node loss, redistribute workloads, and maintain service availability. + +## Use Cases +- Test cluster self-healing capabilities +- Verify pod eviction and rescheduling +- Validate node replacement procedures +- Test load balancer reconfiguration + +## Risk Level +**High** - This will cause complete node failure, potentially affecting multiple pods and services. + +## Prerequisites +- Sufficient cluster capacity to handle node loss +- Proper pod disruption budgets configured +- Cluster autoscaler enabled (recommended) +- Cloud provider credentials configured + +## Usage + +### Basic Usage +```bash +krkn run-template node-failure +``` + +### With Custom Parameters +```bash +krkn run-template node-failure \ + --param instance_count=1 \ + --param label_selector="node-role.kubernetes.io/worker=" \ + --param timeout=600 +``` + +### Target Specific Node +```bash +krkn run-template node-failure \ + --param node_name="worker-node-3" +``` + +## Expected Behavior +1. KRKN identifies target nodes based on configuration +2. Initiates node failure (stop/terminate based on platform) +3. Monitors pod eviction and rescheduling +4. Waits for node recovery or timeout +5. Reports cluster status and recovery success + +## Cluster Requirements +- Minimum 3 worker nodes for production testing +- Sufficient resource capacity for pod redistribution +- Proper networking configuration for pod migration + +## Customization +You can customize this scenario by modifying: +- `instance_count`: Number of nodes to fail +- `node_name`: Target specific node +- `label_selector`: Filter nodes by labels +- `timeout`: Recovery monitoring duration + +## Safety Considerations +- Never run on single-node clusters +- Ensure proper backup procedures +- Monitor cluster health during execution +- Have rollback procedures ready + +## Troubleshooting +- Check cloud provider credentials +- Verify node permissions +- Monitor cluster resource utilization +- Check pod disruption budget status + +## Related Scenarios +- [Pod Failure](../pod-failure/) +- [Network Latency](../network-latency/) +- [Disk Stress](../disk-stress/) diff --git a/templates/chaos-scenarios/node-failure/metadata.yaml b/templates/chaos-scenarios/node-failure/metadata.yaml new file mode 100644 index 000000000..775ad7686 --- /dev/null +++ b/templates/chaos-scenarios/node-failure/metadata.yaml @@ -0,0 +1,47 @@ +# 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. + +name: node-failure +description: Simulates node failure to test cluster resiliency and pod redistribution +target: kubernetes-node +risk_level: high +category: availability +version: "1.0" +author: KRKN Team +tags: + - node + - failure + - availability + - cluster + - resiliency +estimated_duration: "5-15 minutes" +dependencies: + - cloud_provider_credentials # Required for cloud-based node actions +parameters: + - name: instance_count + type: integer + description: Number of nodes to fail + default: 1 + - name: node_name + type: string + description: Specific node name to target (empty for random) + default: "" + - name: label_selector + type: string + description: Label selector to identify target nodes + default: "node-role.kubernetes.io/worker=" + - name: timeout + type: integer + description: Timeout for node recovery in seconds + default: 300 diff --git a/templates/chaos-scenarios/node-failure/scenario.yaml b/templates/chaos-scenarios/node-failure/scenario.yaml new file mode 100644 index 000000000..5ca78af32 --- /dev/null +++ b/templates/chaos-scenarios/node-failure/scenario.yaml @@ -0,0 +1,26 @@ +# 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. + +# yaml-language-server: $schema=../../plugin.schema.json +# Node Failure Chaos Scenario Template +# Simulates node failure to test cluster resiliency +instance_count: 1 +node_name: "" # Leave empty to select random node +label_selector: "node-role.kubernetes.io/worker=" +timeout: 300 +# Optional: Specific node to target +# node_name: "worker-node-1" +# Optional: Cloud provider specific actions +# cloud_type: "aws" # aws, gcp, azure +# region: "us-west-2" diff --git a/templates/chaos-scenarios/pod-failure/README.md b/templates/chaos-scenarios/pod-failure/README.md new file mode 100644 index 000000000..d6cefc938 --- /dev/null +++ b/templates/chaos-scenarios/pod-failure/README.md @@ -0,0 +1,62 @@ +# Pod Failure Chaos Scenario + +## Description +This scenario simulates pod failures by terminating pods that match specified patterns. It helps test your application's ability to recover from pod crashes and maintain availability. + +## Use Cases +- Test application restart policies +- Verify pod disruption budgets +- Validate self-healing mechanisms +- Test load balancer failover + +## Risk Level +**Medium** - This will terminate running pods, which may cause temporary service disruption. + +## Prerequisites +- Target pods should have proper restart policies +- Applications should be designed to handle pod restarts +- Ensure sufficient pod replicas are running + +## Usage + +### Basic Usage +```bash +krkn run-template pod-failure +``` + +### With Custom Parameters +```bash +krkn run-template pod-failure \ + --param name_pattern="^nginx-.*$" \ + --param namespace_pattern="^production$" \ + --param kill=2 +``` + +### Using Configuration File +```bash +krkn run-template pod-failure --config custom-config.yaml +``` + +## Expected Behavior +1. KRKN identifies pods matching the specified patterns +2. Terminates the configured number of pods +3. Monitors pod recovery for the specified duration +4. Reports success/failure based on recovery + +## Customization +You can customize this scenario by modifying: +- `name_pattern`: Target specific pod naming conventions +- `namespace_pattern`: Target specific namespaces +- `kill`: Number of pods to terminate +- `krkn_pod_recovery_time`: Recovery monitoring duration + +## Troubleshooting +- Ensure pods have proper restart policies +- Check if pod disruption budgets are preventing termination +- Verify namespace and pod name patterns are correct +- Monitor pod logs during recovery + +## Related Scenarios +- [Container Restart](../container-restart/) +- [Node Failure](../node-failure/) +- [Network Latency](../network-latency/) diff --git a/templates/chaos-scenarios/pod-failure/metadata.yaml b/templates/chaos-scenarios/pod-failure/metadata.yaml new file mode 100644 index 000000000..f6a61dfe9 --- /dev/null +++ b/templates/chaos-scenarios/pod-failure/metadata.yaml @@ -0,0 +1,45 @@ +# 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. + +name: pod-failure +description: Simulates pod crash to test application resiliency +target: kubernetes-pod +risk_level: medium +category: availability +version: "1.0" +author: KRKN Team +tags: + - pod + - failure + - availability + - kubernetes +estimated_duration: "2-5 minutes" +dependencies: [] +parameters: + - name: name_pattern + type: string + description: Regex pattern to match pod names + default: ^.*-pod-.*$ + - name: namespace_pattern + type: string + description: Regex pattern to match namespaces + default: ^default$ + - name: kill + type: integer + description: Number of pods to kill + default: 1 + - name: krkn_pod_recovery_time + type: integer + description: Recovery time in seconds + default: 120 diff --git a/templates/chaos-scenarios/pod-failure/scenario.yaml b/templates/chaos-scenarios/pod-failure/scenario.yaml new file mode 100644 index 000000000..353fabc89 --- /dev/null +++ b/templates/chaos-scenarios/pod-failure/scenario.yaml @@ -0,0 +1,25 @@ +# 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. + +# yaml-language-server: $schema=../../plugin.schema.json +# Pod Failure Chaos Scenario Template +# Simulates pod crash to test application resiliency +name_pattern: ^nginx-.*$ +namespace_pattern: ^default$ +kill: 1 +krkn_pod_recovery_time: 120 +# Optional: Target specific pods +# label_selector: "app=nginx" +# Optional: Number of pods to kill +# kill_count: 1 diff --git a/templates/chaos-scenarios/pod-kill/README.md b/templates/chaos-scenarios/pod-kill/README.md new file mode 100644 index 000000000..f048884e6 --- /dev/null +++ b/templates/chaos-scenarios/pod-kill/README.md @@ -0,0 +1,85 @@ +# Pod Kill Chaos Scenario + +## Description +This scenario forcefully terminates pods to test application recovery mechanisms and restart policies. Unlike pod failure which simulates crashes, pod kill directly terminates pods to test graceful shutdown handling. + +## Use Cases +- Test pod restart policies +- Verify graceful shutdown behavior +- Test application startup procedures +- Validate deployment recovery + +## Risk Level +**Medium** - This will forcefully terminate running pods, causing immediate service disruption. + +## Prerequisites +- Target pods should have proper restart policies +- Applications should handle SIGTERM/SIGKILL signals +- Ensure sufficient pod replicas are running + +## Usage + +### Basic Usage +```bash +krkn run-template pod-kill +``` + +### With Custom Parameters +```bash +krkn run-template pod-kill \ + --param name_pattern="^frontend-.*$" \ + --param namespace_pattern="^production$" \ + --param kill=2 \ + --param force=true +``` + +### Target Specific Application +```bash +krkn run-template pod-kill \ + --param name_pattern="^nginx-deployment-.*$" \ + --param krkn_pod_recovery_time=180 +``` + +## Expected Behavior +1. KRKN identifies pods matching specified patterns +2. Forcefully terminates the configured number of pods +3. Monitors pod recreation and recovery +4. Waits for pods to become ready again +5. Reports success/failure based on recovery + +## Difference from Pod Failure +- **Pod Kill**: Forceful termination with SIGKILL +- **Pod Failure**: Simulates application crash +- **Pod Kill** tests graceful shutdown and restart +- **Pod Failure** tests crash recovery + +## Customization +You can customize this scenario by modifying: +- `name_pattern`: Target specific pod naming conventions +- `namespace_pattern`: Target specific namespaces +- `kill`: Number of pods to terminate +- `force`: Force kill without grace period +- `krkn_pod_recovery_time`: Recovery monitoring duration + +## Application Requirements +- Handle SIGTERM for graceful shutdown +- Implement proper startup procedures +- Configure appropriate restart policies +- Design for stateless operation when possible + +## Troubleshooting +- Check pod restart policies +- Verify application signal handling +- Monitor pod logs during termination +- Check resource constraints preventing restart + +## Best Practices +- Test with different restart policies +- Monitor application metrics during restart +- Ensure proper health checks configured +- Document expected recovery times + +## Related Scenarios +- [Pod Failure](../pod-failure/) +- [Container Restart](../container-restart/) +- [Node Failure](../node-failure/) diff --git a/templates/chaos-scenarios/pod-kill/metadata.yaml b/templates/chaos-scenarios/pod-kill/metadata.yaml new file mode 100644 index 000000000..cc8a12ded --- /dev/null +++ b/templates/chaos-scenarios/pod-kill/metadata.yaml @@ -0,0 +1,50 @@ +# 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. + +name: pod-kill +description: Forcefully terminates pods to test application recovery and restart policies +target: kubernetes-pod +risk_level: medium +category: availability +version: "1.0" +author: KRKN Team +tags: + - pod + - kill + - termination + - availability + - recovery +estimated_duration: "2-5 minutes" +dependencies: [] +parameters: + - name: name_pattern + type: string + description: Regex pattern to match pod names + default: ^.*-deployment-.*$ + - name: namespace_pattern + type: string + description: Regex pattern to match namespaces + default: ^default$ + - name: kill + type: integer + description: Number of pods to kill + default: 1 + - name: force + type: boolean + description: Force kill without grace period + default: true + - name: krkn_pod_recovery_time + type: integer + description: Recovery time in seconds + default: 120 diff --git a/templates/chaos-scenarios/pod-kill/scenario.yaml b/templates/chaos-scenarios/pod-kill/scenario.yaml new file mode 100644 index 000000000..4e286da41 --- /dev/null +++ b/templates/chaos-scenarios/pod-kill/scenario.yaml @@ -0,0 +1,28 @@ +# 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. + +# yaml-language-server: $schema=../../plugin.schema.json +# Pod Kill Chaos Scenario Template +# Forcefully terminates pods to test application recovery and restart policies +name_pattern: ^nginx-.*$ +namespace_pattern: ^default$ +kill: 1 +force: true +krkn_pod_recovery_time: 120 +# Optional: Target specific pods by label +# label_selector: "app=nginx" +# Optional: Grace period before force kill +# grace_period: 0 +# Optional: Kill all matching pods +# kill_all: false diff --git a/templates/chaos-scenarios/resource-failure/README.md b/templates/chaos-scenarios/resource-failure/README.md new file mode 100644 index 000000000..77694cefa --- /dev/null +++ b/templates/chaos-scenarios/resource-failure/README.md @@ -0,0 +1,108 @@ +# Resource Failure Chaos Scenario + +## Description +This scenario simulates failures for various Kubernetes resources including deployments, services, configmaps, and secrets. It tests the cluster's ability to handle resource-level failures and recover appropriately. + +## Use Cases +- Test deployment recovery mechanisms +- Verify service discovery resilience +- Test configuration management +- Validate resource recreation procedures + +## Risk Level +**Medium** - Resource failures can cause service disruption depending on the resource type and availability. + +## Prerequisites +- Target resources should be properly configured +- Backup procedures for critical resources +- Appropriate RBAC permissions for resource management + +## Usage + +### Basic Usage +```bash +krkn run-template resource-failure +``` + +### Target Different Resource Type +```bash +krkn run-template resource-failure \ + --param resource_type="service" \ + --param resource_name_pattern="^.*-service-.*$" \ + --param action="delete" +``` + +### Scale to Zero Instead of Delete +```bash +krkn run-template resource-failure \ + --param resource_type="deployment" \ + --param action="scale-to-zero" \ + --param recovery_time=180 +``` + +### Edit Resource Configuration +```bash +krkn run-template resource-failure \ + --param resource_type="deployment" \ + --param action="edit" \ + --param resource_name_pattern="^frontend-.*$" +``` + +## Expected Behavior +1. KRKN identifies resources matching specified patterns +2. Executes the configured action (delete/scale/edit) +3. Monitors resource status during the action +4. Waits for resource recovery or timeout +5. Reports success/failure based on recovery + +## Resource Types and Actions + +### Deployments +- **delete**: Removes the deployment +- **scale-to-zero**: Sets replicas to 0 +- **edit**: Modifies deployment configuration + +### Services +- **delete**: Removes the service +- **edit**: Modifies service configuration + +### ConfigMaps/Secrets +- **delete**: Removes the resource +- **edit**: Modifies resource content + +## Customization +You can customize this scenario by modifying: +- `resource_type`: Type of Kubernetes resource +- `resource_name_pattern`: Target specific naming conventions +- `namespace_pattern`: Target specific namespaces +- `action`: Type of operation to perform +- `recovery_time`: Recovery monitoring duration + +## Safety Considerations +- Test in non-production environments first +- Ensure resource backups are available +- Monitor application dependencies +- Have rollback procedures ready + +## Monitoring Recommendations +- Monitor resource status and health +- Watch for application errors +- Check service discovery updates +- Monitor configuration reloads + +## Troubleshooting +- Check resource permissions and RBAC +- Verify resource configurations +- Monitor controller logs +- Check for resource dependencies + +## Best Practices +- Document resource recovery procedures +- Test different resource configurations +- Monitor application behavior +- Ensure proper resource sizing + +## Related Scenarios +- [Pod Failure](../pod-failure/) +- [Node Failure](../node-failure/) +- [Container Restart](../container-restart/) diff --git a/templates/chaos-scenarios/resource-failure/metadata.yaml b/templates/chaos-scenarios/resource-failure/metadata.yaml new file mode 100644 index 000000000..e4ed18241 --- /dev/null +++ b/templates/chaos-scenarios/resource-failure/metadata.yaml @@ -0,0 +1,50 @@ +# 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. + +name: resource-failure +description: Simulates resource failures for various Kubernetes resources to test recovery mechanisms +target: kubernetes-resource +risk_level: medium +category: availability +version: "1.0" +author: KRKN Team +tags: + - resource + - failure + - kubernetes + - deployment + - service +estimated_duration: "3-8 minutes" +dependencies: [] +parameters: + - name: resource_type + type: string + description: Type of Kubernetes resource (deployment, service, configmap, secret) + default: deployment + - name: resource_name_pattern + type: string + description: Regex pattern to match resource names + default: ^.*-app-.*$ + - name: namespace_pattern + type: string + description: Regex pattern to match namespaces + default: ^default$ + - name: action + type: string + description: Action to perform (delete, scale-to-zero, edit) + default: delete + - name: recovery_time + type: integer + description: Resource recovery monitoring time in seconds + default: 120 diff --git a/templates/chaos-scenarios/resource-failure/scenario.yaml b/templates/chaos-scenarios/resource-failure/scenario.yaml new file mode 100644 index 000000000..949b62e7d --- /dev/null +++ b/templates/chaos-scenarios/resource-failure/scenario.yaml @@ -0,0 +1,30 @@ +# 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. + +# yaml-language-server: $schema=../../plugin.schema.json +# Basic Kubernetes Resource Failure Chaos Scenario Template +# Simulates resource failures for various Kubernetes resources +resource_type: deployment +resource_name_pattern: ^.*-app-.*$ +namespace_pattern: ^default$ +action: delete # delete, scale-to-zero, edit +recovery_time: 120 +# Optional: Target specific resource type +# resource_type: "service" +# Optional: Scale to zero instead of delete +# action: "scale-to-zero" +# Optional: Modify resource configuration +# action: "edit" +# modifications: +# replicas: 0 diff --git a/templates/chaos-scenarios/vm-outage/README.md b/templates/chaos-scenarios/vm-outage/README.md new file mode 100644 index 000000000..e7075be0f --- /dev/null +++ b/templates/chaos-scenarios/vm-outage/README.md @@ -0,0 +1,98 @@ +# VM Outage Chaos Scenario + +## Description +This scenario simulates VM outages for OpenShift Virtualization environments to test VM resilience and recovery mechanisms. It supports various VM actions including stop, restart, and pause operations. + +## Use Cases +- Test VM recovery procedures +- Verify VM high availability +- Test virtualization platform resilience +- Validate VM backup and restore + +## Risk Level +**High** - VM outages can cause significant service disruption and data loss if not properly managed. + +## Prerequisites +- OpenShift Virtualization or KubeVirt installed +- Sufficient VM resources available +- Proper VM backup procedures in place +- Appropriate RBAC permissions for VM management + +## Usage + +### Basic Usage +```bash +krkn run-template vm-outage +``` + +### With Custom Action +```bash +krkn run-template vm-outage \ + --param action="restart" \ + --param vm_name_pattern="^production-vm-.*$" \ + --param timeout=600 +``` + +### Target Specific Namespace +```bash +krkn run-template vm-outage \ + --param namespace_pattern="^vm-workspace$" \ + --param action="pause" \ + --param recovery_time=300 +``` + +## Expected Behavior +1. KRKN identifies VMs matching specified patterns +2. Executes the configured VM action (stop/restart/pause) +3. Monitors VM status during the action +4. Waits for VM recovery or timeout +5. Reports success/failure based on recovery + +## VM Actions +- **stop**: Powers down the VM gracefully or forcefully +- **restart**: Reboots the VM +- **pause**: Pauses VM execution (freezes state) + +## Platform Requirements +- OpenShift 4.8+ with Virtualization enabled +- KubeVirt v0.45+ for non-OpenShift environments +- Sufficient compute and storage resources +- Proper network configuration + +## Customization +You can customize this scenario by modifying: +- `vm_name_pattern`: Target specific VM naming conventions +- `namespace_pattern`: Target specific namespaces +- `action`: Type of VM operation to perform +- `timeout`: Action timeout duration +- `recovery_time`: Recovery monitoring duration + +## Safety Considerations +- Ensure VM backups are current +- Test in non-production environments first +- Monitor VM health during execution +- Have rollback procedures ready +- Consider data persistence requirements + +## Monitoring Recommendations +- Monitor VM status and health +- Watch for VM migration events +- Check storage and network connectivity +- Monitor application performance within VMs + +## Troubleshooting +- Check OpenShift Virtualization operator status +- Verify VM permissions and RBAC +- Monitor VM logs and events +- Check storage class availability + +## Best Practices +- Document VM recovery procedures +- Test different VM configurations +- Monitor resource utilization +- Ensure proper VM sizing + +## Related Scenarios +- [Node Failure](../node-failure/) +- [Pod Failure](../pod-failure/) +- [Disk Stress](../disk-stress/) diff --git a/templates/chaos-scenarios/vm-outage/metadata.yaml b/templates/chaos-scenarios/vm-outage/metadata.yaml new file mode 100644 index 000000000..e5bd23254 --- /dev/null +++ b/templates/chaos-scenarios/vm-outage/metadata.yaml @@ -0,0 +1,51 @@ +# 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. + +name: vm-outage +description: Simulates VM outage for OpenShift Virtualization environments to test VM resilience +target: openshift-virtualization +risk_level: high +category: availability +version: "1.0" +author: KRKN Team +tags: + - vm + - outage + - openshift + - virtualization + - kubevirt +estimated_duration: "5-10 minutes" +dependencies: + - openshift_virtualization # Requires OpenShift Virtualization/KubeVirt +parameters: + - name: vm_name_pattern + type: string + description: Regex pattern to match VM names + default: ^.*-vm-.*$ + - name: namespace_pattern + type: string + description: Regex pattern to match namespaces + default: ^.*$ + - name: action + type: string + description: VM action (stop, restart, pause) + default: stop + - name: timeout + type: integer + description: Timeout for VM action in seconds + default: 300 + - name: recovery_time + type: integer + description: VM recovery monitoring time in seconds + default: 180 diff --git a/templates/chaos-scenarios/vm-outage/scenario.yaml b/templates/chaos-scenarios/vm-outage/scenario.yaml new file mode 100644 index 000000000..5386371ff --- /dev/null +++ b/templates/chaos-scenarios/vm-outage/scenario.yaml @@ -0,0 +1,28 @@ +# 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. + +# yaml-language-server: $schema=../../plugin.schema.json +# VM Outage Chaos Scenario Template +# Simulates VM outage for OpenShift Virtualization environments +vm_name_pattern: ^.*-vm-.*$ +namespace_pattern: ^.*$ +action: stop # stop, restart, pause +timeout: 300 +recovery_time: 180 +# Optional: Target specific VM +# vm_name: "my-specific-vm" +# Optional: Graceful shutdown +# graceful: true +# Optional: Force action +# force: false diff --git a/tests/__init__.py b/tests/__init__.py index e69de29bb..798fe911f 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -0,0 +1,16 @@ +#!/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. + diff --git a/tests/rollback_scenario_plugins/__init__.py b/tests/rollback_scenario_plugins/__init__.py index e69de29bb..798fe911f 100644 --- a/tests/rollback_scenario_plugins/__init__.py +++ b/tests/rollback_scenario_plugins/__init__.py @@ -0,0 +1,16 @@ +#!/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. + diff --git a/tests/rollback_scenario_plugins/simple.py b/tests/rollback_scenario_plugins/simple.py index f493ef044..e69d11c31 100644 --- a/tests/rollback_scenario_plugins/simple.py +++ b/tests/rollback_scenario_plugins/simple.py @@ -1,3 +1,19 @@ +#!/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. + import logging from krkn_lib.telemetry.ocp import KrknTelemetryOpenshift @@ -23,14 +39,12 @@ def run( self, run_uuid: str, scenario: str, - krkn_config: dict[str, any], lib_telemetry: KrknTelemetryOpenshift, scenario_telemetry: ScenarioTelemetry, ) -> int: logger.info( f"Setting rollback callable for run {run_uuid} with scenario {scenario}." ) - logger.debug(f"Krkn config: {krkn_config}") self.rollback_handler.set_rollback_callable( self.rollback_callable, RollbackContent( diff --git a/tests/run_python_plugin.py b/tests/run_python_plugin.py index a29c01a9d..e7fd5302d 100644 --- a/tests/run_python_plugin.py +++ b/tests/run_python_plugin.py @@ -1,3 +1,19 @@ +#!/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. + import tempfile import unittest diff --git a/tests/test_abstract_node_scenarios.py b/tests/test_abstract_node_scenarios.py index 1821a7d56..bb82613f3 100644 --- a/tests/test_abstract_node_scenarios.py +++ b/tests/test_abstract_node_scenarios.py @@ -1,3 +1,19 @@ +#!/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. + """ Test suite for AbstractNode Scenarios diff --git a/tests/test_abstract_scenario_plugin_cerberus.py b/tests/test_abstract_scenario_plugin_cerberus.py index 3414faf82..417faa687 100644 --- a/tests/test_abstract_scenario_plugin_cerberus.py +++ b/tests/test_abstract_scenario_plugin_cerberus.py @@ -1,3 +1,19 @@ +#!/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. + """ Test suite for krkn/scenario_plugins/abstract_scenario_plugin.py diff --git a/tests/test_alibaba_node_scenarios.py b/tests/test_alibaba_node_scenarios.py index 731ff0929..24b4eb4c9 100644 --- a/tests/test_alibaba_node_scenarios.py +++ b/tests/test_alibaba_node_scenarios.py @@ -1,4 +1,19 @@ -#!/usr/bin/env python3 +#!/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. + """ Test suite for alibaba_node_scenarios class diff --git a/tests/test_application_outage_scenario_plugin.py b/tests/test_application_outage_scenario_plugin.py index 9137d65f0..747f9b757 100644 --- a/tests/test_application_outage_scenario_plugin.py +++ b/tests/test_application_outage_scenario_plugin.py @@ -1,4 +1,19 @@ -#!/usr/bin/env python3 +#!/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. + """ Test suite for ApplicationOutageScenarioPlugin class diff --git a/tests/test_aws_node_scenarios.py b/tests/test_aws_node_scenarios.py index be71dda05..7d0298c4f 100644 --- a/tests/test_aws_node_scenarios.py +++ b/tests/test_aws_node_scenarios.py @@ -1,4 +1,19 @@ -#!/usr/bin/env python3 +#!/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. + """ Test suite for AWS node scenarios diff --git a/tests/test_az_node_scenarios.py b/tests/test_az_node_scenarios.py index f19f182ce..71cdff44f 100644 --- a/tests/test_az_node_scenarios.py +++ b/tests/test_az_node_scenarios.py @@ -1,4 +1,19 @@ -#!/usr/bin/env python3 +#!/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. + """ Test suite for azure_node_scenarios class diff --git a/tests/test_cerberus_setup.py b/tests/test_cerberus_setup.py index 45102021f..4f1e9e439 100644 --- a/tests/test_cerberus_setup.py +++ b/tests/test_cerberus_setup.py @@ -1,3 +1,19 @@ +#!/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. + """ Test suite for krkn/cerberus/setup.py @@ -33,7 +49,7 @@ def test_set_url_with_cerberus_enabled(self): "cerberus": { "cerberus_enabled": True, "cerberus_url": "http://cerberus.example.com", - "check_applicaton_routes": "route1,route2" + "check_application_routes": "route1,route2" } } @@ -178,12 +194,28 @@ def test_publish_kraken_status_healthy_exit_on_failure_true(self, mock_get_statu cerberus_setup.exit_on_failure = True mock_get_status.return_value = True - with self.assertRaises(SystemExit) as cm: - cerberus_setup.publish_kraken_status(0, 100) - - self.assertEqual(cm.exception.code, 1) + # Healthy cluster should NOT exit regardless of exit_on_failure + cerberus_setup.publish_kraken_status(0, 100) + mock_get_status.assert_called_once_with(0, 100) + def test_set_url_legacy_misspelled_key_fallback(self): + """Test set_url falls back to legacy misspelled key check_applicaton_routes""" + config = { + "kraken": {"exit_on_failure": False}, + "cerberus": { + "cerberus_enabled": True, + "cerberus_url": "http://cerberus.example.com", + "check_applicaton_routes": "legacy-route" # old misspelled key + } + } + + with self.assertLogs(level="WARNING") as log: + cerberus_setup.set_url(config) + + self.assertEqual(cerberus_setup.check_application_routes, "legacy-route") + self.assertTrue(any("deprecated" in msg for msg in log.output)) + @patch('krkn.cerberus.setup.get_status') def test_publish_kraken_status_unhealthy_exit_on_failure_false(self, mock_get_status): """Test publish_kraken_status when cluster is unhealthy and exit_on_failure is False""" diff --git a/tests/test_common_node_functions.py b/tests/test_common_node_functions.py index 17daa3193..87d5c138f 100644 --- a/tests/test_common_node_functions.py +++ b/tests/test_common_node_functions.py @@ -1,4 +1,19 @@ -#!/usr/bin/env python3 +#!/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. + """ Test suite for common_node_functions module diff --git a/tests/test_container_scenario_plugin.py b/tests/test_container_scenario_plugin.py index 8ca40365c..b44dace6b 100644 --- a/tests/test_container_scenario_plugin.py +++ b/tests/test_container_scenario_plugin.py @@ -1,4 +1,19 @@ -#!/usr/bin/env python3 +#!/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. + """ Test suite for ContainerScenarioPlugin class diff --git a/tests/test_failed_scenarios_accumulation.py b/tests/test_failed_scenarios_accumulation.py index 70f0c3c3c..c2ed75389 100644 --- a/tests/test_failed_scenarios_accumulation.py +++ b/tests/test_failed_scenarios_accumulation.py @@ -1,4 +1,19 @@ -#!/usr/bin/env python3 +#!/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. + """ Test to verify that failed scenarios are accumulated across all scenario types diff --git a/tests/test_gcp_node_scenarios.py b/tests/test_gcp_node_scenarios.py index 12f5723d6..09f9d1763 100644 --- a/tests/test_gcp_node_scenarios.py +++ b/tests/test_gcp_node_scenarios.py @@ -1,4 +1,19 @@ -#!/usr/bin/env python3 +#!/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. + """ Test suite for GCP node scenarios diff --git a/tests/test_health_checker.py b/tests/test_health_checker.py index 295950e1d..9e63b5bb3 100644 --- a/tests/test_health_checker.py +++ b/tests/test_health_checker.py @@ -1,4 +1,19 @@ -#!/usr/bin/env python3 +#!/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. + """ Test suite for HealthChecker class diff --git a/tests/test_hogs_scenario_plugin.py b/tests/test_hogs_scenario_plugin.py index 3cd0a0e4c..876661f85 100644 --- a/tests/test_hogs_scenario_plugin.py +++ b/tests/test_hogs_scenario_plugin.py @@ -1,4 +1,19 @@ -#!/usr/bin/env python3 +#!/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. + """ Test suite for HogsScenarioPlugin class diff --git a/tests/test_ibmcloud_node_scenarios.py b/tests/test_ibmcloud_node_scenarios.py index 5bf1cdd4a..11517e7e6 100644 --- a/tests/test_ibmcloud_node_scenarios.py +++ b/tests/test_ibmcloud_node_scenarios.py @@ -1,4 +1,19 @@ -#!/usr/bin/env python3 +#!/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. + """ Test suite for IBM Cloud VPC node scenarios diff --git a/tests/test_ibmcloud_power_node_scenarios.py b/tests/test_ibmcloud_power_node_scenarios.py index 17d474122..3d31784a8 100644 --- a/tests/test_ibmcloud_power_node_scenarios.py +++ b/tests/test_ibmcloud_power_node_scenarios.py @@ -1,4 +1,19 @@ -#!/usr/bin/env python3 +#!/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. + """ Test suite for IBM Cloud Power node scenarios diff --git a/tests/test_ingress_network_plugin.py b/tests/test_ingress_network_plugin.py index 3a22e71ab..adb830a16 100644 --- a/tests/test_ingress_network_plugin.py +++ b/tests/test_ingress_network_plugin.py @@ -1,3 +1,19 @@ +#!/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. + import unittest from unittest.mock import Mock, patch from arcaflow_plugin_sdk import plugin diff --git a/tests/test_kubevirt_vm_outage.py b/tests/test_kubevirt_vm_outage.py index d980e45f7..b0b3d6a04 100644 --- a/tests/test_kubevirt_vm_outage.py +++ b/tests/test_kubevirt_vm_outage.py @@ -1,4 +1,19 @@ -#!/usr/bin/env python3 +#!/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. + """ Test suite for KubeVirt VM Outage Scenario Plugin diff --git a/tests/test_logging_and_code_quality.py b/tests/test_logging_and_code_quality.py index d7b6b3d2c..9b3d40cf2 100644 --- a/tests/test_logging_and_code_quality.py +++ b/tests/test_logging_and_code_quality.py @@ -1,4 +1,18 @@ #!/usr/bin/env python3 +# +# 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. """ Tests for fixes introduced in issues #24–#28. diff --git a/tests/test_managed_cluster_scenario_plugin.py b/tests/test_managed_cluster_scenario_plugin.py index 028b42ce8..bb0a48daf 100644 --- a/tests/test_managed_cluster_scenario_plugin.py +++ b/tests/test_managed_cluster_scenario_plugin.py @@ -1,4 +1,19 @@ -#!/usr/bin/env python3 +#!/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. + """ Test suite for ManagedClusterScenarioPlugin class diff --git a/tests/test_native_scenario_plugin.py b/tests/test_native_scenario_plugin.py index 5d73059b0..2d5b732d6 100644 --- a/tests/test_native_scenario_plugin.py +++ b/tests/test_native_scenario_plugin.py @@ -1,4 +1,19 @@ -#!/usr/bin/env python3 +#!/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. + """ Test suite for NativeScenarioPlugin class diff --git a/tests/test_network_chaos_ng_scenario_plugin.py b/tests/test_network_chaos_ng_scenario_plugin.py index 4e6d36560..238eb59cf 100644 --- a/tests/test_network_chaos_ng_scenario_plugin.py +++ b/tests/test_network_chaos_ng_scenario_plugin.py @@ -1,4 +1,19 @@ -#!/usr/bin/env python3 +#!/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. + """ Test suite for NetworkChaosNgScenarioPlugin class diff --git a/tests/test_network_chaos_scenario_plugin.py b/tests/test_network_chaos_scenario_plugin.py index ac35c43be..561654b7c 100644 --- a/tests/test_network_chaos_scenario_plugin.py +++ b/tests/test_network_chaos_scenario_plugin.py @@ -1,4 +1,19 @@ -#!/usr/bin/env python3 +#!/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. + """ Test suite for NetworkChaosScenarioPlugin class diff --git a/tests/test_node_actions_scenario_plugin.py b/tests/test_node_actions_scenario_plugin.py index 2646433a2..11c064287 100644 --- a/tests/test_node_actions_scenario_plugin.py +++ b/tests/test_node_actions_scenario_plugin.py @@ -1,4 +1,19 @@ -#!/usr/bin/env python3 +#!/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. + """ Test suite for NodeActionsScenarioPlugin class diff --git a/tests/test_node_network_chaos.py b/tests/test_node_network_chaos.py index 510453039..d474e44d5 100644 --- a/tests/test_node_network_chaos.py +++ b/tests/test_node_network_chaos.py @@ -1,4 +1,19 @@ -#!/usr/bin/env python3 +#!/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. + """ Test suite for NodeNetworkChaosModule class diff --git a/tests/test_openstack_node_scenarios.py b/tests/test_openstack_node_scenarios.py index 6a9061348..f5535d2cf 100644 --- a/tests/test_openstack_node_scenarios.py +++ b/tests/test_openstack_node_scenarios.py @@ -1,4 +1,19 @@ -#!/usr/bin/env python3 +#!/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. + """ Test suite for OpenStack node scenarios diff --git a/tests/test_pod_disruption_scenario_plugin.py b/tests/test_pod_disruption_scenario_plugin.py index 6c069f169..86c091551 100644 --- a/tests/test_pod_disruption_scenario_plugin.py +++ b/tests/test_pod_disruption_scenario_plugin.py @@ -1,4 +1,19 @@ -#!/usr/bin/env python3 +#!/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. + """ Test suite for PodDisruptionScenarioPlugin class diff --git a/tests/test_pod_network_chaos.py b/tests/test_pod_network_chaos.py index d49c7b59c..ccd5819ed 100644 --- a/tests/test_pod_network_chaos.py +++ b/tests/test_pod_network_chaos.py @@ -1,4 +1,19 @@ -#!/usr/bin/env python3 +#!/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. + """ Test suite for PodNetworkChaosModule class diff --git a/tests/test_pod_network_outage.py b/tests/test_pod_network_outage.py index e22d21603..43d2a36b6 100644 --- a/tests/test_pod_network_outage.py +++ b/tests/test_pod_network_outage.py @@ -1,3 +1,19 @@ +#!/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. + import unittest from unittest.mock import MagicMock, patch import sys diff --git a/tests/test_prometheus_client.py b/tests/test_prometheus_client.py index 7fa2f9089..9ddc3b0b2 100644 --- a/tests/test_prometheus_client.py +++ b/tests/test_prometheus_client.py @@ -1,4 +1,19 @@ -#!/usr/bin/env python3 +#!/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. + """ Test suite for krkn.prometheus.client module diff --git a/tests/test_prometheus_collector.py b/tests/test_prometheus_collector.py index d5a88e055..9ddb5c7cc 100644 --- a/tests/test_prometheus_collector.py +++ b/tests/test_prometheus_collector.py @@ -1,3 +1,18 @@ +#!/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. """ Tests for krkn.prometheus.collector module. diff --git a/tests/test_pvc_scenario_plugin.py b/tests/test_pvc_scenario_plugin.py index 18495f3a6..799800d2d 100644 --- a/tests/test_pvc_scenario_plugin.py +++ b/tests/test_pvc_scenario_plugin.py @@ -1,4 +1,19 @@ -#!/usr/bin/env python3 +#!/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. + """ Test suite for PvcScenarioPlugin class diff --git a/tests/test_resiliency.py b/tests/test_resiliency.py index 0781f8c63..68f35d0ad 100644 --- a/tests/test_resiliency.py +++ b/tests/test_resiliency.py @@ -1,3 +1,18 @@ +#!/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. """ Tests for krkn.resiliency.resiliency module. diff --git a/tests/test_resiliency_score.py b/tests/test_resiliency_score.py index 4890fec11..c58b398d1 100644 --- a/tests/test_resiliency_score.py +++ b/tests/test_resiliency_score.py @@ -1,3 +1,18 @@ +#!/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. """ Tests for krkn.resiliency.score module. diff --git a/tests/test_rollback.py b/tests/test_rollback.py index 7a0098724..4785174e8 100644 --- a/tests/test_rollback.py +++ b/tests/test_rollback.py @@ -1,3 +1,19 @@ +#!/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. + import pytest import logging import os @@ -143,12 +159,6 @@ def test_simple_rollback_scenario_plugin( simple_rollback_scenario_plugin.run( run_uuid=run_uuid, scenario="test_scenario", - krkn_config={ - "key1": "value", - "key2": False, - "key3": 123, - "key4": ["value1", "value2", "value3"], - }, lib_telemetry=lib_telemetry, scenario_telemetry=scenario_telemetry, ) @@ -240,7 +250,7 @@ def test_run_scenarios_respect_auto_rollback_config(self, auto_rollback, scenari # Create a test scenario plugin class TestScenarioPlugin(AbstractScenarioPlugin): - def run(self, run_uuid: str, scenario: str, krkn_config: dict, lib_telemetry, scenario_telemetry): + def run(self, run_uuid: str, scenario: str, lib_telemetry, scenario_telemetry): return 1 if scenario_should_fail else 0 def get_scenario_types(self) -> list[str]: diff --git a/tests/test_run_python_plugin.py b/tests/test_run_python_plugin.py index a29c01a9d..e7fd5302d 100644 --- a/tests/test_run_python_plugin.py +++ b/tests/test_run_python_plugin.py @@ -1,3 +1,19 @@ +#!/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. + import tempfile import unittest diff --git a/tests/test_server.py b/tests/test_server.py index b970bffe1..09d56c5a8 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -1,4 +1,19 @@ -#!/usr/bin/env python3 +#!/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. + """ Test suite for SimpleHTTPRequestHandler class diff --git a/tests/test_service_disruption_scenario_plugin.py b/tests/test_service_disruption_scenario_plugin.py index dba567d92..915b901f6 100644 --- a/tests/test_service_disruption_scenario_plugin.py +++ b/tests/test_service_disruption_scenario_plugin.py @@ -1,4 +1,19 @@ -#!/usr/bin/env python3 +#!/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. + """ Test suite for ServiceDisruptionScenarioPlugin class diff --git a/tests/test_service_hijacking_scenario_plugin.py b/tests/test_service_hijacking_scenario_plugin.py index 78e8b3159..76c278746 100644 --- a/tests/test_service_hijacking_scenario_plugin.py +++ b/tests/test_service_hijacking_scenario_plugin.py @@ -1,4 +1,19 @@ -#!/usr/bin/env python3 +#!/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. + """ Test suite for ServiceHijackingScenarioPlugin class diff --git a/tests/test_shut_down_scenario_plugin.py b/tests/test_shut_down_scenario_plugin.py index 20e65b60a..b42fcb690 100644 --- a/tests/test_shut_down_scenario_plugin.py +++ b/tests/test_shut_down_scenario_plugin.py @@ -1,4 +1,19 @@ -#!/usr/bin/env python3 +#!/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. + """ Test suite for ShutDownScenarioPlugin class diff --git a/tests/test_syn_flood_scenario_plugin.py b/tests/test_syn_flood_scenario_plugin.py index cae8b48a3..0a5a29ea3 100644 --- a/tests/test_syn_flood_scenario_plugin.py +++ b/tests/test_syn_flood_scenario_plugin.py @@ -1,4 +1,19 @@ -#!/usr/bin/env python3 +#!/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. + """ Test suite for SynFloodScenarioPlugin class diff --git a/tests/test_template_manager.py b/tests/test_template_manager.py new file mode 100644 index 000000000..39458cdd3 --- /dev/null +++ b/tests/test_template_manager.py @@ -0,0 +1,173 @@ +#!/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. + +""" +Test module for KRKN Template functionality +""" + +import pytest +import sys +import os +import yaml +from pathlib import Path + +# Add the krkn package to Python path +package_root = Path(__file__).parent.parent +sys.path.insert(0, str(package_root)) + +from krkn.template_manager import TemplateManager + + +class TestTemplateManager: + """Test cases for TemplateManager class""" + + @pytest.fixture + def template_manager(self): + """Create a template manager instance for testing""" + return TemplateManager() + + def test_template_listing(self, template_manager): + """Test template listing functionality""" + print("Testing Template Listing...") + + templates = template_manager.list_templates() + + print(f"Found {len(templates)} templates") + + expected_templates = [ + 'pod-failure', 'node-failure', 'network-latency', + 'cpu-stress', 'disk-stress', 'pod-kill', + 'container-restart', 'vm-outage', 'resource-failure' + ] + + for template_name in expected_templates: + if template_name in templates: + print(f"Template '{template_name}' found") + assert template_name in templates + else: + print(f"Template '{template_name}' missing") + # Don't fail the test for missing templates as they might not be available in test environment + + def test_template_validation(self, template_manager): + """Test template validation functionality""" + print("Testing Template Validation...") + + templates = template_manager.list_templates() + + for template_name in templates: + is_valid = template_manager.validate_template(template_name) + if is_valid: + print(f"Template '{template_name}' is valid") + assert is_valid + else: + print(f"Template '{template_name}' validation failed") + + def test_template_details(self, template_manager): + """Test getting template details""" + print("Testing Template Details...") + + templates = template_manager.list_templates() + + for template_name in list(templates.keys())[:3]: # Test first 3 templates + details = template_manager.get_template_details(template_name) + if details: + print(f"Got details for template '{template_name}'") + assert 'metadata' in details or 'scenario' in details + else: + print(f"Could not get details for template '{template_name}'") + + def test_prepare_template_config(self, template_manager): + """Test preparing template configuration""" + print("Testing Template Config Preparation...") + + templates = template_manager.list_templates() + + if not templates: + print("No templates available for config preparation test") + return + + # Test with first available template + template_name = list(templates.keys())[0] + + # Test without parameters + config_path = template_manager.prepare_template_config(template_name) + if config_path: + print(f"Prepared config for template '{template_name}': {config_path}") + assert os.path.exists(config_path) + + # Verify it's a valid KRKN config + with open(config_path, 'r') as f: + config = yaml.safe_load(f) + assert 'kraken' in config + assert 'chaos_scenarios' in config['kraken'] + + # Clean up + os.remove(config_path) + else: + print(f"Failed to prepare config for template '{template_name}'") + + def test_prepare_template_config_with_params(self, template_manager): + """Test preparing template configuration with parameters""" + print("Testing Template Config Preparation with Parameters...") + + templates = template_manager.list_templates() + + if not templates: + print("No templates available for config preparation test") + return + + # Test with first available template + template_name = list(templates.keys())[0] + + # Test with parameters + params = { + 'duration': 120, + 'namespace': 'test-namespace' + } + + config_path = template_manager.prepare_template_config(template_name, params) + if config_path: + print(f"Prepared config with params for template '{template_name}': {config_path}") + assert os.path.exists(config_path) + + # Clean up + os.remove(config_path) + else: + print(f"Failed to prepare config with params for template '{template_name}'") + + def test_template_categories(self, template_manager): + """Test getting template categories""" + print("Testing Template Categories...") + + categories = template_manager.get_template_categories() + print(f"Found {len(categories)} categories: {categories}") + assert isinstance(categories, list) + + def test_templates_by_category(self, template_manager): + """Test filtering templates by category""" + print("Testing Templates by Category...") + + categories = template_manager.get_template_categories() + + if categories: + category = categories[0] + filtered_templates = template_manager.get_templates_by_category(category) + print(f"Found {len(filtered_templates)} templates in category '{category}'") + assert isinstance(filtered_templates, dict) + + +if __name__ == "__main__": + pytest.main([__file__, "-v"]) diff --git a/tests/test_time_actions_scenario_plugin.py b/tests/test_time_actions_scenario_plugin.py index 524e9b3f5..093a1d3d8 100644 --- a/tests/test_time_actions_scenario_plugin.py +++ b/tests/test_time_actions_scenario_plugin.py @@ -1,4 +1,19 @@ -#!/usr/bin/env python3 +#!/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. + """ Test suite for TimeActionsScenarioPlugin class diff --git a/tests/test_utils_network_chaos.py b/tests/test_utils_network_chaos.py index 28385fd27..1e6dd454a 100644 --- a/tests/test_utils_network_chaos.py +++ b/tests/test_utils_network_chaos.py @@ -1,4 +1,19 @@ -#!/usr/bin/env python3 +#!/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. + """ Test suite for utils_network_chaos module diff --git a/tests/test_virt_checker.py b/tests/test_virt_checker.py index 6e3d45970..192dc0a1f 100644 --- a/tests/test_virt_checker.py +++ b/tests/test_virt_checker.py @@ -1,4 +1,19 @@ -#!/usr/bin/env python3 +#!/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. + """ Test suite for VirtChecker class diff --git a/tests/test_vmware_node_scenarios.py b/tests/test_vmware_node_scenarios.py index 327495513..a2f58d589 100644 --- a/tests/test_vmware_node_scenarios.py +++ b/tests/test_vmware_node_scenarios.py @@ -1,4 +1,19 @@ -#!/usr/bin/env python3 +#!/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. + """ Test suite for VMWare node scenarios diff --git a/tests/test_zone_outage_scenario_plugin.py b/tests/test_zone_outage_scenario_plugin.py index 10143c9a5..d0ace9681 100644 --- a/tests/test_zone_outage_scenario_plugin.py +++ b/tests/test_zone_outage_scenario_plugin.py @@ -1,4 +1,19 @@ -#!/usr/bin/env python3 +#!/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. + """ Test suite for ZoneOutageScenarioPlugin class diff --git a/utils/chaos_recommender/chaos_recommender.py b/utils/chaos_recommender/chaos_recommender.py index 4b3af527d..3f0e10fc6 100644 --- a/utils/chaos_recommender/chaos_recommender.py +++ b/utils/chaos_recommender/chaos_recommender.py @@ -1,3 +1,19 @@ +#!/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. + import argparse import json import logging