Skip to content

Comments

[patch] create functions to fetch cluster issuer#161

Open
terc1997 wants to merge 7 commits intostablefrom
issue-1812
Open

[patch] create functions to fetch cluster issuer#161
terc1997 wants to merge 7 commits intostablefrom
issue-1812

Conversation

@terc1997
Copy link
Contributor

Description

@terc1997 terc1997 requested a review from a team as a code owner December 30, 2025 18:22
Copy link
Contributor

@durera durera left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also add unittests for the new function to the tests. Don't need you to fill existing test gaps, but we don't want to create more gaps going forward. Use mock framework, and include good/bad path test scenarios.

Also note that delivery is tied to ibm-mas/cli#1983 (review)

We need to update the CLI PR to include the RBAC additions for the new capability that will be used by the CLI user:

https://github.com/ibm-mas/cli/tree/master/rbac/install/user .. the clusterrole will need to be updated to provide the necessary access for the ClusterIssuer resource before this pair of PRs can be merged

return clusterIssuers


def getClusterIssuer(dynClient: DynamicClient, name: str) -> str:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The typehint is incorrect, this is not returning a string clusterIssuer is the object returned by the clusterIssuerAPI, rather than the name of the issuer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In other functions, it's returning a dict. Should we use dict as convention to all or the actual ResourceInstance ?
image

def getStorageClass(dynClient: DynamicClient, name: str) -> dict | None:
"""
Get a specific StorageClass by name.
Parameters:
dynClient (DynamicClient): OpenShift Dynamic Client
name (str): The name of the StorageClass to retrieve
Returns:
StorageClass: The StorageClass resource, or None if not found
Raises:
NotFoundError: If the StorageClass does not exist (caught and returns None)
"""
try:
storageClassAPI = dynClient.resources.get(api_version="storage.k8s.io/v1", kind="StorageClass")
storageclass = storageClassAPI.get(name=name)
return storageclass
except NotFoundError:
return None

ClusterIssuer: The ClusterIssuer resource, or None if not found

Raises:
NotFoundError: If the ClusterIssuer does not exist (caught and returns None)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are catching a NotFoundError and returning None, so we shouldn't document that this raises NotFoundError ... the documentation should only list exceptions that can be raised by calling the function, not exceptions handling internally within the function.

Copy link
Contributor Author

@terc1997 terc1997 Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I agree with that. But there are several example in the code that handle the exceptions like this. Fya:

def crdExists(dynClient: DynamicClient, crdName: str) -> bool:
"""
Check if a Custom Resource Definition (CRD) exists in the cluster.
Parameters:
dynClient (DynamicClient): OpenShift Dynamic Client
crdName (str): The name of the CRD to check (e.g., "suites.core.mas.ibm.com")
Returns:
bool: True if the CRD exists, False otherwise
Raises:
NotFoundError: If the CRD does not exist (caught and returns False)
"""
crdAPI = dynClient.resources.get(api_version="apiextensions.k8s.io/v1", kind="CustomResourceDefinition")
try:
crdAPI.get(name=crdName)
logger.debug(f"CRD does exist: {crdName}")
return True
except NotFoundError:
logger.debug(f"CRD does not exist: {crdName}")
return False

def getStorageClass(dynClient: DynamicClient, name: str) -> dict | None:
"""
Get a specific StorageClass by name.
Parameters:
dynClient (DynamicClient): OpenShift Dynamic Client
name (str): The name of the StorageClass to retrieve
Returns:
StorageClass: The StorageClass resource, or None if not found
Raises:
NotFoundError: If the StorageClass does not exist (caught and returns None)
"""
try:
storageClassAPI = dynClient.resources.get(api_version="storage.k8s.io/v1", kind="StorageClass")
storageclass = storageClassAPI.get(name=name)
return storageclass
except NotFoundError:
return None

I just followed the standard of the code. So, should we change all or keep as is ?

@terc1997 terc1997 requested a review from durera February 19, 2026 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants