Coverage for gco / models / cluster_models.py: 100%

35 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-30 21:47 +0000

1""" 

2Cluster configuration data models for GCO (Global Capacity Orchestrator on AWS). 

3 

4This module defines dataclasses for EKS cluster configuration including: 

5- ResourceThresholds: CPU/memory/GPU utilization thresholds for health monitoring 

6- ClusterConfig: Complete cluster configuration combining all settings 

7 

8All models include validation in __post_init__ to ensure data integrity. 

9""" 

10 

11from __future__ import annotations 

12 

13from dataclasses import dataclass 

14 

15 

16@dataclass 

17class ResourceThresholds: 

18 """ 

19 Resource utilization thresholds for cluster health monitoring. 

20 

21 When utilization exceeds these thresholds, the cluster is considered unhealthy. 

22 Set any threshold to -1 to disable that check entirely. 

23 

24 Attributes: 

25 cpu_threshold: CPU utilization threshold percentage (0-100, or -1 to disable) 

26 memory_threshold: Memory utilization threshold percentage (0-100, or -1 to disable) 

27 gpu_threshold: GPU utilization threshold percentage (0-100, or -1 to disable) 

28 pending_pods_threshold: Max pending pods before unhealthy (-1 to disable, default: 10) 

29 pending_requested_cpu_vcpus: Max vCPUs requested by pending pods (-1 to disable, default: 100) 

30 pending_requested_memory_gb: Max GB memory requested by pending pods (-1 to disable, default: 200) 

31 pending_requested_gpus: Max GPUs requested by pending pods (-1 to disable, default: 8) 

32 """ 

33 

34 cpu_threshold: int 

35 memory_threshold: int 

36 gpu_threshold: int 

37 pending_pods_threshold: int = 10 

38 pending_requested_cpu_vcpus: int = 100 

39 pending_requested_memory_gb: int = 200 

40 pending_requested_gpus: int = 8 

41 

42 def is_disabled(self, field_name: str) -> bool: 

43 """Check if a threshold is disabled (set to -1).""" 

44 value: int = getattr(self, field_name) 

45 return value == -1 

46 

47 def __post_init__(self) -> None: 

48 """Validate threshold values""" 

49 for field_name, value in [ 

50 ("cpu_threshold", self.cpu_threshold), 

51 ("memory_threshold", self.memory_threshold), 

52 ("gpu_threshold", self.gpu_threshold), 

53 ]: 

54 if not isinstance(value, int) or (value != -1 and not 0 <= value <= 100): 

55 raise ValueError( 

56 f"{field_name} must be an integer between 0 and 100 (or -1 to disable), got {value}" 

57 ) 

58 

59 for field_name, value in [ 

60 ("pending_pods_threshold", self.pending_pods_threshold), 

61 ("pending_requested_cpu_vcpus", self.pending_requested_cpu_vcpus), 

62 ("pending_requested_memory_gb", self.pending_requested_memory_gb), 

63 ("pending_requested_gpus", self.pending_requested_gpus), 

64 ]: 

65 if not isinstance(value, int) or (value != -1 and value < 0): 

66 raise ValueError( 

67 f"{field_name} must be a non-negative integer (or -1 to disable), got {value}" 

68 ) 

69 

70 

71@dataclass 

72class ClusterConfig: 

73 """Complete configuration for an EKS cluster""" 

74 

75 region: str 

76 cluster_name: str 

77 kubernetes_version: str 

78 addons: list[str] 

79 resource_thresholds: ResourceThresholds 

80 

81 def __post_init__(self) -> None: 

82 """Validate cluster configuration""" 

83 if not self.region: 

84 raise ValueError("Region cannot be empty") 

85 

86 if not self.cluster_name: 

87 raise ValueError("Cluster name cannot be empty") 

88 

89 if not self.kubernetes_version: 

90 raise ValueError("Kubernetes version cannot be empty")