# Policy

Cedana API for policies

## POST /v2/policy/create

> Create policy

```json
{"openapi":"3.1.0","info":{"title":"Cedana API","version":"0.0.0-staging"},"tags":[{"name":"Policy","description":"Cedana API for policies"}],"security":[{"Token":[]}],"components":{"securitySchemes":{"Token":{"type":"http","scheme":"bearer"}},"schemas":{"PolicyRequest":{"type":"object","required":["heartbeat_time","resource_ids","cluster_id"],"properties":{"cluster_id":{"type":"string"},"heartbeat_time":{"type":"integer","format":"int64","minimum":0},"id":{"type":["string","null"]},"job_filter":{"oneOf":[{"type":"null"},{"$ref":"#/components/schemas/JobFilter"}]},"policy_type":{"oneOf":[{"type":"null"},{"$ref":"#/components/schemas/PolicyType"}]},"resource":{"oneOf":[{"type":"null"},{"$ref":"#/components/schemas/PolicyResource"}]},"resource_ids":{"type":"array","items":{"type":"string","format":"uuid"}},"resource_name":{"type":"string"},"runc_root":{"type":["string","null"]}}},"JobFilter":{"type":"object","properties":{"namespace":{"type":["string","null"]},"priority":{"type":["integer","null"],"format":"int32"}}},"PolicyType":{"type":"string","enum":["heartbeat"]},"PolicyResource":{"type":"string","enum":["pods","namespace","jobs"]},"ApiError":{"type":"object","description":"Standard error response for API endpoints","required":["message"],"properties":{"code":{"type":["string","null"],"description":"HTTP status code"},"details":{"description":"Optional additional error details"},"message":{"type":"string","description":"Error message describing what went wrong"}}}}},"paths":{"/v2/policy/create":{"post":{"tags":["Policy"],"summary":"Create policy","operationId":"policy_create","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/PolicyRequest"}}},"required":true},"responses":{"200":{"description":"Policy created successfully","content":{"text/plain":{"schema":{"type":"string"}}}},"400":{"description":"Invalid request body","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ApiError"}}}},"500":{"description":"Failed to create policy in policy table","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ApiError"}}}}}}}}}
```

## DELETE /v2/policy/delete

> Delete policy

```json
{"openapi":"3.1.0","info":{"title":"Cedana API","version":"0.0.0-staging"},"tags":[{"name":"Policy","description":"Cedana API for policies"}],"security":[{"Token":[]}],"components":{"securitySchemes":{"Token":{"type":"http","scheme":"bearer"}},"schemas":{"PolicyDeleteRequest":{"type":"object","required":["id"],"properties":{"id":{"type":"string","format":"uuid"}}},"ApiError":{"type":"object","description":"Standard error response for API endpoints","required":["message"],"properties":{"code":{"type":["string","null"],"description":"HTTP status code"},"details":{"description":"Optional additional error details"},"message":{"type":"string","description":"Error message describing what went wrong"}}}}},"paths":{"/v2/policy/delete":{"delete":{"tags":["Policy"],"summary":"Delete policy","operationId":"policy_delete","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/PolicyDeleteRequest"}}},"required":true},"responses":{"200":{"description":"Policy deleted successfully","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ApiError"}}}},"400":{"description":"Invalid request body","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ApiError"}}}},"500":{"description":"Failed to delete policy from policy table","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ApiError"}}}}}}}}}
```

## GET /v2/policy/list

> List policies

```json
{"openapi":"3.1.0","info":{"title":"Cedana API","version":"0.0.0-staging"},"tags":[{"name":"Policy","description":"Cedana API for policies"}],"security":[{"Token":[]}],"components":{"securitySchemes":{"Token":{"type":"http","scheme":"bearer"}},"schemas":{"PolicyResponse":{"type":"object","required":["id","status","policy_type","input","resource","resource_list","pod_count"],"properties":{"id":{"type":"string"},"input":{"type":"integer","format":"int64"},"job_count":{"type":["integer","null"],"format":"int64"},"pod_count":{"type":"integer","format":"int64"},"policy_type":{"type":"string"},"resource":{"type":"string"},"resource_list":{"type":"array","items":{"type":"string"}},"status":{"type":"string"},"timestamp":{"type":["string","null"],"format":"date-time"}}},"ApiError":{"type":"object","description":"Standard error response for API endpoints","required":["message"],"properties":{"code":{"type":["string","null"],"description":"HTTP status code"},"details":{"description":"Optional additional error details"},"message":{"type":"string","description":"Error message describing what went wrong"}}}}},"paths":{"/v2/policy/list":{"get":{"tags":["Policy"],"summary":"List policies","operationId":"policy_list","responses":{"200":{"description":"Policies retrieved successfully","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/PolicyResponse"}}}}},"400":{"description":"Invalid request body","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ApiError"}}}},"500":{"description":"Failed to retriev policies from policy table","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ApiError"}}}}}}}}}
```

## POST /v2/policy/sync-jobs

> Sync job policies manually

```json
{"openapi":"3.1.0","info":{"title":"Cedana API","version":"0.0.0-staging"},"tags":[{"name":"Policy","description":"Cedana API for policies"}],"security":[{"api_key":[]}],"components":{"securitySchemes":{},"schemas":{"ApiError":{"type":"object","description":"Standard error response for API endpoints","required":["message"],"properties":{"code":{"type":["string","null"],"description":"HTTP status code"},"details":{"description":"Optional additional error details"},"message":{"type":"string","description":"Error message describing what went wrong"}}}}},"paths":{"/v2/policy/sync-jobs":{"post":{"tags":["Policy"],"summary":"Sync job policies manually","operationId":"sync_job_policies","responses":{"200":{"description":"Job policies synced successfully","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ApiError"}}}},"500":{"description":"Failed to sync job policies"}}}}}}
```

## POST /v2/policy/update

> Update policy

```json
{"openapi":"3.1.0","info":{"title":"Cedana API","version":"0.0.0-staging"},"tags":[{"name":"Policy","description":"Cedana API for policies"}],"security":[{"Token":[]}],"components":{"securitySchemes":{"Token":{"type":"http","scheme":"bearer"}},"schemas":{"PolicyRequest":{"type":"object","required":["heartbeat_time","resource_ids","cluster_id"],"properties":{"cluster_id":{"type":"string"},"heartbeat_time":{"type":"integer","format":"int64","minimum":0},"id":{"type":["string","null"]},"job_filter":{"oneOf":[{"type":"null"},{"$ref":"#/components/schemas/JobFilter"}]},"policy_type":{"oneOf":[{"type":"null"},{"$ref":"#/components/schemas/PolicyType"}]},"resource":{"oneOf":[{"type":"null"},{"$ref":"#/components/schemas/PolicyResource"}]},"resource_ids":{"type":"array","items":{"type":"string","format":"uuid"}},"resource_name":{"type":"string"},"runc_root":{"type":["string","null"]}}},"JobFilter":{"type":"object","properties":{"namespace":{"type":["string","null"]},"priority":{"type":["integer","null"],"format":"int32"}}},"PolicyType":{"type":"string","enum":["heartbeat"]},"PolicyResource":{"type":"string","enum":["pods","namespace","jobs"]},"ApiError":{"type":"object","description":"Standard error response for API endpoints","required":["message"],"properties":{"code":{"type":["string","null"],"description":"HTTP status code"},"details":{"description":"Optional additional error details"},"message":{"type":"string","description":"Error message describing what went wrong"}}}}},"paths":{"/v2/policy/update":{"post":{"tags":["Policy"],"summary":"Update policy","operationId":"policy_update","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/PolicyRequest"}}},"required":true},"responses":{"200":{"description":"Policy updated successfully","content":{"text/plain":{"schema":{"type":"string"}}}},"400":{"description":"Invalid request body","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ApiError"}}}},"500":{"description":"Failed to update policy from policy table","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ApiError"}}}}}}}}}
```

## GET /v2/policy/{policy\_id}/job-status

> Get job policy tracking status

```json
{"openapi":"3.1.0","info":{"title":"Cedana API","version":"0.0.0-staging"},"tags":[{"name":"Policy","description":"Cedana API for policies"}],"security":[{"api_key":[]}],"components":{"securitySchemes":{},"schemas":{"JobPolicyStatus":{"type":"object","required":["policy_id","job_ids","tracked_pods","pod_count"],"properties":{"job_ids":{"type":"array","items":{"type":"string"}},"job_status":{"type":["string","null"]},"last_updated":{"type":["string","null"]},"pod_count":{"type":"integer","format":"int64"},"policy_id":{"type":"string"},"tracked_pods":{"type":"array","items":{"type":"string"}}}}}},"paths":{"/v2/policy/{policy_id}/job-status":{"get":{"tags":["Policy"],"summary":"Get job policy tracking status","operationId":"get_job_policy_status","parameters":[{"name":"policy_id","in":"path","description":"Policy ID to get status for","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"Job policy status","content":{"application/json":{"schema":{"$ref":"#/components/schemas/JobPolicyStatus"}}}},"404":{"description":"Policy not found"},"500":{"description":"Internal server error"}}}}}}
```

## GET /v2/policy/{policy\_id}/jobs

> Get jobs affected by a policy

```json
{"openapi":"3.1.0","info":{"title":"Cedana API","version":"0.0.0-staging"},"tags":[{"name":"Policy","description":"Cedana API for policies"}],"security":[{"api_key":[]}],"components":{"securitySchemes":{},"schemas":{"PolicyJobsResponse":{"type":"object","required":["policy_id","affected_jobs","count"],"properties":{"affected_jobs":{"type":"array","items":{"$ref":"#/components/schemas/PolicyJobInfo"}},"count":{"type":"integer","format":"int64"},"policy_id":{"type":"string"}}},"PolicyJobInfo":{"type":"object","required":["id","name","namespace","status","pod_count"],"properties":{"id":{"type":"string"},"name":{"type":"string"},"namespace":{"type":"string"},"pod_count":{"type":"integer","format":"int64"},"priority":{"type":["integer","null"],"format":"int32"},"status":{"type":"string"}}}}},"paths":{"/v2/policy/{policy_id}/jobs":{"get":{"tags":["Policy"],"summary":"Get jobs affected by a policy","operationId":"policy_jobs","parameters":[{"name":"policy_id","in":"path","description":"Policy ID to get affected jobs for","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"Jobs affected by the policy","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PolicyJobsResponse"}}}},"404":{"description":"Policy not found or not a job policy"},"500":{"description":"Internal server error"}}}}}}
```

## GET /v2/policy/{policy\_id}/pods

> Get pods monitored by a specific policy

```json
{"openapi":"3.1.0","info":{"title":"Cedana API","version":"0.0.0-staging"},"tags":[{"name":"Policy","description":"Cedana API for policies"}],"security":[{"Token":[]}],"components":{"securitySchemes":{"Token":{"type":"http","scheme":"bearer"}},"schemas":{"PolicyPodResponse":{"type":"object","required":["id","name","namespace","status"],"properties":{"id":{"type":"string","format":"uuid"},"name":{"type":"string"},"namespace":{"type":"string"},"status":{"type":"string"}}},"ApiError":{"type":"object","description":"Standard error response for API endpoints","required":["message"],"properties":{"code":{"type":["string","null"],"description":"HTTP status code"},"details":{"description":"Optional additional error details"},"message":{"type":"string","description":"Error message describing what went wrong"}}}}},"paths":{"/v2/policy/{policy_id}/pods":{"get":{"tags":["Policy"],"summary":"Get pods monitored by a specific policy","operationId":"policy_pods","parameters":[{"name":"policy_id","in":"path","description":"Policy UUID","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"Returns pods currently monitored by the policy","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/PolicyPodResponse"}}}}},"400":{"description":"Invalid policy_id format","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ApiError"}}}},"404":{"description":"Policy not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ApiError"}}}},"500":{"description":"Failed to connect/fetch from database","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ApiError"}}}}}}}}}
```
