Skip to content

Commit

Permalink
[Integration][ArgoCD] Add Suppport for k8s resources (#402)
Browse files Browse the repository at this point in the history
  • Loading branch information
PeyGis authored Mar 21, 2024
1 parent f569596 commit 17a7026
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 2 deletions.
72 changes: 71 additions & 1 deletion integrations/argocd/.port/resources/blueprints.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
{
"identifier": "argocdApplication",
"description": "This blueprint represents an ArgoCD Application",
"title": "ArgoCD Application",
"title": "Running Service",
"icon": "Argo",
"schema": {
"properties": {
Expand Down Expand Up @@ -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
}
}
}
]
17 changes: 17 additions & 0 deletions integrations/argocd/.port/resources/port-app-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions integrations/argocd/.port/spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ features:
- kind: project
- kind: application
- kind: deployment-history
- kind: kubernetes-resource
- kind: managed-resource
configurations:
- name: token
Expand Down
7 changes: 7 additions & 0 deletions integrations/argocd/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

<!-- towncrier release notes start -->

# 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
Expand Down
12 changes: 12 additions & 0 deletions integrations/argocd/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class ObjectKind(StrEnum):

class ResourceKindsWithSpecialHandling(StrEnum):
DEPLOYMENT_HISTORY = "deployment-history"
KUBERNETES_RESOURCE = "kubernetes-resource"
MANAGED_RESOURCE = "managed-resource"


Expand Down Expand Up @@ -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]]:
Expand Down
7 changes: 7 additions & 0 deletions integrations/argocd/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion integrations/argocd/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]

Expand Down

0 comments on commit 17a7026

Please sign in to comment.