@@ -40,6 +40,7 @@ def __init__(
4040 client = None ,
4141 capture = None ,
4242 node_selector = None ,
43+ node_selector_labels = None ,
4344 teardown = True ,
4445 mtu = None ,
4546 ports = None ,
@@ -76,6 +77,8 @@ def __init__(
7677 teardown = teardown ,
7778 yaml_file = yaml_file ,
7879 delete_timeout = delete_timeout ,
80+ node_selector = node_selector ,
81+ node_selector_labels = node_selector_labels ,
7982 ** kwargs ,
8083 )
8184 self .desired_state = {"interfaces" : []}
@@ -94,7 +97,6 @@ def __init__(
9497 self .ipv6_autoconf = self .ipv6_dhcp
9598 self .ipv6_auto_dns = ipv6_auto_dns
9699 self .ipv6_addresses = ipv6_addresses
97- self .node_selector = node_selector
98100 self .dns_resolver = dns_resolver
99101 self .routes = routes
100102 self .state = state or self .Interface .State .UP
@@ -104,16 +106,20 @@ def __init__(
104106 self .res = None
105107 self .ipv4_ports_backup_dict = {}
106108 self .ipv6_ports_backup_dict = {}
109+ self .nodes = self ._nodes ()
110+
111+ def _nodes (self ):
107112 if self .node_selector :
108- self ._node_selector = {
109- f"{ self .ApiGroup .KUBERNETES_IO } /hostname" : self .node_selector
110- }
111- self .nodes = list (Node .get (dyn_client = self .client , name = self .node_selector ))
112- else :
113- self ._node_selector = {
114- f"node-role.{ self .ApiGroup .KUBERNETES_IO } /worker" : ""
115- }
116- self .nodes = list (Node .get (dyn_client = self .client ))
113+ return list (Node .get (dyn_client = self .client , name = self .node_selector ))
114+ if self .node_selector_labels :
115+ label_key , label_value = list (self .node_selector_labels .items ())[0 ]
116+ nodes = list (
117+ Node .get (
118+ dyn_client = self .client , label_selector = f"{ label_key } ={ label_value } "
119+ )
120+ )
121+ return nodes
122+ return None
117123
118124 def set_interface (self , interface ):
119125 if not self .res :
@@ -382,7 +388,7 @@ def _process_failed_status():
382388
383389 except (TimeoutExpiredError , NNCPConfigurationFailed ):
384390 LOGGER .error (
385- f"Unable to configure NNCP { self .name } for node { self .node_selector } "
391+ f"Unable to configure NNCP { self .name } for nodes { [ node . name for node in self .nodes ] } "
386392 )
387393 raise
388394
0 commit comments