Skip to content

Commit

Permalink
Merge branch 'main' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
talboren authored Dec 30, 2024
2 parents 299434e + 75d7b91 commit 63fae16
Show file tree
Hide file tree
Showing 16 changed files with 516 additions and 12 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,12 @@
Azure AKS
</a>
</td>
<td align="center" width="150">
<a href="https://docs.keephq.dev/providers/documentation/argocd-provider" target="_blank">
<img width="40" src="keep-ui/public/icons/argocd-icon.png" alt="ArgoCD"/><br/>
ArgoCD
</a>
</td>
<td align="center" width="150">
<a href="https://docs.keephq.dev/providers/documentation/gke-provider" target="_blank">
<img width="40" src="keep-ui/public/icons/gke-icon.png" alt="GKE"/><br/>
Expand Down
1 change: 1 addition & 0 deletions docs/mint.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
"pages": [
"providers/documentation/aks-provider",
"providers/documentation/appdynamics-provider",
"providers/documentation/argocd-provider",
"providers/documentation/auth0-provider",
"providers/documentation/axiom-provider",
"providers/documentation/azuremonitoring-provider",
Expand Down
38 changes: 38 additions & 0 deletions docs/providers/documentation/argocd-provider.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
title: "ArgoCD Provider"
sidebarTitle: "ArgoCD Provider"
description: "The ArgoCD provider enables you to pull topology and Application data."
---

## Overview

The **ArgoCD Provider** facilitates pulling Topology and Application data from ArgoCD.
ArgoCD Applications are mapped to Keep Services
ArgoCD ApplicationSets are mapped to Keep Applcations

## Authentication Parameters

- **ArgoCD Access Token** (required): Access token for authenticating with ArgoCD's API.
- **Deployment Url** (required): Deployment URL for connecting to the ArgoCD instance (e.g., `https://localhost:8080`).

## Scopes

- **authenticated**: Mandatory for all operations, ensures the user is authenticated.

## Connecting with the Provider

1. Obtain the **access token** from your ArgoCD instance by following `Generate auth token` from [ArgoCD's User management docs](https://argo-cd.readthedocs.io/en/latest/operator-manual/user-management/#manage-users).
2. Set the **deployment URL** to your ArgoCD instance's base URL (e.g., `https://localhost:8080`).

## Features

The **ArgoCD Provider** supports the following key features:

- **Topology**: Configures the Topology usin the applications from ArgoCD.
- **Applications**: Creates Applications using the ApplicationSets from ArgoCD.


## Useful Links

- [ArgoCD API Documentation](https://argo-cd.readthedocs.io/en/latest/developer-guide/api-docs)
- [ArgoCD User Management](https://argo-cd.readthedocs.io/en/latest/operator-manual/user-management/#local-usersaccounts)
8 changes: 8 additions & 0 deletions docs/providers/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ By leveraging Keep Providers, users are able to deeply integrate Keep with the t
}
></Card>

<Card
title="ArgoCD"
href="/providers/documentation/argocd-provider"
icon={
<img src="https://github.com/keephq/keep/blob/main/keep-ui/public/icons/argocd-icon.png?raw=true" />
}
></Card>

<Card
title="Axiom"
href="/providers/documentation/axiom-provider"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export function ApplicationsList({
variant="primary"
color="orange"
onClick={() => {
setModalState(initialModalState);
setModalState({ ...initialModalState, isOpen: true });
}}
>
Add Application
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ export function getNodesAndEdgesFromTopologyData(
const allServices = topologyData.map((data) => data.display_name);
// Create nodes from service definitions
for (const service of topologyData) {
const numIncidentsToService = allIncidents.filter((incident) =>
incident.services.includes(service.display_name)
const numIncidentsToService = allIncidents.filter(
(incident) =>
incident.services.includes(service.display_name) ||
incident.services.includes(service.service)
);
const node: ServiceNodeType = {
id: service.service.toString(),
Expand Down
2 changes: 1 addition & 1 deletion keep-ui/app/(keep)/topology/ui/map/service-node.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export function ServiceNode({ data, selected }: NodeProps<ServiceNodeType>) {

const handleClick = () => {
router.push(
`/incidents?services={encodeURIComponent("${data.display_name}")}`
`/incidents?services=${encodeURIComponent(data.display_name)}`
);
};

Expand Down
Binary file added keep-ui/public/icons/argocd-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion keep/api/models/db/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class TopologyService(SQLModel, table=True):
back_populates="service",
sa_relationship_kwargs={
"foreign_keys": "[TopologyServiceDependency.service_id]",
"cascade": "all, delete-orphan"
"cascade": "all, delete-orphan",
},
)

Expand Down Expand Up @@ -116,6 +116,9 @@ class TopologyServiceDtoBase(BaseModel, extra="ignore"):

class TopologyServiceInDto(TopologyServiceDtoBase):
dependencies: dict[str, str] = {} # dict of service it depends on : protocol
application_relations: Optional[dict[UUID, str]] = (
None # An option field, pass it in the form of {application_id_1: application_name_1, application_id_2: application_name_2, ...} tha t the service belongs to, the process_topology function handles the creation/updation of the application
)


class TopologyServiceDependencyDto(BaseModel, extra="ignore"):
Expand Down
4 changes: 2 additions & 2 deletions keep/api/routes/preset.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ def pull_data_from_providers(
f"Provider {provider.type} ({provider.id}) does not implement pulling topology data",
extra=extra,
)
except Exception:
except Exception as e:
logger.exception(
f"Unknown error pulling topology from provider {provider.type} ({provider.id})",
extra={**extra},
extra={**extra, "exception": str(e)},
)

for fingerprint, alert in sorted_provider_alerts_by_fingerprint.items():
Expand Down
36 changes: 36 additions & 0 deletions keep/api/tasks/process_topology_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
TopologyService,
TopologyServiceDependency,
TopologyServiceInDto,
TopologyApplicationDtoIn,
TopologyServiceDtoIn,
)
from keep.topologies.topologies_service import TopologiesService

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -68,8 +71,26 @@ def process_topology(
session.flush()
service_to_keep_service_id_map[service.service] = db_service.id

application_to_services = {}
application_to_name = {}

# Then create the dependencies
for service in topology_data:

# Group all services by application (this is for processing application related data in the next step)
if service.application_relations is not None:
service_id = service_to_keep_service_id_map.get(service.service)
for application_id in service.application_relations:

application_to_name[application_id] = service.application_relations[
application_id
]

if application_id not in application_to_services:
application_to_services[application_id] = [service_id]
else:
application_to_services[application_id].append(service_id)

for dependency in service.dependencies:
service_id = service_to_keep_service_id_map.get(service.service)
depends_on_service_id = service_to_keep_service_id_map.get(dependency)
Expand All @@ -89,6 +110,21 @@ def process_topology(

session.commit()

# Now create or update the application
for application_id in application_to_services:
TopologiesService.create_or_update_application(
tenant_id=tenant_id,
application=TopologyApplicationDtoIn(
id=application_id,
name=application_to_name[application_id],
services=[
TopologyServiceDtoIn(id=service_id)
for service_id in application_to_services[application_id]
],
),
session=session,
)

try:
session.close()
except Exception as e:
Expand Down
105 changes: 105 additions & 0 deletions keep/providers/argocd_provider/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# Instructions for ~~a quick~~ setup

## Setting up ArgoCD

### Installation

1. Spin up Docker Daemon
2. Wait for kubernetes to start
3. Run the commands below
```bash
kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
```
4. If you're on Mac/Linux
```bash
brew install argocd
```
If you're on windows:
Download the executable from here https://github.com/argoproj/argo-cd/releases/latest
5. cd to the `argocd_provider` & run this command (This will create a dummy ApplicationSetwith application app-1 and app-2)
```bash
kubectl apply -f applicationset.yaml
```
6. Run this command to open configmap
```bash
kubectl edit configmap argocd-cm -n argocd
```
7. add this in the configmap
```yaml
data:
accounts.admin: apiKey, login
```
Finally, your configmap should look similar to this
```yaml
# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
apiVersion: v1

################ This is the new part###########
data:
accounts.admin: apiKey, login
################################################
kind: ConfigMap
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"v1","kind":"ConfigMap","metadata":{"annotations":{},"labels":{"app.kubernetes.io/name":"argocd-cm","app.kubernetes.io/part-of":"argocd"},"name":"argocd-cm","namespace":"argocd"}}
creationTimestamp: "2024-12-27T15:40:06Z"
labels:
app.kubernetes.io/name: argocd-cm
app.kubernetes.io/part-of: argocd
name: argocd-cm
namespace: argocd
resourceVersion: "807860"
uid: e2d8722f-e3bc-4299-9bb6-669b2873acdd
```

8. Restart your server
``` bash
kubectl rollout restart deployment argocd-server -n argocd
```

9. Expose the port
```bash
kubectl port-forward svc/argocd-server -n argocd 8000:443
```

10. Run this to get the initial Password & copy this
```bash
argocd admin initial-password -n argocd
```
11. Go to https://localhost:8000, login with credentials Username: admin, Password: <FROM_PREV_STEP>.

12. Click `+ New App` > `Edit as YAML` > Paste the yaml below > Click `Save` > Click `Create`:
```yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: application-1
spec:
destination:
name: ''
namespace: default
server: https://kubernetes.default.svc
source:
path: apps
repoURL: https://github.com/argoproj/argocd-example-apps.git
targetRevision: HEAD
sources: []
project: default
```
13. Find Card `application-1` and click `Sync` > Click `SYNCHRONIZE`.

### Getting Access Token

1. Go to `Settings` > `Accounts` > `Admin` > `Generate New` under tokens, this will generate an access token (Copy this).

### Setting up provider
1. Provider Name: UwU
2. Access Token: `<TOKEN_FROM_PREV_STEP>`
3. Deployment URL: `https://localhost:8000`
Empty file.
29 changes: 29 additions & 0 deletions keep/providers/argocd_provider/applicationset.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: list-applicationset
namespace: argocd
spec:
generators:
- list:
elements:
- cluster: https://kubernetes.default.svc
namespace: app1
name: app1
path: app1-config
- cluster: https://kubernetes.default.svc
namespace: app2
name: app2
path: app2-config
template:
metadata:
name: '{{name}}'
spec:
project: default
source:
repoURL: https://github.com/your-org/your-repo
targetRevision: main
path: '{{path}}'
destination:
server: '{{cluster}}'
namespace: '{{namespace}}'
Loading

0 comments on commit 63fae16

Please sign in to comment.