8080 }
8181 ]
8282 }
83- ]
83+ ],
84+ "nodeSelector": {}
8485 }
8586 }
8687 }
156157 ]
157158 }
158159 ],
160+ "nodeSelector": {},
159161 "volumes":[
160162 {
161163 "name":"minio-user",
@@ -480,8 +482,8 @@ def _create_namespace(self, app_name):
480482 "apiVersion" : self .apiversion ,
481483 "metadata" : {
482484 "name" : app_name
483- }
484485 }
486+ }
485487 resp = self .session .post (url , json = data )
486488 if not resp .status_code == 201 :
487489 error (resp , "create Namespace {}" .format (app_name ))
@@ -622,16 +624,24 @@ def _create_rc(self, name, image, command, **kwargs): # noqa
622624 }
623625 template = string .Template (TEMPLATE ).substitute (l )
624626 js_template = json .loads (template )
627+
628+ # apply tags as needed
629+ tags = kwargs .get ('tags' , {})
630+ js_template ["spec" ]["template" ]["spec" ]["nodeSelector" ] = tags
631+
632+ # Deal with container information
625633 containers = js_template ["spec" ]["template" ]["spec" ]["containers" ]
626634 containers [0 ]['args' ] = args
627635 loc = locals ().copy ()
628636 loc .update (re .match (MATCH , container_fullname ).groupdict ())
629637 mem = kwargs .get ('memory' , {}).get (app_type )
630638 cpu = kwargs .get ('cpu' , {}).get (app_type )
631639 env = kwargs .get ('envs' , {})
640+
632641 if env :
633642 for k , v in env .items ():
634643 containers [0 ]["env" ].append ({"name" : k , "value" : v })
644+
635645 if mem or cpu :
636646 containers [0 ]["resources" ] = {"limits" : {}}
637647
@@ -653,11 +663,13 @@ def _create_rc(self, name, image, command, **kwargs): # noqa
653663 if unhealthy (resp .status_code ):
654664 error (resp , 'create ReplicationController "{}" in Namespace "{}"' ,
655665 name , app_name )
666+
656667 create = False
657668 for _ in range (30 ):
658669 if not create and self ._get_rc_status (name , app_name ) == 404 :
659670 time .sleep (1 )
660671 continue
672+
661673 create = True
662674 rc = self ._get_rc (name , app_name )
663675 if (
@@ -835,4 +847,30 @@ def _pod_log(self, name, namespace):
835847
836848 return resp .status_code , resp .text , resp .reason
837849
850+ # NODES #
851+
852+ def _get_nodes (self , ** kwargs ):
853+ path = '/nodes'
854+ query = {}
855+
856+ # labels and fields are encoded slightly differently than python-requests can do
857+ labels = kwargs .get ('labels' , {})
858+ if labels :
859+ # http://kubernetes.io/v1.1/docs/user-guide/labels.html#list-and-watch-filtering
860+ labels = ['{}={}' .format (key , value ) for key , value in labels .items ()]
861+ query ['labelSelector' ] = ',' .join (labels )
862+
863+ fields = kwargs .get ('fields' , {})
864+ if fields :
865+ fields = ['{}={}' .format (key , value ) for key , value in fields .items ()]
866+ query ['fieldSelector' ] = ',' .join (fields )
867+
868+ url = self ._api (path )
869+ response = self .session .get (url , params = query )
870+ if unhealthy (response .status_code ):
871+ error (response , 'get Nodes' )
872+
873+ return response
874+
875+
838876SchedulerClient = KubeHTTPClient
0 commit comments