@@ -41,6 +41,11 @@ def __init__(self, knative_config):
4141 config .load_kube_config ()
4242 self .api = client .CustomObjectsApi ()
4343 self .v1 = client .CoreV1Api ()
44+ # get current context
45+ current_context = config .list_kube_config_contexts ()[1 ]
46+ current_context_details = current_context .get ('context' )
47+ # get namespace of current context
48+ self .namespace = current_context_details .get ('namespace' )
4449
4550 self .headers = {'content-type' : 'application/json' }
4651
@@ -103,7 +108,7 @@ def _get_service_host(self, service_name):
103108 group = "serving.knative.dev" ,
104109 version = "v1alpha1" ,
105110 name = service_name ,
106- namespace = "default" ,
111+ namespace = self . namespace ,
107112 plural = "services"
108113 )
109114 if svc is not None :
@@ -139,14 +144,14 @@ def _create_account_resources(self):
139144 account_res_name = account_res ['metadata' ]['name' ]
140145
141146 try :
142- self .v1 .delete_namespaced_secret (secret_res_name , 'default' )
143- self .v1 .delete_namespaced_service_account (account_res_name , 'default' )
147+ self .v1 .delete_namespaced_secret (secret_res_name , self . namespace )
148+ self .v1 .delete_namespaced_service_account (account_res_name , self . namespace )
144149 except Exception :
145150 # account resource Not Found - Not deleted
146151 pass
147152
148- self .v1 .create_namespaced_secret ('default' , secret_res )
149- self .v1 .create_namespaced_service_account ('default' , account_res )
153+ self .v1 .create_namespaced_secret (self . namespace , secret_res )
154+ self .v1 .create_namespaced_service_account (self . namespace , account_res )
150155
151156 def _create_build_resources (self ):
152157 logger .debug ("Creating Build resources: PipelineResource and Task" )
@@ -167,7 +172,7 @@ def _create_build_resources(self):
167172 group = "tekton.dev" ,
168173 version = "v1alpha1" ,
169174 name = task_name ,
170- namespace = "default" ,
175+ namespace = self . namespace ,
171176 plural = "tasks" ,
172177 body = client .V1DeleteOptions ()
173178 )
@@ -180,7 +185,7 @@ def _create_build_resources(self):
180185 group = "tekton.dev" ,
181186 version = "v1alpha1" ,
182187 name = git_res_name ,
183- namespace = "default" ,
188+ namespace = self . namespace ,
184189 plural = "pipelineresources" ,
185190 body = client .V1DeleteOptions ()
186191 )
@@ -191,15 +196,15 @@ def _create_build_resources(self):
191196 self .api .create_namespaced_custom_object (
192197 group = "tekton.dev" ,
193198 version = "v1alpha1" ,
194- namespace = "default" ,
199+ namespace = self . namespace ,
195200 plural = "pipelineresources" ,
196201 body = git_res
197202 )
198203
199204 self .api .create_namespaced_custom_object (
200205 group = "tekton.dev" ,
201206 version = "v1alpha1" ,
202- namespace = "default" ,
207+ namespace = self . namespace ,
203208 plural = "tasks" ,
204209 body = task_def
205210 )
@@ -225,7 +230,7 @@ def _build_docker_image_from_git(self, docker_image_name):
225230 group = "tekton.dev" ,
226231 version = "v1alpha1" ,
227232 name = task_run_name ,
228- namespace = "default" ,
233+ namespace = self . namespace ,
229234 plural = "taskruns" ,
230235 body = client .V1DeleteOptions ()
231236 )
@@ -235,14 +240,14 @@ def _build_docker_image_from_git(self, docker_image_name):
235240 self .api .create_namespaced_custom_object (
236241 group = "tekton.dev" ,
237242 version = "v1alpha1" ,
238- namespace = "default" ,
243+ namespace = self . namespace ,
239244 plural = "taskruns" ,
240245 body = task_run
241246 )
242247
243248 pod_name = None
244249 w = watch .Watch ()
245- for event in w .stream (self .api .list_namespaced_custom_object , namespace = 'default' ,
250+ for event in w .stream (self .api .list_namespaced_custom_object , namespace = self . namespace ,
246251 group = "tekton.dev" , version = "v1alpha1" , plural = "taskruns" ,
247252 field_selector = "metadata.name={0}" .format (task_run_name )):
248253 if event ['object' ].get ('status' ) is not None :
@@ -253,7 +258,7 @@ def _build_docker_image_from_git(self, docker_image_name):
253258 raise Exception ('Unable to get the pod name from the task that is building the runtime' )
254259
255260 w = watch .Watch ()
256- for event in w .stream (self .v1 .list_namespaced_pod , namespace = 'default' ,
261+ for event in w .stream (self .v1 .list_namespaced_pod , namespace = self . namespace ,
257262 field_selector = "metadata.name={0}" .format (pod_name )):
258263 if event ['object' ].status .phase == "Succeeded" :
259264 w .stop ()
@@ -265,7 +270,7 @@ def _build_docker_image_from_git(self, docker_image_name):
265270 group = "tekton.dev" ,
266271 version = "v1alpha1" ,
267272 name = task_run_name ,
268- namespace = "default" ,
273+ namespace = self . namespace ,
269274 plural = "taskruns" ,
270275 body = client .V1DeleteOptions ()
271276 )
@@ -281,6 +286,7 @@ def _create_service(self, docker_image_name, runtime_memory, timeout):
281286
282287 service_name = self ._format_service_name (docker_image_name , runtime_memory )
283288 svc_res ['metadata' ]['name' ] = service_name
289+ svc_res ['metadata' ]['namespace' ] = self .namespace
284290
285291 svc_res ['spec' ]['template' ]['spec' ]['timeoutSeconds' ] = timeout
286292
@@ -295,7 +301,7 @@ def _create_service(self, docker_image_name, runtime_memory, timeout):
295301 group = "serving.knative.dev" ,
296302 version = "v1alpha1" ,
297303 name = service_name ,
298- namespace = "default" ,
304+ namespace = self . namespace ,
299305 plural = "services" ,
300306 body = client .V1DeleteOptions ()
301307 )
@@ -306,14 +312,14 @@ def _create_service(self, docker_image_name, runtime_memory, timeout):
306312 self .api .create_namespaced_custom_object (
307313 group = "serving.knative.dev" ,
308314 version = "v1alpha1" ,
309- namespace = "default" ,
315+ namespace = self . namespace ,
310316 plural = "services" ,
311317 body = svc_res
312318 )
313319
314320 w = watch .Watch ()
315321 for event in w .stream (self .api .list_namespaced_custom_object ,
316- namespace = 'default' , group = "serving.knative.dev" ,
322+ namespace = self . namespace , group = "serving.knative.dev" ,
317323 version = "v1alpha1" , plural = "services" ,
318324 field_selector = "metadata.name={0}" .format (service_name )):
319325 conditions = None
@@ -383,7 +389,7 @@ def delete_runtime(self, docker_image_name, memory):
383389 group = "serving.knative.dev" ,
384390 version = "v1alpha1" ,
385391 name = service_name ,
386- namespace = "default" ,
392+ namespace = self . namespace ,
387393 plural = "services" ,
388394 body = client .V1DeleteOptions ()
389395 )
@@ -402,7 +408,7 @@ def list_runtimes(self, docker_image_name='all'):
402408 return: list of tuples [docker_image_name, memory]
403409 """
404410 #TODO
405- runtimes = [[docker_image_name , 0 ]]
411+ runtimes = [[docker_image_name , 256 ]]
406412 return runtimes
407413
408414 def invoke (self , docker_image_name , memory , payload ):
0 commit comments