Coverage for ocp_resources/machine.py: 0%

38 statements  

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

1# Generated using https://github.com/RedHatQE/openshift-python-wrapper/blob/main/scripts/resource/README.md 

2 

3from typing import Any, Dict, List, Optional 

4from ocp_resources.resource import NamespacedResource 

5 

6 

7class Machine(NamespacedResource): 

8 """ 

9 Machine is the Schema for the machines API Compatibility level 2: Stable within a major release for a minimum of 9 months or 3 minor releases (whichever is longer). 

10 """ 

11 

12 api_group: str = NamespacedResource.ApiGroup.MACHINE_OPENSHIFT_IO 

13 

14 def __init__( 

15 self, 

16 lifecycle_hooks: Optional[Dict[str, Any]] = None, 

17 metadata: Optional[Dict[str, Any]] = None, 

18 provider_id: Optional[str] = "", 

19 provider_spec: Optional[Dict[str, Any]] = None, 

20 taints: Optional[List[Any]] = None, 

21 **kwargs: Any, 

22 ) -> None: 

23 """ 

24 Args: 

25 lifecycle_hooks (Dict[str, Any]): LifecycleHooks allow users to pause operations on the machine at 

26 certain predefined points within the machine lifecycle. 

27 

28 metadata (Dict[str, Any]): ObjectMeta will autopopulate the Node created. Use this to indicate 

29 what labels, annotations, name prefix, etc., should be used when 

30 creating the Node. 

31 

32 provider_id (str): ProviderID is the identification ID of the machine provided by the 

33 provider. This field must match the provider ID as seen on the 

34 node object corresponding to this machine. This field is required 

35 by higher level consumers of cluster-api. Example use case is 

36 cluster autoscaler with cluster-api as provider. Clean-up logic in 

37 the autoscaler compares machines to nodes to find out machines at 

38 provider which could not get registered as Kubernetes nodes. With 

39 cluster-api as a generic out-of-tree provider for autoscaler, this 

40 field is required by autoscaler to be able to have a provider view 

41 of the list of machines. Another list of nodes is queried from the 

42 k8s apiserver and then a comparison is done to find out 

43 unregistered machines and are marked for delete. This field will 

44 be set by the actuators and consumed by higher level entities like 

45 autoscaler that will be interfacing with cluster-api as generic 

46 provider. 

47 

48 provider_spec (Dict[str, Any]): ProviderSpec details Provider-specific configuration to use during 

49 node creation. 

50 

51 taints (List[Any]): The list of the taints to be applied to the corresponding Node in 

52 additive manner. This list will not overwrite any other taints 

53 added to the Node on an ongoing basis by other entities. These 

54 taints should be actively reconciled e.g. if you ask the machine 

55 controller to apply a taint and then manually remove the taint the 

56 machine controller will put it back) but not have the machine 

57 controller remove any taints 

58 

59 """ 

60 super().__init__(**kwargs) 

61 

62 self.lifecycle_hooks = lifecycle_hooks 

63 self.metadata = metadata 

64 self.provider_id = provider_id 

65 self.provider_spec = provider_spec 

66 self.taints = taints 

67 

68 def to_dict(self) -> None: 

69 super().to_dict() 

70 

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

72 self.res["spec"] = {} 

73 _spec = self.res["spec"] 

74 

75 if self.lifecycle_hooks: 

76 _spec["lifecycleHooks"] = self.lifecycle_hooks 

77 

78 if self.metadata: 

79 _spec["metadata"] = self.metadata 

80 

81 if self.provider_id: 

82 _spec["providerID"] = self.provider_id 

83 

84 if self.provider_spec: 

85 _spec["providerSpec"] = self.provider_spec 

86 

87 if self.taints: 

88 _spec["taints"] = self.taints 

89 

90 # End of generated code 

91 

92 @property 

93 def cluster_name(self): 

94 return self.instance.metadata.labels[f"{self.api_group}/cluster-api-cluster"] 

95 

96 @property 

97 def machine_role(self): 

98 return self.instance.metadata.labels[f"{self.api_group}/cluster-api-machine-role"] 

99 

100 @property 

101 def machine_type(self): 

102 return self.instance.metadata.labels[f"{self.api_group}/cluster-api-machine-type"] 

103 

104 @property 

105 def machineset_name(self): 

106 return self.instance.metadata.labels[f"{self.api_group}/cluster-api-machineset"]