Skip to content

Commit 2b7c569

Browse files
authored
litmus and cluster events deprecation (#126)
linting Signed-off-by: Tullio Sebastiani <[email protected]>
1 parent 307051f commit 2b7c569

File tree

5 files changed

+0
-437
lines changed

5 files changed

+0
-437
lines changed

src/krkn_lib/k8s/krkn_kubernetes.py

-164
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212
from functools import partial
1313
from queue import Queue
1414
from typing import Any, Dict, List, Optional
15-
from krkn_lib.version import __version__
1615

1716
import arcaflow_lib_kubernetes
18-
import deprecation
1917
import kubernetes
2018
import urllib3
2119
import yaml
@@ -31,10 +29,7 @@
3129
PVC,
3230
AffectedPod,
3331
ApiRequestException,
34-
ChaosEngine,
35-
ChaosResult,
3632
Container,
37-
LitmusChaosObject,
3833
Pod,
3934
PodsMonitorThread,
4035
PodsStatus,
@@ -1575,82 +1570,6 @@ def get_pod_info(self, name: str, namespace: str = "default") -> Pod:
15751570
)
15761571
return None
15771572

1578-
@deprecation.deprecated(
1579-
deprecated_in="3.1.0",
1580-
removed_in="3.2.0",
1581-
current_version=__version__,
1582-
details="litmus support dropped from krkn",
1583-
)
1584-
def get_litmus_chaos_object(
1585-
self, kind: str, name: str, namespace: str = "default"
1586-
) -> LitmusChaosObject:
1587-
"""
1588-
Retrieves Litmus Chaos CRDs
1589-
1590-
:param kind: the custom resource type
1591-
:param name: the object name
1592-
:param namespace: the namespace (optional default `default`)
1593-
:return: data class object of a subclass of LitmusChaosObject
1594-
"""
1595-
1596-
group = "litmuschaos.io"
1597-
version = "v1alpha1"
1598-
1599-
if kind.lower() == "chaosengine":
1600-
plural = "chaosengines"
1601-
response = self.custom_object_client.get_namespaced_custom_object(
1602-
group=group,
1603-
plural=plural,
1604-
version=version,
1605-
namespace=namespace,
1606-
name=name,
1607-
)
1608-
try:
1609-
engine_status = response["status"]["engineStatus"]
1610-
exp_status = response["status"]["experiments"][0]["status"]
1611-
except Exception:
1612-
engine_status = "Not Initialized"
1613-
exp_status = "Not Initialized"
1614-
custom_object = ChaosEngine(
1615-
kind="ChaosEngine",
1616-
group=group,
1617-
namespace=namespace,
1618-
name=name,
1619-
plural=plural,
1620-
version=version,
1621-
engineStatus=engine_status,
1622-
expStatus=exp_status,
1623-
)
1624-
elif kind.lower() == "chaosresult":
1625-
plural = "chaosresults"
1626-
response = self.custom_object_client.get_namespaced_custom_object(
1627-
group=group,
1628-
plural=plural,
1629-
version=version,
1630-
namespace=namespace,
1631-
name=name,
1632-
)
1633-
try:
1634-
verdict = response["status"]["experimentStatus"]["verdict"]
1635-
fail_step = response["status"]["experimentStatus"]["failStep"]
1636-
except Exception:
1637-
verdict = "N/A"
1638-
fail_step = "N/A"
1639-
custom_object = ChaosResult(
1640-
kind="ChaosResult",
1641-
group=group,
1642-
namespace=namespace,
1643-
name=name,
1644-
plural=plural,
1645-
version=version,
1646-
verdict=verdict,
1647-
failStep=fail_step,
1648-
)
1649-
else:
1650-
logging.error("Invalid litmus chaos custom resource name")
1651-
custom_object = None
1652-
return custom_object
1653-
16541573
def check_if_namespace_exists(self, name: str) -> bool:
16551574
"""
16561575
Check if a namespace exists by parsing through
@@ -2596,89 +2515,6 @@ def collect_and_parse_cluster_events(
25962515

25972516
return events
25982517

2599-
@deprecation.deprecated(
2600-
deprecated_in="3.1.0",
2601-
removed_in="3.2.0",
2602-
current_version=__version__,
2603-
details="replaced by `collect_and_parse_cluster_events`",
2604-
)
2605-
def collect_cluster_events(
2606-
self,
2607-
start_timestamp: int,
2608-
end_timestamp: int,
2609-
local_timezone: str,
2610-
cluster_timezone: str = "UTC",
2611-
limit: int = 500,
2612-
namespace: str = None,
2613-
) -> Optional[str]:
2614-
"""
2615-
Collects cluster events querying `/api/v1/events`
2616-
filtered in a given time interval and writes them in
2617-
a temporary file in json format.
2618-
2619-
:param start_timestamp: timestamp of the minimum date
2620-
after that the event is relevant
2621-
:param end_timestamp: timestamp of the maximum date
2622-
before that the event is relevant
2623-
:param local_timezone: timezone of the local system
2624-
:param cluster_timezone: timezone of the remote cluster
2625-
:param limit: limit of the number of events to be fetched
2626-
from the cluster
2627-
:param namespace: Namespace from which the events must be
2628-
collected, if None all-namespaces will be selected
2629-
2630-
"""
2631-
2632-
try:
2633-
path_params: Dict[str, str] = {}
2634-
query_params = {"limit": limit}
2635-
header_params: Dict[str, str] = {}
2636-
auth_settings = ["BearerToken"]
2637-
header_params["Accept"] = self.api_client.select_header_accept(
2638-
["application/json"]
2639-
)
2640-
2641-
path = "/api/v1/events"
2642-
if namespace:
2643-
path = f"/api/v1/namespaces/{namespace}/events"
2644-
2645-
(data) = self.api_client.call_api(
2646-
path,
2647-
"GET",
2648-
path_params,
2649-
query_params,
2650-
header_params,
2651-
response_type="str",
2652-
auth_settings=auth_settings,
2653-
)
2654-
events = []
2655-
json_obj = ast.literal_eval(data[0])
2656-
events_list = reversed(json_obj["items"])
2657-
for obj in events_list:
2658-
filtered_obj = filter_dictionary(
2659-
obj,
2660-
"firstTimestamp",
2661-
start_timestamp,
2662-
end_timestamp,
2663-
cluster_timezone,
2664-
local_timezone,
2665-
)
2666-
if filtered_obj:
2667-
events.append(filtered_obj)
2668-
2669-
if len(events) > 0:
2670-
file_content = json.dumps(events, indent=2)
2671-
with tempfile.NamedTemporaryFile(
2672-
delete=False, mode="w"
2673-
) as file:
2674-
file.write(file_content)
2675-
file.flush()
2676-
return file.name
2677-
return None
2678-
except Exception as e:
2679-
logging.error(str(e))
2680-
return None
2681-
26822518
def parse_events_from_file(
26832519
self, events_filename: str
26842520
) -> Optional[list[ClusterEvent]]:

src/krkn_lib/models/k8s/models.py

-76
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
from concurrent.futures import Future, ThreadPoolExecutor
22
from dataclasses import dataclass
33
from typing import Optional
4-
from krkn_lib.version import __version__
5-
6-
import deprecation
74

85

96
@dataclass(frozen=True, order=False)
@@ -119,79 +116,6 @@ class Pod:
119116
"""
120117

121118

122-
class LitmusChaosObject:
123-
"""
124-
Data class to hold information regarding
125-
a custom object of litmus project
126-
"""
127-
128-
@deprecation.deprecated(
129-
deprecated_in="3.1.0",
130-
removed_in="3.2.0",
131-
current_version=__version__,
132-
details="litmus support removed from krkn",
133-
)
134-
def __init__(self):
135-
pass
136-
137-
kind: str
138-
"""
139-
Litmus Object Kind
140-
"""
141-
group: str
142-
"""
143-
Api Group
144-
"""
145-
namespace: str
146-
"""
147-
Namespace where the object is deployed
148-
"""
149-
name: str
150-
"""
151-
Object name
152-
"""
153-
plural: str
154-
"""
155-
CRD plural
156-
"""
157-
version: str
158-
"""
159-
Version
160-
"""
161-
162-
163-
class ChaosEngine(LitmusChaosObject):
164-
"""
165-
Data class to hold information
166-
regarding a ChaosEngine object
167-
"""
168-
169-
engineStatus: str
170-
"""
171-
Litmus Chaos engine status
172-
"""
173-
expStatus: str
174-
"""
175-
Litmus Chaos Engine experiment status
176-
"""
177-
178-
179-
class ChaosResult(LitmusChaosObject):
180-
"""
181-
Data class to hold information
182-
regarding a ChaosResult object
183-
"""
184-
185-
verdict: str
186-
"""
187-
Verdict of the chaos experiment
188-
"""
189-
failStep: str
190-
"""
191-
Flag to show the failure step of the ChaosExperiment
192-
"""
193-
194-
195119
class ApiRequestException(Exception):
196120
"""
197121
Generic API Exception raised by k8s package

0 commit comments

Comments
 (0)