diff --git a/integrations/argocd/.port/resources/blueprints.json b/integrations/argocd/.port/resources/blueprints.json index 521a0bbb27..f772f014a1 100644 --- a/integrations/argocd/.port/resources/blueprints.json +++ b/integrations/argocd/.port/resources/blueprints.json @@ -105,7 +105,7 @@ { "identifier": "argocdApplication", "description": "This blueprint represents an ArgoCD Application", - "title": "ArgoCD Application", + "title": "Running Service", "icon": "Argo", "schema": { "properties": { @@ -246,5 +246,75 @@ "many": false } } + }, + { + "identifier": "argocdKubernetesResource", + "description": "This blueprint represents an ArgoCD kubernetes resource", + "title": "Kubernetes Resource", + "icon": "Argo", + "schema": { + "properties": { + "kind": { + "title": "Kind", + "type": "string" + }, + "version": { + "title": "Version", + "type": "string" + }, + "syncStatus": { + "type": "string", + "title": "Sync Status", + "enum": [ + "Synced", + "OutOfSync", + "Unknown" + ], + "enumColors": { + "Synced": "green", + "OutOfSync": "red", + "Unknown": "lightGray" + }, + "description": "The sync status of the application" + }, + "healthStatus": { + "type": "string", + "title": "Health Status", + "enum": [ + "Healthy", + "Missing", + "Suspended", + "Degraded", + "Progressing", + "Unknown" + ], + "enumColors": { + "Healthy": "green", + "Missing": "yellow", + "Suspended": "purple", + "Degraded": "red", + "Progressing": "blue", + "Unknown": "lightGray" + }, + "description": "The health status of the application" + }, + "namespace": { + "title": "Namespace", + "type": "string" + } + }, + "required": [] + }, + "mirrorProperties": {}, + "calculationProperties": {}, + "aggregationProperties": {}, + "relations": { + "application": { + "title": "Application", + "target": "argocdApplication", + "required": false, + "many": false + } + } } ] diff --git a/integrations/argocd/.port/resources/port-app-config.yaml b/integrations/argocd/.port/resources/port-app-config.yaml index 992a353f53..9d3f440467 100644 --- a/integrations/argocd/.port/resources/port-app-config.yaml +++ b/integrations/argocd/.port/resources/port-app-config.yaml @@ -73,3 +73,20 @@ resources: sourcePath: .source.path relations: application: .__applicationId + - kind: kubernetes-resource + selector: + query: "true" + port: + entity: + mappings: + identifier: .__applicationId + "-" + .name + title: .name + blueprint: '"argocdKubernetesResource"' + properties: + kind: .kind + version: .version + namespace: .namespace + syncStatus: .status + healthStatus: .health.status + relations: + application: .__applicationId diff --git a/integrations/argocd/.port/spec.yaml b/integrations/argocd/.port/spec.yaml index 35692ad05f..2700fee8fc 100644 --- a/integrations/argocd/.port/spec.yaml +++ b/integrations/argocd/.port/spec.yaml @@ -10,6 +10,7 @@ features: - kind: project - kind: application - kind: deployment-history + - kind: kubernetes-resource - kind: managed-resource configurations: - name: token diff --git a/integrations/argocd/CHANGELOG.md b/integrations/argocd/CHANGELOG.md index 501fc7b1b2..c347f56d1e 100644 --- a/integrations/argocd/CHANGELOG.md +++ b/integrations/argocd/CHANGELOG.md @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 +# Port_Ocean 0.1.32 (2024-03-21) + +### Improvements + +- Added support for ArgoCD kubernetes resources (PORT-6911) + + # Port_Ocean 0.1.31 (2024-03-20) ### Improvements diff --git a/integrations/argocd/client.py b/integrations/argocd/client.py index 5187c555b8..50e802ab95 100644 --- a/integrations/argocd/client.py +++ b/integrations/argocd/client.py @@ -15,6 +15,7 @@ class ObjectKind(StrEnum): class ResourceKindsWithSpecialHandling(StrEnum): DEPLOYMENT_HISTORY = "deployment-history" + KUBERNETES_RESOURCE = "kubernetes-resource" MANAGED_RESOURCE = "managed-resource" @@ -73,6 +74,17 @@ async def get_deployment_history(self) -> list[dict[str, Any]]: ] return all_history + async def get_kubernetes_resource(self) -> list[dict[str, Any]]: + """The ArgoCD application returns a list of managed kubernetes resources. This function reuses the output of the application endpoint""" + logger.info("fetching Argocd k8s resources from applications endpoint") + applications = await self.get_resources(resource_kind=ObjectKind.APPLICATION) + all_k8s_resources = [ + {**resource, "__applicationId": application["metadata"]["uid"]} + for application in applications + for resource in application["status"].get("resources", []) + ] + return all_k8s_resources + async def get_managed_resources( self, application_name: str ) -> list[dict[str, Any]]: diff --git a/integrations/argocd/main.py b/integrations/argocd/main.py index 1960668eba..1b7ae8bb84 100644 --- a/integrations/argocd/main.py +++ b/integrations/argocd/main.py @@ -29,6 +29,13 @@ async def on_history_resync(kind: str) -> RAW_RESULT: return await argocd_client.get_deployment_history() +@ocean.on_resync(kind=ResourceKindsWithSpecialHandling.KUBERNETES_RESOURCE) +async def on_managed_k8s_resources_resync(kind: str) -> RAW_RESULT: + argocd_client = init_client() + + return await argocd_client.get_kubernetes_resource() + + @ocean.on_resync(kind=ResourceKindsWithSpecialHandling.MANAGED_RESOURCE) async def on_managed_resources_resync(kind: str) -> ASYNC_GENERATOR_RESYNC_TYPE: argocd_client = init_client() diff --git a/integrations/argocd/pyproject.toml b/integrations/argocd/pyproject.toml index 9818c85c66..011f5b4d52 100644 --- a/integrations/argocd/pyproject.toml +++ b/integrations/argocd/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "argocd" -version = "0.1.31" +version = "0.1.32" description = "Argo CD integration powered by Ocean" authors = ["Isaac Coffie "]