Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add functions to support list resource names #1352

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/robusta/core/discovery/resource_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from kubernetes import client
from pydantic import BaseModel

from robusta.integrations.kubernetes.custom_models import DeploymentConfig
from robusta.utils.error_codes import ActionException, ErrorCodes


Expand Down Expand Up @@ -54,6 +55,10 @@ class ResourceLister(BaseModel):
list_all=client.NetworkingV1Api().list_ingress_for_all_namespaces,
list_namespaced=client.NetworkingV1Api().list_namespaced_ingress,
),
"deploymentconfig": ResourceLister(
list_all=DeploymentConfig.list_for_all_namespaces,
list_namespaced=DeploymentConfig.list_namespaced,
),
}


Expand Down
31 changes: 31 additions & 0 deletions src/robusta/integrations/kubernetes/custom_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,37 @@ class DeploymentConfig(HikaruDocumentBase, HikaruCRDDocumentMixin):
def readNamespaced(self, name: str, namespace: str):
obj = DeploymentConfig(metadata=ObjectMeta(name=name, namespace=namespace)).read()
return type("", (object,), {"obj": obj})()

@classmethod
def list_namespaced(self, namespace: str):
deployconfigs_res = client.CustomObjectsApi().list_namespaced_custom_object(
group=DeploymentConfig.group,
version=DeploymentConfig.version,
namespace=namespace,
plural=DeploymentConfig.plural,
)
dc_list = type("", (object,), {"items": [
DeploymentConfig(metadata=ObjectMeta(**dc.get("metadata", {})), spec=DeploymentConfigSpec(**dc.get("spec", {})))
for dc in
deployconfigs_res.get("items", [])
]})()

return dc_list

@classmethod
def list_for_all_namespaces(self):
deployconfigs_res = client.CustomObjectsApi().list_cluster_custom_object(
group=DeploymentConfig.group,
version=DeploymentConfig.version,
plural=DeploymentConfig.plural,
)
dc_list = type("", (object,), {"items": [
DeploymentConfig(metadata=ObjectMeta(**dc.get("metadata", {})), spec=DeploymentConfigSpec(**dc.get("spec", {})))
for dc in
deployconfigs_res.get("items", [])
]})()

return dc_list


def DictToK8sObj(obj: Dict, class_name):
Expand Down
Loading