The EA Job Operator is a Kubernetes-based operator service responsible for managing the lifecycle of AgentJob custom resources (CRs). It ensures smooth orchestration of job execution within the ea-platform namespace. The operator consists of multiple independently running controllers (watch loops) to handle different stages of the job lifecycle.
-
AgentJob State Management
- Detects and marks newly created jobs as
inactive. - Moves
inactivejobs toexecutingand spawns a corresponding Kubernetes Job to execute a users AgentJob workflow. - Watches for
executingjobs that complete and updates their state tocompleted. - Cleans up
completedjobs after a configured duration.
- Detects and marks newly created jobs as
-
TODO: Orphaned Job Recovery
- Identifies jobs whose assigned operator pod has failed.
- Resets job state and removes orphaned locks to allow for retrying.
- Deletes corresponding Kubernetes Jobs to ensure a fresh restart.
-
Scalability & Configurability
- Uses feature flags via environment variables to enable/disable specific operators.
- Supports HA (High Availability) by distributing workloads across multiple pods.
The EA Job Operator runs multiple watch loops, each responsible for handling a specific part of the job lifecycle:
| Watch Function | Description |
|---|---|
WatchNewAgentJobs |
Detects new AgentJobs with blank statuses and marks them as inactive. |
WatchInactiveAgentJobs |
Moves inactive jobs to pending, locks them, and spawns Kubernetes Jobs. |
WatchCompletedJobs |
Watches Kubernetes Jobs and updates corresponding AgentJobs upon completion. |
WatchCompletedAgentJobs |
Cleans up completed jobs older than a certain threshold. |
Configuration is managed through environment variables:
| Variable | Description | Default |
|---|---|---|
PORT |
Port for metrics endpoint | 8080 |
GIN_MODE |
Gin mode (release or debug) |
release |
FEATURE_NEW_AGENT_JOBS |
Enables WatchNewAgentJobs |
true |
FEATURE_INACTIVE_AGENT_JOBS |
Enables WatchInactiveAgentJobs |
true |
FEATURE_COMPLETED_JOBS |
Enables WatchCompletedJobs |
true |
FEATURE_COMPLETED_AGENT_JOBS |
Enables WatchCompletedAgentJobs |
true |
To modify the configuration, update your deployment environment variables in chart/values.yaml.
The operator exposes Prometheus-compatible metrics at:
http://<pod-ip>:8080/metrics
Key metrics include:
operator_step_counter: Counts execution steps for each watch function.
Structured logs are emitted in JSON format and can be collected using kubectl logs:
kubectl logs -f deployment/ea-job-operator -n ea-platformRight now this works pretty well for 100s of jobs in a short period of time. If we want to go to millions of jobs a min we will need a more sophisticated mecahnism to allow actual pod performance improvements when we scale out the number of operator pods.
Today how each operator loop picks up work they just step all over eachother causing update conflict errors. We can fix these with these approaches together probably. Its fine for now though.
- job sharding for multi pod performance improvement
- implement kubernetes finalizers for job cleanup