@@ -160,15 +160,23 @@ def get_taskruns(namespace, task_name):
160160 version = "v1"
161161 plural = "taskruns"
162162
163+ configuration = client .Configuration .get_default_copy ()
164+
165+ # Create ApiClient with the configuration
166+ api_client = client .ApiClient (configuration )
167+
163168 # access the custom resource from tekton
164- tektonV1 = client .CustomObjectsApi ()
165- taskruns = tektonV1 .list_namespaced_custom_object (
166- group ,
167- version ,
168- namespace ,
169- plural ,
170- label_selector = f"{ group } /task={ task_name } , triggers.tekton.dev/trigger=python-tracer-scheduled-pipeline-triggger" ,
171- )["items" ]
169+ tektonV1 = client .CustomObjectsApi (api_client )
170+ try :
171+ taskruns = tektonV1 .list_namespaced_custom_object (
172+ group ,
173+ version ,
174+ namespace ,
175+ plural ,
176+ label_selector = f"{ group } /task={ task_name } , triggers.tekton.dev/trigger=python-tracer-scheduled-pipeline-triggger" ,
177+ )["items" ]
178+ finally :
179+ api_client .close ()
172180
173181 filtered_taskruns = list (filter (taskrun_filter , taskruns ))
174182 filtered_taskruns .sort (
@@ -214,11 +222,33 @@ def process_taskrun_logs(
214222
215223def get_tekton_ci_output ():
216224 """Get the latest successful scheduled tekton pipeline output"""
225+ import os
226+
217227 try :
218- config .load_incluster_config ()
219- print ("Using in-cluster Kubernetes configuration..." )
220- except config .config_exception .ConfigException :
221- # Fall back to local config if running locally and not inside cluster
228+ token_path = "/var/run/secrets/kubernetes.io/serviceaccount/token"
229+ if os .path .exists (token_path ):
230+ print (f"ServiceAccount token found at { token_path } " )
231+ with open (token_path , 'r' ) as f :
232+ token = f .read ().strip ()
233+ print (f"Token length: { len (token )} " )
234+ print (f"Token preview: { token [:50 ]} ..." ) # İlk 50 karakter
235+
236+ # Manuel olarak configuration oluştur
237+ configuration = client .Configuration ()
238+ configuration .host = "https://kubernetes.default.svc"
239+ configuration .verify_ssl = True
240+ configuration .ssl_ca_cert = "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"
241+
242+ with open (token_path , 'r' ) as f :
243+ token = f .read ().strip ()
244+ configuration .api_key = {"authorization" : f"Bearer { token } " }
245+
246+ client .Configuration .set_default (configuration )
247+ print ("Using manually configured in-cluster Kubernetes configuration..." )
248+ print (f"API Server: { configuration .host } " )
249+
250+ except Exception as e :
251+ print (f"Error setting up configuration: { e } " )
222252 config .load_kube_config ()
223253 print ("Using local Kubernetes configuration..." )
224254
0 commit comments