Skip to content

API Reference

This page provides a complete API reference for the OptimizationPolicy Custom Resource Definition (CRD).

apiVersion: optipod.optipod.io/v1alpha1
kind: OptimizationPolicy
apiVersion: optipod.optipod.io/v1alpha1
kind: OptimizationPolicy
metadata:
name: string
namespace: string
spec:
mode: string
weight: integer
selector: object
metricsConfig: object
resourceBounds: object
updateStrategy: object
reconciliationInterval: duration
status:
conditions: []Condition
workloadsDiscovered: integer
workloadsProcessed: integer
lastReconciliation: timestamp
workloadsByType: object

Standard Kubernetes metadata fields:

FieldTypeRequiredDescription
namestringYesPolicy name
namespacestringYesPolicy namespace
labelsmap[string]stringNoLabels
annotationsmap[string]stringNoAnnotations
PropertyValue
Typestring
RequiredYes
ValuesRecommend, Auto, Disabled
DefaultNone

Operational mode for the policy.

Example:

spec:
mode: Recommend
PropertyValue
Typeinteger
RequiredNo
Range1-1000
Default100

Priority when multiple policies match the same workload. Higher weight wins.

Example:

spec:
weight: 200
PropertyValue
Typeobject
RequiredYes
FieldsworkloadSelector, 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: []WorkloadType

Example:

spec:
selector:
workloadSelector:
matchLabels:
optipod.io/enabled: "true"
workloadTypes:
include:
- Deployment
- StatefulSet
namespaces:
allow:
- production
- staging
PropertyValue
TypeLabelSelector
RequiredNo

Standard Kubernetes label selector for workloads.

Example:

workloadSelector:
matchLabels:
optipod.io/enabled: "true"
environment: production
matchExpressions:
- key: tier
operator: In
values: ["frontend", "backend"]
PropertyValue
TypeLabelSelector
RequiredNo

Standard Kubernetes label selector for namespaces.

Example:

namespaceSelector:
matchLabels:
environment: production
PropertyValue
Typeobject
RequiredNo
Fieldsallow, deny

Allow/deny lists for namespace filtering. Deny takes precedence over allow.

Example:

namespaces:
allow:
- production
- staging
deny:
- kube-system
- kube-public
PropertyValue
Typeobject
RequiredNo
Fieldsinclude, exclude

Include/exclude filters for workload types. Exclude takes precedence over include.

Supported workload types:

  • Deployment
  • StatefulSet
  • DaemonSet

Example:

workloadTypes:
include:
- Deployment
- StatefulSet
exclude:
- DaemonSet
PropertyValue
Typeobject
RequiredYes
Fieldsprovider, rollingWindow, percentile, safetyFactor, metricsServer

Configuration for metrics collection and processing.

Structure:

spec:
metricsConfig:
provider: string
rollingWindow: duration
percentile: string
safetyFactor: float
metricsServer:
minSamplesRequired: integer

Example:

spec:
metricsConfig:
provider: prometheus
rollingWindow: 7d
percentile: P90
safetyFactor: 1.2
PropertyValue
Typestring
RequiredYes
Valuesprometheus, metrics-server, custom

Metrics backend to use.

PropertyValue
Typeduration
RequiredNo
Default24h
Format<number><unit> (d=days, h=hours, m=minutes, s=seconds)

Time period over which metrics are aggregated.

Examples: 3d, 7d, 14d, 24h

PropertyValue
Typestring
RequiredNo
ValuesP50, P90, P99
DefaultP90

Percentile to use for recommendations.

PropertyValue
Typefloat
RequiredNo
Default1.2
Minimum1.0

Multiplier applied to the selected percentile to add headroom.

Example: With P90=200m and safetyFactor=1.2, recommendation is 240m.

PropertyValue
Typeobject
RequiredNo
FieldsminSamplesRequired

Configuration specific to metrics-server provider.

Example:

metricsServer:
minSamplesRequired: 10
PropertyValue
Typeobject
RequiredYes
Fieldscpu, memory

Minimum and maximum constraints for recommendations.

Structure:

spec:
resourceBounds:
cpu:
min: quantity
max: quantity
memory:
min: quantity
max: quantity

Example:

spec:
resourceBounds:
cpu:
min: 10m
max: 4000m
memory:
min: 64Mi
max: 8Gi
PropertyValue
Typeobject
RequiredYes
Fieldsmin, max

CPU resource bounds.

PropertyValue
Typeobject
RequiredYes
Fieldsmin, max

Memory resource bounds.

PropertyValue
Typeobject
RequiredYes
Fieldsstrategy, 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 implemented

Example:

spec:
updateStrategy:
strategy: ssa
rolloutStrategy: onNextRestart
useServerSideApply: true
updateRequestsOnly: true
allowUnsafeMemoryDecrease: false
limitConfig:
cpuLimitMultiplier: 1.0
memoryLimitMultiplier: 1.1
# Note: gradualDecreaseConfig not yet implemented
PropertyValue
Typestring
RequiredNo
Valuesssa, webhook
Defaultwebhook

Update strategy type.

PropertyValue
Typestring
RequiredNo
Valuesimmediate, onNextRestart
DefaultonNextRestart

When changes take effect (webhook strategy only).

PropertyValue
Typeboolean
RequiredNo
Defaulttrue

Enable Server-Side Apply for field-level ownership.

PropertyValue
Typeboolean
RequiredNo
Defaulttrue

Update only requests, not limits.

PropertyValue
Typeboolean
RequiredNo
Defaulttrue

Enable in-place pod resize when supported by Kubernetes.

PropertyValue
Typeboolean
RequiredNo
Defaultfalse

Allow pod recreation when in-place resize is not available.

spec.updateStrategy.allowUnsafeMemoryDecrease

Section titled “spec.updateStrategy.allowUnsafeMemoryDecrease”
PropertyValue
Typeboolean
RequiredNo
Defaultfalse

Disable memory safety checks. When false, OptiPod blocks memory decreases that could cause OOM kills.

PropertyValue
Typeobject
RequiredNo
FieldscpuLimitMultiplier, memoryLimitMultiplier

How limits are calculated from requests.

Example:

limitConfig:
cpuLimitMultiplier: 1.0 # Limit = request × 1.0
memoryLimitMultiplier: 1.1 # Limit = request × 1.1

⚠️ Implementation Status: Not yet implemented. Configuration is accepted but has no effect.

PropertyValue
Typeobject
RequiredNo
Fieldsenabled, memoryDecreasePercentage, minimumDecreaseThreshold, maximumTotalDecrease

Gradual memory reduction configuration for safer optimization (planned feature).

Example:

gradualDecreaseConfig:
enabled: true
memoryDecreasePercentage: 10
minimumDecreaseThreshold: 100Mi
maximumTotalDecrease: 70

Current Behavior: Memory decreases are applied immediately in full.

PropertyValue
Typeduration
RequiredNo
Default5m
Format<number><unit> (d=days, h=hours, m=minutes, s=seconds)

How often the policy is evaluated.

Example:

spec:
reconciliationInterval: 5m
PropertyValue
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 workloads
PropertyValue
Typeinteger

Count of workloads matching this policy.

PropertyValue
Typeinteger

Count of workloads successfully processed.

PropertyValue
Typetimestamp
FormatRFC3339

Timestamp of the last reconciliation.

PropertyValue
Typeobject
Fieldsdeployments, statefulSets, daemonSets

Breakdown of workloads by type.

Example:

status:
workloadsByType:
deployments: 3
statefulSets: 2
daemonSets: 0
apiVersion: optipod.optipod.io/v1alpha1
kind: OptimizationPolicy
metadata:
name: production-policy
namespace: production
labels:
environment: production
tier: standard
spec:
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: 0
Terminal window
kubectl apply -f policy.yaml
Terminal window
# All namespaces
kubectl get optimizationpolicy -A
# Specific namespace
kubectl get optimizationpolicy -n production
# With custom columns
kubectl get optimizationpolicy -A \
-o custom-columns=NAMESPACE:.metadata.namespace,NAME:.metadata.name,MODE:.spec.mode,PROVIDER:.spec.metricsConfig.provider
Terminal window
# YAML output
kubectl get optimizationpolicy my-policy -n production -o yaml
# JSON output
kubectl get optimizationpolicy my-policy -n production -o json
# Describe
kubectl describe optimizationpolicy my-policy -n production
Terminal window
# Edit interactively
kubectl edit optimizationpolicy my-policy -n production
# Patch mode
kubectl patch optimizationpolicy my-policy -n production \
--type merge \
-p '{"spec":{"mode":"Auto"}}'
# Patch weight
kubectl patch optimizationpolicy my-policy -n production \
--type merge \
-p '{"spec":{"weight":200}}'
Terminal window
kubectl delete optimizationpolicy my-policy -n production