Skip to content

Commit

Permalink
[Integration] [ArgoCD] - Blueprint Enhancement and Relation Reversal (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
PeyGis authored Apr 12, 2024
1 parent 55c6784 commit 3da83ca
Show file tree
Hide file tree
Showing 8 changed files with 207 additions and 184 deletions.
131 changes: 57 additions & 74 deletions integrations/argocd/.port/resources/blueprints.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,4 @@
[
{
"identifier": "argocdNamespace",
"description": "This blueprint represents an ArgoCD namespace",
"title": "ArgoCD Namespace",
"icon": "Argo",
"schema": {
"properties": {},
"required": []
},
"aggregationProperties": {},
"mirrorProperties": {},
"calculationProperties": {},
"relations": {}
},
{
"identifier": "argocdCluster",
"description": "This blueprint represents an ArgoCD cluster",
Expand Down Expand Up @@ -55,12 +41,26 @@
},
"mirrorProperties": {},
"calculationProperties": {},
"relations": {}
},
{
"identifier": "argocdNamespace",
"description": "This blueprint represents an ArgoCD namespace",
"title": "ArgoCD Namespace",
"icon": "Argo",
"schema": {
"properties": {},
"required": []
},
"aggregationProperties": {},
"mirrorProperties": {},
"calculationProperties": {},
"relations": {
"namespace": {
"title": "ArgoCD Namespace",
"target": "argocdNamespace",
"cluster": {
"title": "ArgoCD Cluster",
"target": "argocdCluster",
"required": false,
"many": true
"many": false
}
}
},
Expand All @@ -71,11 +71,6 @@
"icon": "Argo",
"schema": {
"properties": {
"namespace": {
"title": "Namespace",
"type": "string",
"icon": "DefaultProperty"
},
"createdAt": {
"title": "Created At",
"type": "string",
Expand All @@ -93,14 +88,7 @@
},
"mirrorProperties": {},
"calculationProperties": {},
"relations": {
"cluster": {
"title": "ArgoCD Cluster",
"target": "argocdCluster",
"required": false,
"many": true
}
}
"relations": {}
},
{
"identifier": "argocdApplication",
Expand All @@ -122,15 +110,18 @@
},
"destinationServer": {
"type": "string",
"title": "Destination Server"
"title": "Destination Server",
"description": "The URL of the target cluster's Kubernetes control plane API"
},
"revision": {
"type": "string",
"title": "Revision"
"title": "Revision",
"description": "Revision contains information about the revision the comparison has been performed to"
},
"targetRevision": {
"type": "string",
"title": "Target Revision"
"title": "Target Revision",
"description": "Target Revision defines the revision of the source to sync the application to. In case of Git, this can be commit, tag, or branch"
},
"syncStatus": {
"type": "string",
Expand All @@ -145,7 +136,7 @@
"OutOfSync": "red",
"Unknown": "lightGray"
},
"description": "The sync status of the application"
"description": "Status is the sync state of the comparison"
},
"healthStatus": {
"type": "string",
Expand All @@ -166,12 +157,23 @@
"Progressing": "blue",
"Unknown": "lightGray"
},
"description": "The health status of the application"
"description": "Status holds the status code of the application or resource"
},
"createdAt": {
"title": "Created At",
"type": "string",
"format": "date-time"
"format": "date-time",
"description": "The created timestamp of the application"
},
"labels": {
"type": "object",
"title": "Labels",
"description": "Map of string keys and values that can be used to organize and categorize object"
},
"annotations": {
"type": "object",
"title": "Annotations",
"description": "Annotations are unstructured key value map stored with a resource that may be set by external tools to store and retrieve arbitrary metadata"
}
},
"required": []
Expand Down Expand Up @@ -262,50 +264,31 @@
"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"
},
"labels": {
"type": "object",
"title": "Labels"
},
"annotations": {
"type": "object",
"title": "Annotations"
}
},
"required": []
},
"mirrorProperties": {},
"mirrorProperties": {
"healthStatus": {
"title": "Health Status",
"path": "application.healthStatus"
},
"syncStatus": {
"title": "Sync Status",
"path": "application.syncStatus"
}
},
"calculationProperties": {},
"aggregationProperties": {},
"relations": {
Expand Down
53 changes: 32 additions & 21 deletions integrations/argocd/.port/resources/port-app-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,19 @@ resources:
labels: .labels
updatedAt: .connectionState.attemptedAt
server: .server
- kind: cluster
selector:
query: "true"
port:
itemsToParse: .namespaces
entity:
mappings:
identifier: .name + "-" + .item | tostring
title: .name + "-" + .item
blueprint: '"argocdNamespace"'
properties: {}
relations:
namespace: .namespaces
cluster: .name
- kind: project
selector:
query: "true"
Expand All @@ -28,11 +39,8 @@ resources:
title: .metadata.name
blueprint: '"argocdProject"'
properties:
namespace: .metadata.namespace
createdAt: .metadata.creationTimestamp
description: .spec.description
relations:
cluster: '[.spec.destinations[].name | select(test("^[a-zA-Z0-9@_.:/=-]+$"))]'
- kind: application
selector:
query: "true"
Expand All @@ -51,42 +59,45 @@ resources:
syncStatus: .status.sync.status
healthStatus: .status.health.status
createdAt: .metadata.creationTimestamp
labels: .metadata.labels
annotations: .metadata.annotations
relations:
project: .spec.project
namespace: .metadata.namespace
cluster: .spec.destination.name
- kind: deployment-history
- kind: application
selector:
query: "true"
port:
itemsToParse: .status.history
entity:
mappings:
identifier: .__applicationId + "-" + (.id | tostring)
title: .id | tostring
identifier: .metadata.uid + "-" + (.item.id | tostring)
title: .metadata.name + "-" + (.item.id | tostring)
blueprint: '"argocdDeploymentHistory"'
properties:
deployedAt: .deployedAt
deployStartedAt: .deployStartedAt
revision: .source.repoURL + "/commit/" + .revision
initiatedBy: .initiatedBy.username
repoURL: .source.repoURL
sourcePath: .source.path
deployedAt: .item.deployedAt
deployStartedAt: .item.deployStartedAt
revision: .item.source.repoURL + "/commit/" + .item.revision
initiatedBy: .item.initiatedBy.username
repoURL: .item.source.repoURL
sourcePath: .item.source.path
relations:
application: .__applicationId
- kind: kubernetes-resource
application: .metadata.uid
- kind: managed-resource
selector:
query: "true"
port:
entity:
mappings:
identifier: .__applicationId + "-" + .name
title: .name
identifier: .__application.metadata.uid + "-" + .name
title: .__application.metadata.name + "-" + .name
blueprint: '"argocdKubernetesResource"'
properties:
kind: .kind
version: .version
namespace: .namespace
syncStatus: .status
healthStatus: .health.status
version: .resourceVersion
annotations: .liveState | fromjson | .metadata.annotations
labels: .liveState | fromjson | .metadata.labels
relations:
application: .__applicationId
application: .__application.metadata.uid
2 changes: 1 addition & 1 deletion integrations/argocd/.port/spec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
type: argocd
description: Argocd integration for Port Ocean
icon: Argo
docs: https://docs.getport.io/build-your-software-catalog/sync-data-to-catalog/kubernetes/argocd
docs: https://docs.getport.io/build-your-software-catalog/sync-data-to-catalog/argocd/
features:
- type: exporter
section: Kubernetes Stack
Expand Down
11 changes: 11 additions & 0 deletions integrations/argocd/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

<!-- towncrier release notes start -->

# Port_Ocean 0.1.37 (2024-04-11)

### Deprecations
- Added deprecation warnings to the deployment-history and kubernetes-resource kind, urging users to utilize the itemsToParse functionality instead

### Improvements

- Reveresed the relation between cluster and namespace, and other general enhancements on blueprints (PORT-7550)
- Updated the default mapping for deployment-history and kubernetes-resource kind to reuse the application kind's response and parse items using the itemsToParse functionality for improved efficiency


# Port_Ocean 0.1.36 (2024-04-11)

### Improvements
Expand Down
26 changes: 20 additions & 6 deletions integrations/argocd/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class ResourceKindsWithSpecialHandling(StrEnum):
MANAGED_RESOURCE = "managed-resource"


DEPRECATION_WARNING = "Please use the get_resources method with the application kind and map the response using the itemsToParse functionality. You can read more about parsing items here https://ocean.getport.io/framework/features/resource-mapping/#fields"


class ArgocdClient:
def __init__(self, token: str, server_url: str):
self.token = token
Expand All @@ -34,6 +37,7 @@ async def _send_api_request(
query_params: Optional[dict[str, Any]] = None,
json_data: Optional[dict[str, Any]] = None,
) -> dict[str, Any]:
logger.info(f"Sending request to ArgoCD API: {method} {url}")
try:
response = await self.http_client.request(
method=method,
Expand All @@ -46,18 +50,23 @@ async def _send_api_request(

except httpx.HTTPStatusError as e:
logger.error(
f"HTTP error with status code: {e.response.status_code} and response text: {e.response.text}"
f"Encountered an HTTP error with status code: {e.response.status_code} and response text: {e.response.text}"
)
raise
except httpx.HTTPError as e:
logger.error(f"HTTP occurred while fetching ArgoCD data {e}")
logger.error(
f"Encountered an HTTP error {e} while sending a request to {method} {url} with query_params: {query_params}"
)
raise

async def get_resources(self, resource_kind: ObjectKind) -> list[dict[str, Any]]:
logger.info(f"Fetching ArgoCD resource: {resource_kind}")
url = f"{self.api_url}/{resource_kind}s"
response_data = (await self._send_api_request(url=url))["items"]
return response_data
try:
response_data = await self._send_api_request(url=url)
return response_data["items"]
except Exception as e:
logger.error(f"Failed to fetch resources of kind {resource_kind}: {e}")
raise e

async def get_application_by_name(self, name: str) -> dict[str, Any]:
url = f"{self.api_url}/{ObjectKind.APPLICATION}s/{name}"
Expand All @@ -66,6 +75,9 @@ async def get_application_by_name(self, name: str) -> dict[str, Any]:

async def get_deployment_history(self) -> list[dict[str, Any]]:
"""The ArgoCD application route returns a history of all deployments. This function reuses the output of the application endpoint"""
logger.warning(
f"get_deployment_history is deprecated as of 0.1.34. {DEPRECATION_WARNING}"
)
applications = await self.get_resources(resource_kind=ObjectKind.APPLICATION)
all_history = [
{**history_item, "__applicationId": application["metadata"]["uid"]}
Expand All @@ -76,7 +88,9 @@ async def get_deployment_history(self) -> list[dict[str, Any]]:

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")
logger.warning(
f"get_kubernetes_resource is deprecated as of 0.1.34. {DEPRECATION_WARNING}"
)
applications = await self.get_resources(resource_kind=ObjectKind.APPLICATION)
all_k8s_resources = [
{**resource, "__applicationId": application["metadata"]["uid"]}
Expand Down
Loading

0 comments on commit 3da83ca

Please sign in to comment.