kailash 0.8.3__py3-none-any.whl → 0.8.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- kailash/__init__.py +1 -7
- kailash/cli/__init__.py +11 -1
- kailash/cli/validation_audit.py +570 -0
- kailash/core/actors/supervisor.py +1 -1
- kailash/core/resilience/circuit_breaker.py +71 -1
- kailash/core/resilience/health_monitor.py +172 -0
- kailash/edge/compliance.py +33 -0
- kailash/edge/consistency.py +609 -0
- kailash/edge/coordination/__init__.py +30 -0
- kailash/edge/coordination/global_ordering.py +355 -0
- kailash/edge/coordination/leader_election.py +217 -0
- kailash/edge/coordination/partition_detector.py +296 -0
- kailash/edge/coordination/raft.py +485 -0
- kailash/edge/discovery.py +63 -1
- kailash/edge/migration/__init__.py +19 -0
- kailash/edge/migration/edge_migrator.py +832 -0
- kailash/edge/monitoring/__init__.py +21 -0
- kailash/edge/monitoring/edge_monitor.py +736 -0
- kailash/edge/prediction/__init__.py +10 -0
- kailash/edge/prediction/predictive_warmer.py +591 -0
- kailash/edge/resource/__init__.py +102 -0
- kailash/edge/resource/cloud_integration.py +796 -0
- kailash/edge/resource/cost_optimizer.py +949 -0
- kailash/edge/resource/docker_integration.py +919 -0
- kailash/edge/resource/kubernetes_integration.py +893 -0
- kailash/edge/resource/platform_integration.py +913 -0
- kailash/edge/resource/predictive_scaler.py +959 -0
- kailash/edge/resource/resource_analyzer.py +824 -0
- kailash/edge/resource/resource_pools.py +610 -0
- kailash/integrations/dataflow_edge.py +261 -0
- kailash/mcp_server/registry_integration.py +1 -1
- kailash/monitoring/__init__.py +18 -0
- kailash/monitoring/alerts.py +646 -0
- kailash/monitoring/metrics.py +677 -0
- kailash/nodes/__init__.py +2 -0
- kailash/nodes/ai/__init__.py +17 -0
- kailash/nodes/ai/a2a.py +1914 -43
- kailash/nodes/ai/a2a_backup.py +1807 -0
- kailash/nodes/ai/hybrid_search.py +972 -0
- kailash/nodes/ai/semantic_memory.py +558 -0
- kailash/nodes/ai/streaming_analytics.py +947 -0
- kailash/nodes/base.py +545 -0
- kailash/nodes/edge/__init__.py +36 -0
- kailash/nodes/edge/base.py +240 -0
- kailash/nodes/edge/cloud_node.py +710 -0
- kailash/nodes/edge/coordination.py +239 -0
- kailash/nodes/edge/docker_node.py +825 -0
- kailash/nodes/edge/edge_data.py +582 -0
- kailash/nodes/edge/edge_migration_node.py +392 -0
- kailash/nodes/edge/edge_monitoring_node.py +421 -0
- kailash/nodes/edge/edge_state.py +673 -0
- kailash/nodes/edge/edge_warming_node.py +393 -0
- kailash/nodes/edge/kubernetes_node.py +652 -0
- kailash/nodes/edge/platform_node.py +766 -0
- kailash/nodes/edge/resource_analyzer_node.py +378 -0
- kailash/nodes/edge/resource_optimizer_node.py +501 -0
- kailash/nodes/edge/resource_scaler_node.py +397 -0
- kailash/nodes/ports.py +676 -0
- kailash/runtime/local.py +344 -1
- kailash/runtime/validation/__init__.py +20 -0
- kailash/runtime/validation/connection_context.py +119 -0
- kailash/runtime/validation/enhanced_error_formatter.py +202 -0
- kailash/runtime/validation/error_categorizer.py +164 -0
- kailash/runtime/validation/metrics.py +380 -0
- kailash/runtime/validation/performance.py +615 -0
- kailash/runtime/validation/suggestion_engine.py +212 -0
- kailash/testing/fixtures.py +2 -2
- kailash/workflow/builder.py +234 -8
- kailash/workflow/contracts.py +418 -0
- kailash/workflow/edge_infrastructure.py +369 -0
- kailash/workflow/migration.py +3 -3
- kailash/workflow/type_inference.py +669 -0
- {kailash-0.8.3.dist-info → kailash-0.8.5.dist-info}/METADATA +44 -27
- {kailash-0.8.3.dist-info → kailash-0.8.5.dist-info}/RECORD +78 -28
- kailash/nexus/__init__.py +0 -21
- kailash/nexus/cli/__init__.py +0 -5
- kailash/nexus/cli/__main__.py +0 -6
- kailash/nexus/cli/main.py +0 -176
- kailash/nexus/factory.py +0 -413
- kailash/nexus/gateway.py +0 -545
- {kailash-0.8.3.dist-info → kailash-0.8.5.dist-info}/WHEEL +0 -0
- {kailash-0.8.3.dist-info → kailash-0.8.5.dist-info}/entry_points.txt +0 -0
- {kailash-0.8.3.dist-info → kailash-0.8.5.dist-info}/licenses/LICENSE +0 -0
- {kailash-0.8.3.dist-info → kailash-0.8.5.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,652 @@
|
|
1
|
+
"""Kubernetes integration node for edge resource management."""
|
2
|
+
|
3
|
+
from typing import Any, Dict, List, Optional
|
4
|
+
|
5
|
+
from kailash.edge.resource.kubernetes_integration import (
|
6
|
+
KubernetesIntegration,
|
7
|
+
KubernetesResource,
|
8
|
+
KubernetesResourceType,
|
9
|
+
PodScalingSpec,
|
10
|
+
ScalingPolicy,
|
11
|
+
)
|
12
|
+
from kailash.nodes.base import NodeParameter, register_node
|
13
|
+
from kailash.nodes.base_async import AsyncNode
|
14
|
+
|
15
|
+
|
16
|
+
@register_node()
|
17
|
+
class KubernetesNode(AsyncNode):
|
18
|
+
"""Node for Kubernetes resource management and integration."""
|
19
|
+
|
20
|
+
def __init__(self, **kwargs):
|
21
|
+
super().__init__(**kwargs)
|
22
|
+
self.kubernetes_integration: Optional[KubernetesIntegration] = None
|
23
|
+
|
24
|
+
@property
|
25
|
+
def input_parameters(self) -> Dict[str, NodeParameter]:
|
26
|
+
"""Define input parameters."""
|
27
|
+
return {
|
28
|
+
"operation": NodeParameter(
|
29
|
+
name="operation",
|
30
|
+
type=str,
|
31
|
+
required=True,
|
32
|
+
description="Operation to perform",
|
33
|
+
enum=[
|
34
|
+
"initialize",
|
35
|
+
"create_resource",
|
36
|
+
"update_resource",
|
37
|
+
"delete_resource",
|
38
|
+
"get_status",
|
39
|
+
"list_resources",
|
40
|
+
"scale_deployment",
|
41
|
+
"create_autoscaler",
|
42
|
+
"get_cluster_info",
|
43
|
+
"start_monitoring",
|
44
|
+
"stop_monitoring",
|
45
|
+
],
|
46
|
+
),
|
47
|
+
"kubeconfig_path": NodeParameter(
|
48
|
+
name="kubeconfig_path",
|
49
|
+
type=str,
|
50
|
+
required=False,
|
51
|
+
description="Path to kubeconfig file",
|
52
|
+
),
|
53
|
+
"context_name": NodeParameter(
|
54
|
+
name="context_name",
|
55
|
+
type=str,
|
56
|
+
required=False,
|
57
|
+
description="Kubernetes context to use",
|
58
|
+
),
|
59
|
+
"namespace": NodeParameter(
|
60
|
+
name="namespace",
|
61
|
+
type=str,
|
62
|
+
required=False,
|
63
|
+
description="Kubernetes namespace",
|
64
|
+
),
|
65
|
+
# Resource operations
|
66
|
+
"resource_name": NodeParameter(
|
67
|
+
name="resource_name",
|
68
|
+
type=str,
|
69
|
+
required=False,
|
70
|
+
description="Kubernetes resource name",
|
71
|
+
),
|
72
|
+
"resource_type": NodeParameter(
|
73
|
+
name="resource_type",
|
74
|
+
type=str,
|
75
|
+
required=False,
|
76
|
+
description="Kubernetes resource type",
|
77
|
+
enum=[
|
78
|
+
"deployment",
|
79
|
+
"service",
|
80
|
+
"configmap",
|
81
|
+
"secret",
|
82
|
+
"pod",
|
83
|
+
"persistent_volume",
|
84
|
+
"persistent_volume_claim",
|
85
|
+
"ingress",
|
86
|
+
"horizontal_pod_autoscaler",
|
87
|
+
],
|
88
|
+
),
|
89
|
+
"resource_spec": NodeParameter(
|
90
|
+
name="resource_spec",
|
91
|
+
type=dict,
|
92
|
+
required=False,
|
93
|
+
description="Kubernetes resource specification",
|
94
|
+
),
|
95
|
+
"labels": NodeParameter(
|
96
|
+
name="labels", type=dict, required=False, description="Resource labels"
|
97
|
+
),
|
98
|
+
"annotations": NodeParameter(
|
99
|
+
name="annotations",
|
100
|
+
type=dict,
|
101
|
+
required=False,
|
102
|
+
description="Resource annotations",
|
103
|
+
),
|
104
|
+
"edge_node": NodeParameter(
|
105
|
+
name="edge_node",
|
106
|
+
type=str,
|
107
|
+
required=False,
|
108
|
+
description="Target edge node for resource placement",
|
109
|
+
),
|
110
|
+
# Scaling operations
|
111
|
+
"deployment_name": NodeParameter(
|
112
|
+
name="deployment_name",
|
113
|
+
type=str,
|
114
|
+
required=False,
|
115
|
+
description="Deployment name for scaling",
|
116
|
+
),
|
117
|
+
"replicas": NodeParameter(
|
118
|
+
name="replicas",
|
119
|
+
type=int,
|
120
|
+
required=False,
|
121
|
+
description="Target replica count",
|
122
|
+
),
|
123
|
+
"min_replicas": NodeParameter(
|
124
|
+
name="min_replicas",
|
125
|
+
type=int,
|
126
|
+
required=False,
|
127
|
+
description="Minimum replica count for autoscaling",
|
128
|
+
),
|
129
|
+
"max_replicas": NodeParameter(
|
130
|
+
name="max_replicas",
|
131
|
+
type=int,
|
132
|
+
required=False,
|
133
|
+
description="Maximum replica count for autoscaling",
|
134
|
+
),
|
135
|
+
"target_cpu_utilization": NodeParameter(
|
136
|
+
name="target_cpu_utilization",
|
137
|
+
type=float,
|
138
|
+
required=False,
|
139
|
+
description="Target CPU utilization for autoscaling (0.0-1.0)",
|
140
|
+
),
|
141
|
+
"target_memory_utilization": NodeParameter(
|
142
|
+
name="target_memory_utilization",
|
143
|
+
type=float,
|
144
|
+
required=False,
|
145
|
+
description="Target memory utilization for autoscaling (0.0-1.0)",
|
146
|
+
),
|
147
|
+
# List operations
|
148
|
+
"label_selector": NodeParameter(
|
149
|
+
name="label_selector",
|
150
|
+
type=dict,
|
151
|
+
required=False,
|
152
|
+
description="Label selector for filtering resources",
|
153
|
+
),
|
154
|
+
}
|
155
|
+
|
156
|
+
@property
|
157
|
+
def output_parameters(self) -> Dict[str, NodeParameter]:
|
158
|
+
"""Define output parameters."""
|
159
|
+
return {
|
160
|
+
"status": NodeParameter(
|
161
|
+
name="status", type=str, description="Operation status"
|
162
|
+
),
|
163
|
+
"result": NodeParameter(
|
164
|
+
name="result", type=dict, description="Operation result"
|
165
|
+
),
|
166
|
+
"resources": NodeParameter(
|
167
|
+
name="resources", type=list, description="List of resources"
|
168
|
+
),
|
169
|
+
"cluster_info": NodeParameter(
|
170
|
+
name="cluster_info", type=dict, description="Cluster information"
|
171
|
+
),
|
172
|
+
"resource_created": NodeParameter(
|
173
|
+
name="resource_created",
|
174
|
+
type=bool,
|
175
|
+
description="Whether resource was created",
|
176
|
+
),
|
177
|
+
"resource_updated": NodeParameter(
|
178
|
+
name="resource_updated",
|
179
|
+
type=bool,
|
180
|
+
description="Whether resource was updated",
|
181
|
+
),
|
182
|
+
"resource_deleted": NodeParameter(
|
183
|
+
name="resource_deleted",
|
184
|
+
type=bool,
|
185
|
+
description="Whether resource was deleted",
|
186
|
+
),
|
187
|
+
"deployment_scaled": NodeParameter(
|
188
|
+
name="deployment_scaled",
|
189
|
+
type=bool,
|
190
|
+
description="Whether deployment was scaled",
|
191
|
+
),
|
192
|
+
"autoscaler_created": NodeParameter(
|
193
|
+
name="autoscaler_created",
|
194
|
+
type=bool,
|
195
|
+
description="Whether autoscaler was created",
|
196
|
+
),
|
197
|
+
"monitoring_started": NodeParameter(
|
198
|
+
name="monitoring_started",
|
199
|
+
type=bool,
|
200
|
+
description="Whether monitoring was started",
|
201
|
+
),
|
202
|
+
"monitoring_stopped": NodeParameter(
|
203
|
+
name="monitoring_stopped",
|
204
|
+
type=bool,
|
205
|
+
description="Whether monitoring was stopped",
|
206
|
+
),
|
207
|
+
}
|
208
|
+
|
209
|
+
def get_parameters(self) -> Dict[str, NodeParameter]:
|
210
|
+
"""Get all parameters for this node."""
|
211
|
+
return self.input_parameters
|
212
|
+
|
213
|
+
async def async_run(self, **kwargs) -> Dict[str, Any]:
|
214
|
+
"""Execute Kubernetes operation.
|
215
|
+
|
216
|
+
Args:
|
217
|
+
**kwargs: Operation parameters
|
218
|
+
|
219
|
+
Returns:
|
220
|
+
Operation result
|
221
|
+
"""
|
222
|
+
operation = kwargs.get("operation")
|
223
|
+
|
224
|
+
if not operation:
|
225
|
+
return {"status": "error", "error": "Operation is required"}
|
226
|
+
|
227
|
+
try:
|
228
|
+
if operation == "initialize":
|
229
|
+
return await self._initialize_kubernetes(**kwargs)
|
230
|
+
elif operation == "create_resource":
|
231
|
+
return await self._create_resource(**kwargs)
|
232
|
+
elif operation == "update_resource":
|
233
|
+
return await self._update_resource(**kwargs)
|
234
|
+
elif operation == "delete_resource":
|
235
|
+
return await self._delete_resource(**kwargs)
|
236
|
+
elif operation == "get_status":
|
237
|
+
return await self._get_resource_status(**kwargs)
|
238
|
+
elif operation == "list_resources":
|
239
|
+
return await self._list_resources(**kwargs)
|
240
|
+
elif operation == "scale_deployment":
|
241
|
+
return await self._scale_deployment(**kwargs)
|
242
|
+
elif operation == "create_autoscaler":
|
243
|
+
return await self._create_autoscaler(**kwargs)
|
244
|
+
elif operation == "get_cluster_info":
|
245
|
+
return await self._get_cluster_info(**kwargs)
|
246
|
+
elif operation == "start_monitoring":
|
247
|
+
return await self._start_monitoring(**kwargs)
|
248
|
+
elif operation == "stop_monitoring":
|
249
|
+
return await self._stop_monitoring(**kwargs)
|
250
|
+
else:
|
251
|
+
return {"status": "error", "error": f"Unknown operation: {operation}"}
|
252
|
+
|
253
|
+
except Exception as e:
|
254
|
+
return {
|
255
|
+
"status": "error",
|
256
|
+
"error": f"Kubernetes operation failed: {str(e)}",
|
257
|
+
}
|
258
|
+
|
259
|
+
async def _initialize_kubernetes(self, **kwargs) -> Dict[str, Any]:
|
260
|
+
"""Initialize Kubernetes integration."""
|
261
|
+
kubeconfig_path = kwargs.get("kubeconfig_path")
|
262
|
+
context_name = kwargs.get("context_name")
|
263
|
+
namespace = kwargs.get("namespace", "default")
|
264
|
+
|
265
|
+
try:
|
266
|
+
self.kubernetes_integration = KubernetesIntegration(
|
267
|
+
kubeconfig_path=kubeconfig_path,
|
268
|
+
context_name=context_name,
|
269
|
+
namespace=namespace,
|
270
|
+
)
|
271
|
+
|
272
|
+
await self.kubernetes_integration.initialize()
|
273
|
+
|
274
|
+
return {
|
275
|
+
"status": "success",
|
276
|
+
"kubernetes_initialized": True,
|
277
|
+
"namespace": namespace,
|
278
|
+
"result": {
|
279
|
+
"message": "Kubernetes integration initialized successfully",
|
280
|
+
"namespace": namespace,
|
281
|
+
"kubeconfig_path": kubeconfig_path,
|
282
|
+
"context_name": context_name,
|
283
|
+
},
|
284
|
+
}
|
285
|
+
|
286
|
+
except Exception as e:
|
287
|
+
return {
|
288
|
+
"status": "error",
|
289
|
+
"kubernetes_initialized": False,
|
290
|
+
"error": f"Failed to initialize Kubernetes: {str(e)}",
|
291
|
+
}
|
292
|
+
|
293
|
+
async def _create_resource(self, **kwargs) -> Dict[str, Any]:
|
294
|
+
"""Create Kubernetes resource."""
|
295
|
+
if not self.kubernetes_integration:
|
296
|
+
await self._initialize_kubernetes(**kwargs)
|
297
|
+
|
298
|
+
resource_name = kwargs.get("resource_name")
|
299
|
+
resource_type = kwargs.get("resource_type")
|
300
|
+
resource_spec = kwargs.get("resource_spec", {})
|
301
|
+
namespace = kwargs.get("namespace", "default")
|
302
|
+
labels = kwargs.get("labels", {})
|
303
|
+
annotations = kwargs.get("annotations", {})
|
304
|
+
edge_node = kwargs.get("edge_node")
|
305
|
+
|
306
|
+
if not resource_name or not resource_type or not resource_spec:
|
307
|
+
return {
|
308
|
+
"status": "error",
|
309
|
+
"resource_created": False,
|
310
|
+
"error": "resource_name, resource_type, and resource_spec are required",
|
311
|
+
}
|
312
|
+
|
313
|
+
try:
|
314
|
+
# Convert string type to enum
|
315
|
+
k8s_resource_type = KubernetesResourceType(resource_type)
|
316
|
+
|
317
|
+
# Create resource object
|
318
|
+
resource = KubernetesResource(
|
319
|
+
name=resource_name,
|
320
|
+
namespace=namespace,
|
321
|
+
resource_type=k8s_resource_type,
|
322
|
+
spec=resource_spec,
|
323
|
+
labels=labels,
|
324
|
+
annotations=annotations,
|
325
|
+
edge_node=edge_node,
|
326
|
+
)
|
327
|
+
|
328
|
+
# Create resource in cluster
|
329
|
+
result = await self.kubernetes_integration.create_resource(resource)
|
330
|
+
|
331
|
+
return {
|
332
|
+
"status": result.get("status", "unknown"),
|
333
|
+
"resource_created": result.get("status") == "created",
|
334
|
+
"result": result,
|
335
|
+
}
|
336
|
+
|
337
|
+
except Exception as e:
|
338
|
+
return {
|
339
|
+
"status": "error",
|
340
|
+
"resource_created": False,
|
341
|
+
"error": f"Failed to create resource: {str(e)}",
|
342
|
+
}
|
343
|
+
|
344
|
+
async def _update_resource(self, **kwargs) -> Dict[str, Any]:
|
345
|
+
"""Update Kubernetes resource."""
|
346
|
+
if not self.kubernetes_integration:
|
347
|
+
await self._initialize_kubernetes(**kwargs)
|
348
|
+
|
349
|
+
resource_name = kwargs.get("resource_name")
|
350
|
+
resource_type = kwargs.get("resource_type")
|
351
|
+
resource_spec = kwargs.get("resource_spec", {})
|
352
|
+
namespace = kwargs.get("namespace", "default")
|
353
|
+
labels = kwargs.get("labels", {})
|
354
|
+
annotations = kwargs.get("annotations", {})
|
355
|
+
edge_node = kwargs.get("edge_node")
|
356
|
+
|
357
|
+
if not resource_name or not resource_type:
|
358
|
+
return {
|
359
|
+
"status": "error",
|
360
|
+
"resource_updated": False,
|
361
|
+
"error": "resource_name and resource_type are required",
|
362
|
+
}
|
363
|
+
|
364
|
+
try:
|
365
|
+
# Convert string type to enum
|
366
|
+
k8s_resource_type = KubernetesResourceType(resource_type)
|
367
|
+
|
368
|
+
# Create resource object
|
369
|
+
resource = KubernetesResource(
|
370
|
+
name=resource_name,
|
371
|
+
namespace=namespace,
|
372
|
+
resource_type=k8s_resource_type,
|
373
|
+
spec=resource_spec,
|
374
|
+
labels=labels,
|
375
|
+
annotations=annotations,
|
376
|
+
edge_node=edge_node,
|
377
|
+
)
|
378
|
+
|
379
|
+
# Update resource in cluster
|
380
|
+
result = await self.kubernetes_integration.update_resource(resource)
|
381
|
+
|
382
|
+
return {
|
383
|
+
"status": result.get("status", "unknown"),
|
384
|
+
"resource_updated": result.get("status") == "updated",
|
385
|
+
"result": result,
|
386
|
+
}
|
387
|
+
|
388
|
+
except Exception as e:
|
389
|
+
return {
|
390
|
+
"status": "error",
|
391
|
+
"resource_updated": False,
|
392
|
+
"error": f"Failed to update resource: {str(e)}",
|
393
|
+
}
|
394
|
+
|
395
|
+
async def _delete_resource(self, **kwargs) -> Dict[str, Any]:
|
396
|
+
"""Delete Kubernetes resource."""
|
397
|
+
if not self.kubernetes_integration:
|
398
|
+
await self._initialize_kubernetes(**kwargs)
|
399
|
+
|
400
|
+
resource_name = kwargs.get("resource_name")
|
401
|
+
resource_type = kwargs.get("resource_type")
|
402
|
+
namespace = kwargs.get("namespace", "default")
|
403
|
+
|
404
|
+
if not resource_name or not resource_type:
|
405
|
+
return {
|
406
|
+
"status": "error",
|
407
|
+
"resource_deleted": False,
|
408
|
+
"error": "resource_name and resource_type are required",
|
409
|
+
}
|
410
|
+
|
411
|
+
try:
|
412
|
+
# Convert string type to enum
|
413
|
+
k8s_resource_type = KubernetesResourceType(resource_type)
|
414
|
+
|
415
|
+
# Delete resource from cluster
|
416
|
+
result = await self.kubernetes_integration.delete_resource(
|
417
|
+
resource_name, namespace, k8s_resource_type
|
418
|
+
)
|
419
|
+
|
420
|
+
return {
|
421
|
+
"status": result.get("status", "unknown"),
|
422
|
+
"resource_deleted": result.get("status") == "deleted",
|
423
|
+
"result": result,
|
424
|
+
}
|
425
|
+
|
426
|
+
except Exception as e:
|
427
|
+
return {
|
428
|
+
"status": "error",
|
429
|
+
"resource_deleted": False,
|
430
|
+
"error": f"Failed to delete resource: {str(e)}",
|
431
|
+
}
|
432
|
+
|
433
|
+
async def _get_resource_status(self, **kwargs) -> Dict[str, Any]:
|
434
|
+
"""Get Kubernetes resource status."""
|
435
|
+
if not self.kubernetes_integration:
|
436
|
+
await self._initialize_kubernetes(**kwargs)
|
437
|
+
|
438
|
+
resource_name = kwargs.get("resource_name")
|
439
|
+
resource_type = kwargs.get("resource_type")
|
440
|
+
namespace = kwargs.get("namespace", "default")
|
441
|
+
|
442
|
+
if not resource_name or not resource_type:
|
443
|
+
return {
|
444
|
+
"status": "error",
|
445
|
+
"error": "resource_name and resource_type are required",
|
446
|
+
}
|
447
|
+
|
448
|
+
try:
|
449
|
+
# Convert string type to enum
|
450
|
+
k8s_resource_type = KubernetesResourceType(resource_type)
|
451
|
+
|
452
|
+
# Get resource status
|
453
|
+
status = await self.kubernetes_integration.get_resource_status(
|
454
|
+
resource_name, namespace, k8s_resource_type
|
455
|
+
)
|
456
|
+
|
457
|
+
return {"status": "success", "result": status}
|
458
|
+
|
459
|
+
except Exception as e:
|
460
|
+
return {
|
461
|
+
"status": "error",
|
462
|
+
"error": f"Failed to get resource status: {str(e)}",
|
463
|
+
}
|
464
|
+
|
465
|
+
async def _list_resources(self, **kwargs) -> Dict[str, Any]:
|
466
|
+
"""List Kubernetes resources."""
|
467
|
+
if not self.kubernetes_integration:
|
468
|
+
await self._initialize_kubernetes(**kwargs)
|
469
|
+
|
470
|
+
namespace = kwargs.get("namespace")
|
471
|
+
resource_type = kwargs.get("resource_type")
|
472
|
+
label_selector = kwargs.get("label_selector", {})
|
473
|
+
|
474
|
+
try:
|
475
|
+
# Convert string type to enum if provided
|
476
|
+
k8s_resource_type = None
|
477
|
+
if resource_type:
|
478
|
+
k8s_resource_type = KubernetesResourceType(resource_type)
|
479
|
+
|
480
|
+
# List resources
|
481
|
+
resources = await self.kubernetes_integration.list_resources(
|
482
|
+
namespace=namespace,
|
483
|
+
resource_type=k8s_resource_type,
|
484
|
+
labels=label_selector,
|
485
|
+
)
|
486
|
+
|
487
|
+
return {
|
488
|
+
"status": "success",
|
489
|
+
"resources": resources,
|
490
|
+
"result": {"resource_count": len(resources), "resources": resources},
|
491
|
+
}
|
492
|
+
|
493
|
+
except Exception as e:
|
494
|
+
return {
|
495
|
+
"status": "error",
|
496
|
+
"resources": [],
|
497
|
+
"error": f"Failed to list resources: {str(e)}",
|
498
|
+
}
|
499
|
+
|
500
|
+
async def _scale_deployment(self, **kwargs) -> Dict[str, Any]:
|
501
|
+
"""Scale Kubernetes deployment."""
|
502
|
+
if not self.kubernetes_integration:
|
503
|
+
await self._initialize_kubernetes(**kwargs)
|
504
|
+
|
505
|
+
deployment_name = kwargs.get("deployment_name")
|
506
|
+
replicas = kwargs.get("replicas")
|
507
|
+
namespace = kwargs.get("namespace", "default")
|
508
|
+
|
509
|
+
if not deployment_name or replicas is None:
|
510
|
+
return {
|
511
|
+
"status": "error",
|
512
|
+
"deployment_scaled": False,
|
513
|
+
"error": "deployment_name and replicas are required",
|
514
|
+
}
|
515
|
+
|
516
|
+
try:
|
517
|
+
# Scale deployment
|
518
|
+
result = await self.kubernetes_integration.scale_deployment(
|
519
|
+
deployment_name, namespace, replicas
|
520
|
+
)
|
521
|
+
|
522
|
+
return {
|
523
|
+
"status": result.get("status", "unknown"),
|
524
|
+
"deployment_scaled": result.get("status") == "scaled",
|
525
|
+
"result": result,
|
526
|
+
}
|
527
|
+
|
528
|
+
except Exception as e:
|
529
|
+
return {
|
530
|
+
"status": "error",
|
531
|
+
"deployment_scaled": False,
|
532
|
+
"error": f"Failed to scale deployment: {str(e)}",
|
533
|
+
}
|
534
|
+
|
535
|
+
async def _create_autoscaler(self, **kwargs) -> Dict[str, Any]:
|
536
|
+
"""Create Kubernetes autoscaler."""
|
537
|
+
if not self.kubernetes_integration:
|
538
|
+
await self._initialize_kubernetes(**kwargs)
|
539
|
+
|
540
|
+
deployment_name = kwargs.get("deployment_name")
|
541
|
+
namespace = kwargs.get("namespace", "default")
|
542
|
+
min_replicas = kwargs.get("min_replicas", 1)
|
543
|
+
max_replicas = kwargs.get("max_replicas", 10)
|
544
|
+
target_cpu_utilization = kwargs.get("target_cpu_utilization", 0.8)
|
545
|
+
target_memory_utilization = kwargs.get("target_memory_utilization")
|
546
|
+
|
547
|
+
if not deployment_name:
|
548
|
+
return {
|
549
|
+
"status": "error",
|
550
|
+
"autoscaler_created": False,
|
551
|
+
"error": "deployment_name is required",
|
552
|
+
}
|
553
|
+
|
554
|
+
try:
|
555
|
+
# Create scaling specification
|
556
|
+
scaling_spec = PodScalingSpec(
|
557
|
+
min_replicas=min_replicas,
|
558
|
+
max_replicas=max_replicas,
|
559
|
+
target_cpu_utilization=target_cpu_utilization,
|
560
|
+
target_memory_utilization=target_memory_utilization,
|
561
|
+
)
|
562
|
+
|
563
|
+
# Create autoscaler
|
564
|
+
result = await self.kubernetes_integration.create_autoscaler(
|
565
|
+
deployment_name, namespace, scaling_spec
|
566
|
+
)
|
567
|
+
|
568
|
+
return {
|
569
|
+
"status": result.get("status", "unknown"),
|
570
|
+
"autoscaler_created": result.get("status") == "created",
|
571
|
+
"result": result,
|
572
|
+
}
|
573
|
+
|
574
|
+
except Exception as e:
|
575
|
+
return {
|
576
|
+
"status": "error",
|
577
|
+
"autoscaler_created": False,
|
578
|
+
"error": f"Failed to create autoscaler: {str(e)}",
|
579
|
+
}
|
580
|
+
|
581
|
+
async def _get_cluster_info(self, **kwargs) -> Dict[str, Any]:
|
582
|
+
"""Get Kubernetes cluster information."""
|
583
|
+
if not self.kubernetes_integration:
|
584
|
+
await self._initialize_kubernetes(**kwargs)
|
585
|
+
|
586
|
+
try:
|
587
|
+
# Get cluster info
|
588
|
+
cluster_info = await self.kubernetes_integration.get_cluster_info()
|
589
|
+
|
590
|
+
return {
|
591
|
+
"status": "success",
|
592
|
+
"cluster_info": cluster_info,
|
593
|
+
"result": cluster_info,
|
594
|
+
}
|
595
|
+
|
596
|
+
except Exception as e:
|
597
|
+
return {
|
598
|
+
"status": "error",
|
599
|
+
"cluster_info": {},
|
600
|
+
"error": f"Failed to get cluster info: {str(e)}",
|
601
|
+
}
|
602
|
+
|
603
|
+
async def _start_monitoring(self, **kwargs) -> Dict[str, Any]:
|
604
|
+
"""Start Kubernetes resource monitoring."""
|
605
|
+
if not self.kubernetes_integration:
|
606
|
+
await self._initialize_kubernetes(**kwargs)
|
607
|
+
|
608
|
+
try:
|
609
|
+
# Start monitoring
|
610
|
+
await self.kubernetes_integration.start_monitoring()
|
611
|
+
|
612
|
+
return {
|
613
|
+
"status": "success",
|
614
|
+
"monitoring_started": True,
|
615
|
+
"result": {
|
616
|
+
"message": "Kubernetes resource monitoring started",
|
617
|
+
"monitoring_interval": self.kubernetes_integration.monitoring_interval,
|
618
|
+
},
|
619
|
+
}
|
620
|
+
|
621
|
+
except Exception as e:
|
622
|
+
return {
|
623
|
+
"status": "error",
|
624
|
+
"monitoring_started": False,
|
625
|
+
"error": f"Failed to start monitoring: {str(e)}",
|
626
|
+
}
|
627
|
+
|
628
|
+
async def _stop_monitoring(self, **kwargs) -> Dict[str, Any]:
|
629
|
+
"""Stop Kubernetes resource monitoring."""
|
630
|
+
if not self.kubernetes_integration:
|
631
|
+
return {
|
632
|
+
"status": "error",
|
633
|
+
"monitoring_stopped": False,
|
634
|
+
"error": "Kubernetes integration not initialized",
|
635
|
+
}
|
636
|
+
|
637
|
+
try:
|
638
|
+
# Stop monitoring
|
639
|
+
await self.kubernetes_integration.stop_monitoring()
|
640
|
+
|
641
|
+
return {
|
642
|
+
"status": "success",
|
643
|
+
"monitoring_stopped": True,
|
644
|
+
"result": {"message": "Kubernetes resource monitoring stopped"},
|
645
|
+
}
|
646
|
+
|
647
|
+
except Exception as e:
|
648
|
+
return {
|
649
|
+
"status": "error",
|
650
|
+
"monitoring_stopped": False,
|
651
|
+
"error": f"Failed to stop monitoring: {str(e)}",
|
652
|
+
}
|