1919from kubernetes import client
2020from kubernetes .stream import stream
2121from kubernetes .stream .ws_client import ERROR_CHANNEL
22+ from kubernetes .dynamic .resource import ResourceInstance
2223
2324import yaml
2425
@@ -85,9 +86,6 @@ def getClusterVersion(dynClient: DynamicClient) -> str:
8586
8687 Returns:
8788 str: The cluster version string (e.g., "4.12.0"), or None if not found
88-
89- Raises:
90- NotFoundError: If the ClusterVersion resource cannot be retrieved
9189 """
9290 clusterVersionAPI = dynClient .resources .get (api_version = "config.openshift.io/v1" , kind = "ClusterVersion" )
9391
@@ -131,8 +129,6 @@ def getNamespace(dynClient: DynamicClient, namespace: str) -> dict:
131129 Returns:
132130 dict: The namespace resource as a dictionary, or an empty dict if not found
133131
134- Raises:
135- NotFoundError: If the namespace does not exist
136132 """
137133 namespaceAPI = dynClient .resources .get (api_version = "v1" , kind = "Namespace" )
138134
@@ -142,7 +138,6 @@ def getNamespace(dynClient: DynamicClient, namespace: str) -> dict:
142138 return ns
143139 except NotFoundError :
144140 logger .debug (f"Namespace { namespace } does not exist" )
145-
146141 return {}
147142
148143
@@ -160,9 +155,6 @@ def createNamespace(dynClient: DynamicClient, namespace: str, kyvernoLabel: str
160155
161156 Returns:
162157 bool: Always returns True
163-
164- Raises:
165- NotFoundError: If the namespace resource cannot be accessed
166158 """
167159 namespaceAPI = dynClient .resources .get (api_version = "v1" , kind = "Namespace" )
168160 try :
@@ -204,9 +196,6 @@ def deleteNamespace(dynClient: DynamicClient, namespace: str) -> bool:
204196
205197 Returns:
206198 bool: Always returns True
207-
208- Raises:
209- NotFoundError: If the namespace does not exist (caught and logged)
210199 """
211200 namespaceAPI = dynClient .resources .get (api_version = "v1" , kind = "Namespace" )
212201 try :
@@ -229,9 +218,6 @@ def waitForCRD(dynClient: DynamicClient, crdName: str) -> bool:
229218
230219 Returns:
231220 bool: True if the CRD becomes established, False if timeout is reached
232-
233- Raises:
234- NotFoundError: If the CRD is not found (caught and retried)
235221 """
236222 crdAPI = dynClient .resources .get (api_version = "apiextensions.k8s.io/v1" , kind = "CustomResourceDefinition" )
237223 maxRetries = 100
@@ -274,9 +260,6 @@ def waitForDeployment(dynClient: DynamicClient, namespace: str, deploymentName:
274260
275261 Returns:
276262 bool: True if the deployment becomes ready, False if timeout is reached
277-
278- Raises:
279- NotFoundError: If the deployment is not found (caught and retried)
280263 """
281264 deploymentAPI = dynClient .resources .get (api_version = "apps/v1" , kind = "Deployment" )
282265 maxRetries = 100
@@ -309,9 +292,6 @@ def getConsoleURL(dynClient: DynamicClient) -> str:
309292
310293 Returns:
311294 str: The HTTPS URL of the OpenShift console (e.g., "https://console-openshift-console.apps.cluster.example.com")
312-
313- Raises:
314- NotFoundError: If the console route is not found
315295 """
316296 routesAPI = dynClient .resources .get (api_version = "route.openshift.io/v1" , kind = "Route" )
317297 consoleRoute = routesAPI .get (name = "console" , namespace = "openshift-console" )
@@ -327,9 +307,6 @@ def getNodes(dynClient: DynamicClient) -> dict:
327307
328308 Returns:
329309 list: List of node resources as dictionaries
330-
331- Raises:
332- NotFoundError: If nodes cannot be retrieved
333310 """
334311 nodesAPI = dynClient .resources .get (api_version = "v1" , kind = "Node" )
335312 nodes = nodesAPI .get ().to_dict ()['items' ]
@@ -346,9 +323,6 @@ def getStorageClass(dynClient: DynamicClient, name: str) -> dict | None:
346323
347324 Returns:
348325 StorageClass: The StorageClass resource, or None if not found
349-
350- Raises:
351- NotFoundError: If the StorageClass does not exist (caught and returns None)
352326 """
353327 try :
354328 storageClassAPI = dynClient .resources .get (api_version = "storage.k8s.io/v1" , kind = "StorageClass" )
@@ -367,15 +341,46 @@ def getStorageClasses(dynClient: DynamicClient) -> list:
367341
368342 Returns:
369343 list: List of StorageClass resources
370-
371- Raises:
372- NotFoundError: If StorageClasses cannot be retrieved
373344 """
374345 storageClassAPI = dynClient .resources .get (api_version = "storage.k8s.io/v1" , kind = "StorageClass" )
375346 storageClasses = storageClassAPI .get ().items
376347 return storageClasses
377348
378349
350+ def getClusterIssuers (dynClient : DynamicClient ) -> list :
351+ """
352+ Get all ClusterIssuers in the cluster.
353+
354+ Parameters:
355+ dynClient (DynamicClient): OpenShift Dynamic Client
356+
357+ Returns:
358+ list: List of ClusterIssuers resources or an empty list if no cluster issuers
359+ """
360+ clusterIssuerAPI = dynClient .resources .get (api_version = "cert-manager.io/v1" , kind = "ClusterIssuer" )
361+ clusterIssuers = clusterIssuerAPI .get ().items
362+ return clusterIssuers
363+
364+
365+ def getClusterIssuer (dynClient : DynamicClient , name : str ) -> ResourceInstance | None :
366+ """
367+ Get a specific ClusterIssuer by name.
368+
369+ Parameters:
370+ dynClient (DynamicClient): OpenShift Dynamic Client
371+ name (str): The name of the ClusterIssuer to retrieve
372+
373+ Returns:
374+ ClusterIssuer: The ClusterIssuer resource, or None if not found
375+ """
376+ try :
377+ clusterIssuerAPI = dynClient .resources .get (api_version = "cert-manager.io/v1" , kind = "ClusterIssuer" )
378+ clusterIssuer = clusterIssuerAPI .get (name = name )
379+ return clusterIssuer
380+ except NotFoundError :
381+ return None
382+
383+
379384def getStorageClassVolumeBindingMode (dynClient : DynamicClient , storageClassName : str ) -> str :
380385 """
381386 Get the volumeBindingMode for a storage class.
0 commit comments