-
Notifications
You must be signed in to change notification settings - Fork 17
feat: add argo workflow JobAgent #856
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
Merged
mleonidas
merged 46 commits into
main
from
777-feat-add-argo-workflows-job-agent-integration
Mar 31, 2026
Merged
Changes from all commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
287c528
feat: add argo workflow JobAgent
mleonidas b1d2513
fix: update jsonnet for argo workflow
mleonidas ab23275
fix: bad typescript
mleonidas 1616248
fix: same params as argocd
mleonidas 40f6e4f
feat: continue adding argoworkflow jobagent
mleonidas 55aac41
feat: continuing with argo workflow agent
mleonidas efc4a84
{WIP}
mleonidas 5956230
feat: use generateName on workflow
mleonidas 7a442bf
test: add some tests
mleonidas f514d10
feat: support workflowtemplate calls
mleonidas c4576c5
Merge branch 'main' into 777-feat-add-argo-workflows-job-agent-integr…
mleonidas d516cc4
wip
mleonidas 5a6d18a
Merge branch 'main' into 777-feat-add-argo-workflows-job-agent-integr…
mleonidas 79edb58
fix: lint issues
mleonidas 39f4b25
fix: more lint issues
mleonidas a22e461
Merge branch 'main' into 777-feat-add-argo-workflows-job-agent-integr…
mleonidas f10661b
fix: more linting issues
mleonidas ce5a605
Merge branch 'main' into 777-feat-add-argo-workflows-job-agent-integr…
mleonidas 172f980
chore: update go.mod
mleonidas f9d80d9
Merge branch 'main' into 777-feat-add-argo-workflows-job-agent-integr…
mleonidas a5513ed
docs: add argo-workflow docs
mleonidas 076226f
fix: add generated files
mleonidas 207761e
feat: check if job is already running
mleonidas eda2058
Merge branch 'main' into 777-feat-add-argo-workflows-job-agent-integr…
mleonidas 6e594ae
fix: remove unused var
mleonidas 70b1d36
Merge branch 'main' into 777-feat-add-argo-workflows-job-agent-integr…
mleonidas 2b13b39
refactor: workflowTemplates no need for special treatment
mleonidas ad0a803
feat: pass ssl config through config env
mleonidas c13136a
fix: remove unused function
mleonidas b1da6b7
fix: remove config dir
mleonidas 3edfed8
fix: remove binary
mleonidas 005e0fa
fix: remove unused import
mleonidas 45c23c7
docs: update example env file
mleonidas 646d3e2
fix: lint issues
mleonidas 3c3c775
Update apps/api/src/routes/argoworkflow/workflow.ts
mleonidas 1198ea7
Update apps/api/src/routes/argoworkflow/workflow.ts
mleonidas 683860e
fix: package naming
mleonidas 59f85f3
feat: route based on jobAgent ID
mleonidas 55b1028
fix: update docs to reflect new webhook
mleonidas 0b77314
fix: eslint error
mleonidas 5071eb5
feat: update oapi spec
mleonidas bb3e334
Merge branch 'main' into 777-feat-add-argo-workflows-job-agent-integr…
mleonidas a8c42d0
Update docs/integrations/job-agents/argo-workflows.mdx
mleonidas 3d7e0a9
fix: remove print statement
mleonidas 7a8b7a3
Merge branch 'main' into 777-feat-add-argo-workflows-job-agent-integr…
mleonidas 4532801
Merge branch 'main' into 777-feat-add-argo-workflows-job-agent-integr…
mleonidas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import type { Request, Response } from "express"; | ||
| import { asyncHandler } from "@/types/api.js"; | ||
| import { Router } from "express"; | ||
|
|
||
| import { eq } from "@ctrlplane/db"; | ||
| import { db } from "@ctrlplane/db/client"; | ||
| import * as schema from "@ctrlplane/db/schema"; | ||
|
|
||
| import { handleArgoWorkflow } from "./workflow.js"; | ||
|
|
||
| export const createArgoWorkflowRouter = (): Router => | ||
| Router().post("/:id/webhook", asyncHandler(handleWebhookRequest)); | ||
|
|
||
| const getJobAgent = async (id: string) => { | ||
| return db.query.jobAgent.findFirst({ | ||
| where: eq(schema.jobAgent.id, id), | ||
| }); | ||
| }; | ||
|
|
||
| const handleWebhookRequest = async (req: Request, res: Response) => { | ||
| const { id } = req.params; | ||
| if (id == null) { | ||
| res.status(400).json({ message: "Missing job agent id" }); | ||
| return; | ||
| } | ||
|
|
||
| const agent = await getJobAgent(id); | ||
| if (agent == null) { | ||
| res.status(404).json({ message: "Job agent not found" }); | ||
| return; | ||
| } | ||
|
|
||
| const config = agent.config as Record<string, unknown>; | ||
| const webhookSecret = | ||
| typeof config.webhookSecret === "string" ? config.webhookSecret : null; | ||
| if (webhookSecret == null) { | ||
| res | ||
| .status(500) | ||
| .json({ message: "Job agent has no webhookSecret configured" }); | ||
| return; | ||
| } | ||
|
|
||
| const authHeader = req.headers.authorization?.toString(); | ||
| if (authHeader == null || authHeader !== webhookSecret) { | ||
| res.status(401).json({ message: "Unauthorized" }); | ||
| return; | ||
| } | ||
|
|
||
| const payload = req.body; | ||
| await handleArgoWorkflow(payload); | ||
| res.status(200).send(); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import { eq } from "@ctrlplane/db"; | ||
| import { db } from "@ctrlplane/db/client"; | ||
| import { enqueueAllReleaseTargetsDesiredVersion } from "@ctrlplane/db/reconcilers"; | ||
| import * as schema from "@ctrlplane/db/schema"; | ||
| import { exitedStatus, JobStatus } from "@ctrlplane/validators/jobs"; | ||
|
|
||
| interface ArgoWorkflowPayload { | ||
| workflowName: string; | ||
| namespace: string; | ||
| uid: string; | ||
| createdAt: string; | ||
| startedAt: string; | ||
| finishedAt: string | null; | ||
| jobId: string | null; | ||
| phase: string; | ||
| eventType: string; | ||
| } | ||
|
|
||
| const statusMap: Record<string, JobStatus> = { | ||
| Succeeded: JobStatus.Successful, | ||
| Failed: JobStatus.Failure, | ||
| Running: JobStatus.InProgress, | ||
| Pending: JobStatus.Pending, | ||
| }; | ||
|
|
||
| export const mapTriggerToStatus = (trigger: string): JobStatus | null => | ||
| statusMap[trigger] ?? null; | ||
|
|
||
| export const getJobId = (payload: ArgoWorkflowPayload) => | ||
| payload.jobId ?? payload.workflowName; | ||
|
|
||
| export const handleArgoWorkflow = async (payload: ArgoWorkflowPayload) => { | ||
| const { uid, phase, startedAt, finishedAt } = payload; | ||
|
|
||
| const jobId = getJobId(payload); | ||
|
|
||
| const status = statusMap[phase] ?? null; | ||
| if (status == null) return; | ||
|
|
||
| const isCompleted = exitedStatus.includes(status); | ||
| const completedAt = | ||
| isCompleted && finishedAt != null ? new Date(finishedAt) : null; | ||
|
|
||
| const [updated] = await db | ||
| .update(schema.job) | ||
| .set({ | ||
| externalId: uid, | ||
| status, | ||
| ...(startedAt ? { startedAt: new Date(startedAt) } : {}), | ||
| completedAt, | ||
| updatedAt: new Date(), | ||
| }) | ||
| .where(eq(schema.job.id, jobId)) | ||
| .returning(); | ||
|
|
||
| if (updated == null) return; | ||
|
|
||
| const result = await db | ||
| .select({ workspaceId: schema.deployment.workspaceId }) | ||
| .from(schema.releaseJob) | ||
| .innerJoin( | ||
| schema.release, | ||
| eq(schema.releaseJob.releaseId, schema.release.id), | ||
| ) | ||
| .innerJoin( | ||
| schema.deployment, | ||
| eq(schema.release.deploymentId, schema.deployment.id), | ||
| ) | ||
| .where(eq(schema.releaseJob.jobId, jobId)) | ||
| .then((rows) => rows[0] ?? null); | ||
|
|
||
| if (result?.workspaceId == null) return; | ||
| enqueueAllReleaseTargetsDesiredVersion(db, result.workspaceId); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.