Coverage for ocp_resources/machine_config_pool.py: 0%

26 statements  

« prev     ^ index     » next       coverage.py v7.6.10, created at 2025-01-30 10:48 +0200

1from ocp_resources.resource import Resource 

2 

3 

4class MachineConfigPool(Resource): 

5 """ 

6 MachineConfigPool object. API reference: 

7 https://docs.openshift.com/container-platform/4.12/rest_api/machine_apis/machineconfigpool-machineconfiguration-openshift-io-v1.html 

8 

9 Args: 

10 node_selector (dict): Matching dict with supported selector logic, either labels or expressions. 

11 matchLabels example: 

12 matchLabels: 

13 component: <some component> 

14 matchExpressions: 

15 - { key: tier, operator: In, values: [cache] } 

16 - { key: environment, operator: NotIn, values: [dev] } 

17 matchExpressions example: 

18 matchExpressions: 

19 - key: <resource name>/role 

20 operator: In 

21 values: 

22 - value_1 

23 - value_2 

24 machine_config_selector (dict): Matching labels/expressions, to determine which MachineConfig objects 

25 to apply this MachineConfigPool object. 

26 For filtering based on labels, the `matchLabels` dict is used - the same way as it is used in the 

27 nodeSelector (see the example of node_selector["matchLabels"] above). 

28 For filtering based on expressions, the `matchExpressions` dict is used - the same way as it is used in the 

29 nodeSelector (see the example of node_selector["matchExpressions"] above). 

30 configuration (dict): Targeted MachineConfig object for the machine config pool, in the following format: 

31 {"name": (str), "source": <List of dicts, each representing a MachineConfig resource>} 

32 max_unavailable (int or str): Number/percentage of nodes that can go Unavailable during an update. 

33 paused (bool): Whether changes to this MachineConfigPool should be stopped. 

34 """ 

35 

36 api_group = Resource.ApiGroup.MACHINECONFIGURATION_OPENSHIFT_IO 

37 

38 class Status(Resource.Status): 

39 UPDATED = "Updated" 

40 UPDATING = "Updating" 

41 

42 def __init__( 

43 self, 

44 machine_config_selector=None, 

45 configuration=None, 

46 node_selector=None, 

47 max_unavailable=None, 

48 paused=None, 

49 **kwargs, 

50 ): 

51 super().__init__(**kwargs) 

52 self.configuration = configuration 

53 self.machine_config_selector = machine_config_selector 

54 self.node_selector = node_selector 

55 self.max_unavailable = max_unavailable 

56 self.paused = paused 

57 

58 def to_dict(self) -> None: 

59 super().to_dict() 

60 if not self.kind_dict and not self.yaml_file: 

61 self.res.update( 

62 { 

63 "spec": { 

64 "configuration": self.configuration or {}, 

65 }, 

66 }, 

67 ) 

68 

69 manifest_spec = self.res["spec"] 

70 if self.machine_config_selector: 

71 manifest_spec["machineConfigSelector"] = self.machine_config_selector 

72 

73 if self.node_selector: 

74 manifest_spec["nodeSelector"] = self.node_selector 

75 

76 if self.max_unavailable: 

77 manifest_spec["maxUnavailable"] = self.max_unavailable 

78 

79 if self.paused: 

80 manifest_spec["paused"] = self.paused