Coverage for ocp_resources/node.py: 31%
48 statements
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-30 10:51 +0200
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-30 10:51 +0200
1# Generated using https://github.com/RedHatQE/openshift-python-wrapper/blob/main/scripts/resource/README.md
3from typing import Any, Dict, List, Optional
4from ocp_resources.resource import Resource
7class Node(Resource):
8 """
9 Node is a worker node in Kubernetes. Each node will have a unique identifier in the cache (i.e. in etcd).
10 """
12 api_version: str = Resource.ApiVersion.V1
14 def __init__(
15 self,
16 config_source: Optional[Dict[str, Any]] = None,
17 external_id: Optional[str] = "",
18 pod_cidr: Optional[str] = "",
19 pod_cidrs: Optional[List[Any]] = None,
20 provider_id: Optional[str] = "",
21 taints: Optional[List[Any]] = None,
22 unschedulable: Optional[bool] = None,
23 **kwargs: Any,
24 ) -> None:
25 """
26 Args:
27 config_source (Dict[str, Any]): NodeConfigSource specifies a source of node configuration. Exactly one
28 subfield (excluding metadata) must be non-nil. This API is
29 deprecated since 1.22
31 external_id (str): Deprecated. Not all kubelets will set this field. Remove field after
32 1.13. see: https://issues.k8s.io/61966
34 pod_cidr (str): PodCIDR represents the pod IP range assigned to the node.
36 pod_cidrs (List[Any]): podCIDRs represents the IP ranges assigned to the node for usage by
37 Pods on that node. If this field is specified, the 0th entry must
38 match the podCIDR field. It may contain at most 1 value for each
39 of IPv4 and IPv6.
41 provider_id (str): ID of the node assigned by the cloud provider in the format:
42 <ProviderName>://<ProviderSpecificNodeID>
44 taints (List[Any]): If specified, the node's taints.
46 unschedulable (bool): Unschedulable controls node schedulability of new pods. By default,
47 node is schedulable. More info:
48 https://kubernetes.io/docs/concepts/nodes/node/#manual-node-
49 administration
51 """
52 super().__init__(**kwargs)
54 self.config_source = config_source
55 self.external_id = external_id
56 self.pod_cidr = pod_cidr
57 self.pod_cidrs = pod_cidrs
58 self.provider_id = provider_id
59 self.taints = taints
60 self.unschedulable = unschedulable
62 def to_dict(self) -> None:
63 super().to_dict()
65 if not self.kind_dict and not self.yaml_file:
66 self.res["spec"] = {}
67 _spec = self.res["spec"]
69 if self.config_source:
70 _spec["configSource"] = self.config_source
72 if self.external_id:
73 _spec["externalID"] = self.external_id
75 if self.pod_cidr:
76 _spec["podCIDR"] = self.pod_cidr
78 if self.pod_cidrs:
79 _spec["podCIDRs"] = self.pod_cidrs
81 if self.provider_id:
82 _spec["providerID"] = self.provider_id
84 if self.taints:
85 _spec["taints"] = self.taints
87 if self.unschedulable is not None:
88 _spec["unschedulable"] = self.unschedulable
90 # End of generated code
92 @property
93 def kubelet_ready(self):
94 return any(
95 stat["reason"] == "KubeletReady" and stat["status"] == self.Condition.Status.TRUE
96 for stat in self.instance.status.conditions
97 )
99 @property
100 def machine_name(self):
101 return self.instance.metadata.annotations[f"{self.ApiGroup.MACHINE_OPENSHIFT_IO}/machine"].split("/")[-1]
103 @property
104 def internal_ip(self):
105 for addr in self.instance.status.addresses:
106 if addr.type == "InternalIP":
107 return addr.address
109 @property
110 def hostname(self):
111 return self.labels["kubernetes.io/hostname"]
113 def get_taints(self):
114 return self.instance.get("spec", {}).get("taints")