Configuration¶
Field Ordering Rules¶
kfix applies Kubernetes-aware field ordering to make manifests more readable and consistent. Fields are ordered according to their importance and common usage patterns.
Top-Level Fields¶
Resource-level fields are ordered:
apiVersion- API version of the resourcekind- Type of Kubernetes resourcemetadata- Resource metadataspec- Resource specificationdata- ConfigMap/Secret datastatus- Resource status (typically read-only)
Example:
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp
spec:
replicas: 3
status:
availableReplicas: 3
Metadata Fields¶
Within metadata, fields are ordered:
name- Resource name (required)namespace- Namespace locationlabels- Label selectorsannotations- Additional metadataOther fields (alphabetically)
Example:
metadata:
name: myapp
namespace: production
labels:
app: myapp
version: v1.0.0
annotations:
description: "My application"
Container Spec Fields¶
Within container specifications, fields are ordered:
name- Container nameimage- Container imageimagePullPolicy- Image pull strategycommand- Entrypoint overrideargs- Arguments to commandworkingDir- Working directoryports- Exposed portsenv- Environment variablesresources- Resource requests/limitsvolumeMounts- Volume mount pointslivenessProbe- Liveness health checkreadinessProbe- Readiness health checkstartupProbe- Startup health checklifecycle- Lifecycle hookssecurityContext- Security settings
Example:
containers:
- name: app
image: myapp:1.0.0
command: ["/app"]
args: ["--config=/etc/app/config.yaml"]
ports:
- containerPort: 8080
env:
- name: LOG_LEVEL
value: info
resources:
limits:
memory: 512Mi
cpu: 500m
requests:
memory: 256Mi
cpu: 250m
volumeMounts:
- name: config
mountPath: /etc/app
livenessProbe:
httpGet:
path: /healthz
port: 8080
Pod Spec Fields¶
Within pod specifications, fields are ordered:
replicas- Number of replicas (for Deployments/StatefulSets)selector- Label selectortemplate- Pod templateserviceName- Service name (for StatefulSets)serviceAccountName- Service accountserviceAccount- Legacy service accountautomountServiceAccountToken- Token mountingnodeSelector- Node selectionaffinity- Pod affinity rulestolerations- Node tolerationsinitContainers- Init containerscontainers- Main containersvolumes- Volume definitionsrestartPolicy- Restart behaviorterminationGracePeriodSeconds- Graceful shutdown time
Example:
spec:
replicas: 3
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
serviceAccountName: myapp
containers:
- name: app
image: myapp:1.0.0
volumes:
- name: config
configMap:
name: myapp-config
restartPolicy: Always
Indentation Settings¶
Default: 2 Spaces¶
kfix uses 2-space indentation by default, which is the Kubernetes standard:
apiVersion: v1
kind: Pod
metadata:
name: myapp
spec:
containers:
- name: app
image: myapp:1.0.0
Custom Indentation¶
Use the --indent flag to customize:
kfix format --indent 4 deployment.yaml
Output with 4 spaces:
apiVersion: v1
kind: Pod
metadata:
name: myapp
spec:
containers:
- name: app
image: myapp:1.0.0
Formatting Behavior¶
What kfix Does¶
✓ Reorders fields according to K8s conventions
✓ Applies consistent indentation
✓ Formats nested structures (containers, volumes, etc.)
✓ Handles multi-document YAML files
✓ Preserves comments (where possible)
✓ Maintains data types (strings, numbers, booleans)
What kfix Does NOT Do¶
✗ Fix malformed YAML syntax
✗ Validate resource schema
✗ Add missing required fields
✗ Modify resource logic or behavior
✗ Convert between API versions
✗ Apply cluster-specific policies
Limitations¶
Valid YAML Required¶
kfix requires syntactically valid YAML. It will reject:
# Invalid indentation
metadata:
name: test
namespace: default # Incorrect indent
# Missing colons
metadata
name: test
# Unclosed quotes
metadata:
name: "test
Kubernetes Resources Only¶
kfix only formats files with apiVersion and kind fields:
# Will be formatted
apiVersion: v1
kind: ConfigMap
data:
key: value
# Will be rejected (no apiVersion/kind)
data:
key: value
Future Configuration¶
Configuration File Support¶
Planned support for .kfix.yaml or .kfix.yml configuration files.
Future configuration options:
Custom field ordering preferences
Field exclusion rules
Resource-type-specific formatting
Indentation per resource type
Comment preservation strategies
Example future config:
# .kfix.yaml
indent: 2
fieldOrder:
container:
- name
- image
- ports
- env
excludeFields:
- status
- managedFields
Stay tuned for updates at: https://github.com/amaanx86/kfix