@@ -29,6 +29,18 @@ class KubeVersion(Base):
2929 }
3030
3131
32+ @dataclass
33+ class LKENodePoolTaint (JSONObject ):
34+ """
35+ LKENodePoolTaint represents the structure of a single taint that can be
36+ applied to a node pool.
37+ """
38+
39+ key : Optional [str ] = None
40+ value : Optional [str ] = None
41+ effect : Optional [str ] = None
42+
43+
3244@dataclass
3345class LKEClusterControlPlaneACLAddressesOptions (JSONObject ):
3446 """
@@ -139,37 +151,51 @@ class LKENodePool(DerivedBase):
139151 ), # this is formatted in _populate below
140152 "autoscaler" : Property (mutable = True ),
141153 "tags" : Property (mutable = True , unordered = True ),
154+ "labels" : Property (mutable = True ),
155+ "taints" : Property (mutable = True ),
142156 }
143157
158+ def _parse_raw_node (
159+ self , raw_node : Union [LKENodePoolNode , dict , str ]
160+ ) -> LKENodePoolNode :
161+ """
162+ Builds a list of LKENodePoolNode objects given a node pool response's JSON.
163+ """
164+ if isinstance (raw_node , LKENodePoolNode ):
165+ return raw_node
166+
167+ if isinstance (raw_node , dict ):
168+ node_id = raw_node .get ("id" )
169+ if node_id is None :
170+ raise ValueError ("Node dictionary does not contain 'id' key" )
171+
172+ return LKENodePoolNode (self ._client , raw_node )
173+
174+ if isinstance (raw_node , str ):
175+ return self ._client .load (
176+ LKENodePoolNode , target_id = raw_node , target_parent_id = self .id
177+ )
178+
179+ raise TypeError ("Unsupported node type: {}" .format (type (raw_node )))
180+
144181 def _populate (self , json ):
145182 """
146183 Parse Nodes into more useful LKENodePoolNode objects
147184 """
185+
148186 if json is not None and json != {}:
149- new_nodes = []
150- for c in json ["nodes" ]:
151- if isinstance (c , LKENodePoolNode ):
152- new_nodes .append (c )
153- elif isinstance (c , dict ):
154- node_id = c .get ("id" )
155- if node_id is not None :
156- new_nodes .append (LKENodePoolNode (self ._client , c ))
157- else :
158- raise ValueError (
159- "Node dictionary does not contain 'id' key"
160- )
161- elif isinstance (c , str ):
162- node_details = self ._client .get (
163- LKENodePool .api_endpoint .format (
164- cluster_id = self .id , id = c
165- )
166- )
167- new_nodes .append (
168- LKENodePoolNode (self ._client , node_details )
169- )
170- else :
171- raise TypeError ("Unsupported node type: {}" .format (type (c )))
172- json ["nodes" ] = new_nodes
187+ json ["nodes" ] = [
188+ self ._parse_raw_node (node ) for node in json .get ("nodes" , [])
189+ ]
190+
191+ json ["taints" ] = [
192+ (
193+ LKENodePoolTaint .from_json (taint )
194+ if not isinstance (taint , LKENodePoolTaint )
195+ else taint
196+ )
197+ for taint in json .get ("taints" , [])
198+ ]
173199
174200 super ()._populate (json )
175201
@@ -302,7 +328,14 @@ def control_plane_acl(self) -> LKEClusterControlPlaneACL:
302328
303329 return LKEClusterControlPlaneACL .from_json (self ._control_plane_acl )
304330
305- def node_pool_create (self , node_type , node_count , ** kwargs ):
331+ def node_pool_create (
332+ self ,
333+ node_type : Union [Type , str ],
334+ node_count : int ,
335+ labels : Dict [str , str ] = None ,
336+ taints : List [Union [LKENodePoolTaint , Dict [str , Any ]]] = None ,
337+ ** kwargs ,
338+ ):
306339 """
307340 Creates a new :any:`LKENodePool` for this cluster.
308341
@@ -312,6 +345,10 @@ def node_pool_create(self, node_type, node_count, **kwargs):
312345 :type node_type: :any:`Type` or str
313346 :param node_count: The number of nodes to create in this pool.
314347 :type node_count: int
348+ :param labels: A dict mapping labels to their values to apply to this pool.
349+ :type labels: Dict[str, str]
350+ :param taints: A list of taints to apply to this pool.
351+ :type taints: List of :any:`LKENodePoolTaint` or dict
315352 :param kwargs: Any other arguments to pass to the API. See the API docs
316353 for possible values.
317354
@@ -322,6 +359,13 @@ def node_pool_create(self, node_type, node_count, **kwargs):
322359 "type" : node_type ,
323360 "count" : node_count ,
324361 }
362+
363+ if labels is not None :
364+ params ["labels" ] = labels
365+
366+ if taints is not None :
367+ params ["taints" ] = taints
368+
325369 params .update (kwargs )
326370
327371 result = self ._client .post (
0 commit comments