API Reference
This page provides a complete API reference for the OptimizationPolicy Custom Resource Definition (CRD).
API Version
Section titled “API Version”apiVersion: optipod.optipod.io/v1alpha1kind: OptimizationPolicyResource Structure
Section titled “Resource Structure”apiVersion: optipod.optipod.io/v1alpha1kind: OptimizationPolicymetadata: name: string namespace: stringspec: mode: string weight: integer selector: object metricsConfig: object resourceBounds: object updateStrategy: object reconciliationInterval: durationstatus: conditions: []Condition workloadsDiscovered: integer workloadsProcessed: integer lastReconciliation: timestamp workloadsByType: objectMetadata
Section titled “Metadata”Standard Kubernetes metadata fields:
| Field | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Policy name |
namespace | string | Yes | Policy namespace |
labels | map[string]string | No | Labels |
annotations | map[string]string | No | Annotations |
Spec Fields
Section titled “Spec Fields”spec.mode
Section titled “spec.mode”| Property | Value |
|---|---|
| Type | string |
| Required | Yes |
| Values | Recommend, Auto, Disabled |
| Default | None |
Operational mode for the policy.
Example:
spec: mode: Recommendspec.weight
Section titled “spec.weight”| Property | Value |
|---|---|
| Type | integer |
| Required | No |
| Range | 1-1000 |
| Default | 100 |
Priority when multiple policies match the same workload. Higher weight wins.
Example:
spec: weight: 200spec.selector
Section titled “spec.selector”| Property | Value |
|---|---|
| Type | object |
| Required | Yes |
| Fields | workloadSelector, namespaceSelector, namespaces, workloadTypes |
Defines which workloads this policy applies to.
Structure:
spec: selector: workloadSelector: matchLabels: map[string]string matchExpressions: []LabelSelectorRequirement namespaceSelector: matchLabels: map[string]string matchExpressions: []LabelSelectorRequirement namespaces: allow: []string deny: []string workloadTypes: include: []WorkloadType exclude: []WorkloadTypeExample:
spec: selector: workloadSelector: matchLabels: optipod.io/enabled: "true" workloadTypes: include: - Deployment - StatefulSet namespaces: allow: - production - stagingspec.selector.workloadSelector
Section titled “spec.selector.workloadSelector”| Property | Value |
|---|---|
| Type | LabelSelector |
| Required | No |
Standard Kubernetes label selector for workloads.
Example:
workloadSelector: matchLabels: optipod.io/enabled: "true" environment: production matchExpressions: - key: tier operator: In values: ["frontend", "backend"]spec.selector.namespaceSelector
Section titled “spec.selector.namespaceSelector”| Property | Value |
|---|---|
| Type | LabelSelector |
| Required | No |
Standard Kubernetes label selector for namespaces.
Example:
namespaceSelector: matchLabels: environment: productionspec.selector.namespaces
Section titled “spec.selector.namespaces”| Property | Value |
|---|---|
| Type | object |
| Required | No |
| Fields | allow, deny |
Allow/deny lists for namespace filtering. Deny takes precedence over allow.
Example:
namespaces: allow: - production - staging deny: - kube-system - kube-publicspec.selector.workloadTypes
Section titled “spec.selector.workloadTypes”| Property | Value |
|---|---|
| Type | object |
| Required | No |
| Fields | include, exclude |
Include/exclude filters for workload types. Exclude takes precedence over include.
Supported workload types:
DeploymentStatefulSetDaemonSet
Example:
workloadTypes: include: - Deployment - StatefulSet exclude: - DaemonSetspec.metricsConfig
Section titled “spec.metricsConfig”| Property | Value |
|---|---|
| Type | object |
| Required | Yes |
| Fields | provider, rollingWindow, percentile, safetyFactor, metricsServer |
Configuration for metrics collection and processing.
Structure:
spec: metricsConfig: provider: string rollingWindow: duration percentile: string safetyFactor: float metricsServer: minSamplesRequired: integerExample:
spec: metricsConfig: provider: prometheus rollingWindow: 7d percentile: P90 safetyFactor: 1.2spec.metricsConfig.provider
Section titled “spec.metricsConfig.provider”| Property | Value |
|---|---|
| Type | string |
| Required | Yes |
| Values | prometheus, metrics-server, custom |
Metrics backend to use.
spec.metricsConfig.rollingWindow
Section titled “spec.metricsConfig.rollingWindow”| Property | Value |
|---|---|
| Type | duration |
| Required | No |
| Default | 24h |
| Format | <number><unit> (d=days, h=hours, m=minutes, s=seconds) |
Time period over which metrics are aggregated.
Examples: 3d, 7d, 14d, 24h
spec.metricsConfig.percentile
Section titled “spec.metricsConfig.percentile”| Property | Value |
|---|---|
| Type | string |
| Required | No |
| Values | P50, P90, P99 |
| Default | P90 |
Percentile to use for recommendations.
spec.metricsConfig.safetyFactor
Section titled “spec.metricsConfig.safetyFactor”| Property | Value |
|---|---|
| Type | float |
| Required | No |
| Default | 1.2 |
| Minimum | 1.0 |
Multiplier applied to the selected percentile to add headroom.
Example: With P90=200m and safetyFactor=1.2, recommendation is 240m.
spec.metricsConfig.metricsServer
Section titled “spec.metricsConfig.metricsServer”| Property | Value |
|---|---|
| Type | object |
| Required | No |
| Fields | minSamplesRequired |
Configuration specific to metrics-server provider.
Example:
metricsServer: minSamplesRequired: 10spec.resourceBounds
Section titled “spec.resourceBounds”| Property | Value |
|---|---|
| Type | object |
| Required | Yes |
| Fields | cpu, memory |
Minimum and maximum constraints for recommendations.
Structure:
spec: resourceBounds: cpu: min: quantity max: quantity memory: min: quantity max: quantityExample:
spec: resourceBounds: cpu: min: 10m max: 4000m memory: min: 64Mi max: 8Gispec.resourceBounds.cpu
Section titled “spec.resourceBounds.cpu”| Property | Value |
|---|---|
| Type | object |
| Required | Yes |
| Fields | min, max |
CPU resource bounds.
spec.resourceBounds.memory
Section titled “spec.resourceBounds.memory”| Property | Value |
|---|---|
| Type | object |
| Required | Yes |
| Fields | min, max |
Memory resource bounds.
spec.updateStrategy
Section titled “spec.updateStrategy”| Property | Value |
|---|---|
| Type | object |
| Required | Yes |
| Fields | strategy, rolloutStrategy, useServerSideApply, updateRequestsOnly, allowInPlaceResize, allowRecreate, allowUnsafeMemoryDecrease, limitConfig, gradualDecreaseConfig |
Defines how resource updates are applied.
Structure:
spec: updateStrategy: strategy: string rolloutStrategy: string useServerSideApply: boolean updateRequestsOnly: boolean allowInPlaceResize: boolean allowRecreate: boolean allowUnsafeMemoryDecrease: boolean limitConfig: cpuLimitMultiplier: float memoryLimitMultiplier: float # gradualDecreaseConfig: Not yet implementedExample:
spec: updateStrategy: strategy: ssa rolloutStrategy: onNextRestart useServerSideApply: true updateRequestsOnly: true allowUnsafeMemoryDecrease: false limitConfig: cpuLimitMultiplier: 1.0 memoryLimitMultiplier: 1.1 # Note: gradualDecreaseConfig not yet implementedspec.updateStrategy.strategy
Section titled “spec.updateStrategy.strategy”| Property | Value |
|---|---|
| Type | string |
| Required | No |
| Values | ssa, webhook |
| Default | webhook |
Update strategy type.
spec.updateStrategy.rolloutStrategy
Section titled “spec.updateStrategy.rolloutStrategy”| Property | Value |
|---|---|
| Type | string |
| Required | No |
| Values | immediate, onNextRestart |
| Default | onNextRestart |
When changes take effect (webhook strategy only).
spec.updateStrategy.useServerSideApply
Section titled “spec.updateStrategy.useServerSideApply”| Property | Value |
|---|---|
| Type | boolean |
| Required | No |
| Default | true |
Enable Server-Side Apply for field-level ownership.
spec.updateStrategy.updateRequestsOnly
Section titled “spec.updateStrategy.updateRequestsOnly”| Property | Value |
|---|---|
| Type | boolean |
| Required | No |
| Default | true |
Update only requests, not limits.
spec.updateStrategy.allowInPlaceResize
Section titled “spec.updateStrategy.allowInPlaceResize”| Property | Value |
|---|---|
| Type | boolean |
| Required | No |
| Default | true |
Enable in-place pod resize when supported by Kubernetes.
spec.updateStrategy.allowRecreate
Section titled “spec.updateStrategy.allowRecreate”| Property | Value |
|---|---|
| Type | boolean |
| Required | No |
| Default | false |
Allow pod recreation when in-place resize is not available.
spec.updateStrategy.allowUnsafeMemoryDecrease
Section titled “spec.updateStrategy.allowUnsafeMemoryDecrease”| Property | Value |
|---|---|
| Type | boolean |
| Required | No |
| Default | false |
Disable memory safety checks. When false, OptiPod blocks memory decreases that could cause OOM kills.
spec.updateStrategy.limitConfig
Section titled “spec.updateStrategy.limitConfig”| Property | Value |
|---|---|
| Type | object |
| Required | No |
| Fields | cpuLimitMultiplier, memoryLimitMultiplier |
How limits are calculated from requests.
Example:
limitConfig: cpuLimitMultiplier: 1.0 # Limit = request × 1.0 memoryLimitMultiplier: 1.1 # Limit = request × 1.1spec.updateStrategy.gradualDecreaseConfig
Section titled “spec.updateStrategy.gradualDecreaseConfig”⚠️ Implementation Status: Not yet implemented. Configuration is accepted but has no effect.
| Property | Value |
|---|---|
| Type | object |
| Required | No |
| Fields | enabled, memoryDecreasePercentage, minimumDecreaseThreshold, maximumTotalDecrease |
Gradual memory reduction configuration for safer optimization (planned feature).
Example:
gradualDecreaseConfig: enabled: true memoryDecreasePercentage: 10 minimumDecreaseThreshold: 100Mi maximumTotalDecrease: 70Current Behavior: Memory decreases are applied immediately in full.
spec.reconciliationInterval
Section titled “spec.reconciliationInterval”| Property | Value |
|---|---|
| Type | duration |
| Required | No |
| Default | 5m |
| Format | <number><unit> (d=days, h=hours, m=minutes, s=seconds) |
How often the policy is evaluated.
Example:
spec: reconciliationInterval: 5mStatus Fields
Section titled “Status Fields”status.conditions
Section titled “status.conditions”| Property | Value |
|---|---|
| Type | []Condition |
Standard Kubernetes conditions.
Example:
status: conditions: - type: Ready status: "True" lastTransitionTime: "2026-01-26T10:30:00Z" reason: PolicyActive message: Policy is active and processing workloadsstatus.workloadsDiscovered
Section titled “status.workloadsDiscovered”| Property | Value |
|---|---|
| Type | integer |
Count of workloads matching this policy.
status.workloadsProcessed
Section titled “status.workloadsProcessed”| Property | Value |
|---|---|
| Type | integer |
Count of workloads successfully processed.
status.lastReconciliation
Section titled “status.lastReconciliation”| Property | Value |
|---|---|
| Type | timestamp |
| Format | RFC3339 |
Timestamp of the last reconciliation.
status.workloadsByType
Section titled “status.workloadsByType”| Property | Value |
|---|---|
| Type | object |
| Fields | deployments, statefulSets, daemonSets |
Breakdown of workloads by type.
Example:
status: workloadsByType: deployments: 3 statefulSets: 2 daemonSets: 0Complete Example
Section titled “Complete Example”apiVersion: optipod.optipod.io/v1alpha1kind: OptimizationPolicymetadata: name: production-policy namespace: production labels: environment: production tier: standardspec: mode: Auto weight: 150
selector: workloadSelector: matchLabels: optipod.io/enabled: "true" workloadTypes: include: - Deployment - StatefulSet namespaces: allow: - production
metricsConfig: provider: prometheus rollingWindow: 7d percentile: P90 safetyFactor: 1.2
resourceBounds: cpu: min: 10m max: 4000m memory: min: 64Mi max: 8Gi
updateStrategy: strategy: ssa rolloutStrategy: onNextRestart useServerSideApply: true updateRequestsOnly: true allowInPlaceResize: true allowRecreate: false allowUnsafeMemoryDecrease: false limitConfig: cpuLimitMultiplier: 1.0 memoryLimitMultiplier: 1.1 # Note: gradualDecreaseConfig not yet implemented
reconciliationInterval: 5m
status: conditions: - type: Ready status: "True" lastTransitionTime: "2026-01-26T10:30:00Z" reason: PolicyActive message: Policy is active and processing workloads workloadsDiscovered: 5 workloadsProcessed: 5 lastReconciliation: "2026-01-26T10:30:00Z" workloadsByType: deployments: 3 statefulSets: 2 daemonSets: 0kubectl Commands
Section titled “kubectl Commands”Create Policy
Section titled “Create Policy”kubectl apply -f policy.yamlList Policies
Section titled “List Policies”# All namespaceskubectl get optimizationpolicy -A
# Specific namespacekubectl get optimizationpolicy -n production
# With custom columnskubectl get optimizationpolicy -A \ -o custom-columns=NAMESPACE:.metadata.namespace,NAME:.metadata.name,MODE:.spec.mode,PROVIDER:.spec.metricsConfig.providerGet Policy Details
Section titled “Get Policy Details”# YAML outputkubectl get optimizationpolicy my-policy -n production -o yaml
# JSON outputkubectl get optimizationpolicy my-policy -n production -o json
# Describekubectl describe optimizationpolicy my-policy -n productionUpdate Policy
Section titled “Update Policy”# Edit interactivelykubectl edit optimizationpolicy my-policy -n production
# Patch modekubectl patch optimizationpolicy my-policy -n production \ --type merge \ -p '{"spec":{"mode":"Auto"}}'
# Patch weightkubectl patch optimizationpolicy my-policy -n production \ --type merge \ -p '{"spec":{"weight":200}}'Delete Policy
Section titled “Delete Policy”kubectl delete optimizationpolicy my-policy -n production