Drift
Find changes made in the cluster outside git, and decide whether to revert them, adopt them into git, or ignore the field for good.
Drift is a difference between what Wardn applied and what the cluster now runs: someone ran kubectl edit, a script patched a Deployment, an object was deleted by hand. Left alone, drift means the cluster no longer matches what git and your reviews say, and the next apply may quietly undo the change or fight it. Wardn shows drift, does not change the cluster because of it unless you ask, and gives you three answers. What counts as drift, and what does not, is explained in Drift.
You need deployment:read to see drift. Each answer has its own permission, listed at the end.
How drift is found
After each apply and on a schedule, the operator compares the live objects with the snapshot it last applied, using a server-side dry run of the same apply, and reports the result. A difference is confirmed with a second look a couple of seconds later, so a controller writing at that instant does not show up as drift.
Only fields Wardn owns count. That is why the report can be trusted:
- A field another controller owns, such as the replica count an autoscaler sets, is not drift, and Wardn does not fight it when it applies.
- Defaults the API server adds, quantities it normalises (
1000mstored as1), a sidecar a webhook injects, status that a controller writes, and labels or annotations added by other tools are not drift. - A Secret's values are masked in the report.
- An object missing from the cluster is drift, reported as added: it is in the snapshot and not running.
Drift is reported for every deployment, including one set to Observe only. A report about a snapshot that has since been replaced is dropped; the next report is about the right one.
Wardn does not report spec.replicas as drift on a Deployment or StatefulSet that a HorizontalPodAutoscaler in the namespace targets, or that carries the label drift.wardn.dev/hpa-managed: "true". Leave replicas out of the manifest, because an apply writes the manifest's value back. For any other field an autoscaler or controller owns, add an ignore rule. See Ignore autoscaler fields.
Where to look
- A deployment's Overview shows Drift with a count.
- The deployment's Drift tab lists What drifted: each object (kind and name), its app, and each field with the value the snapshot sets and the value the cluster has. "The cluster matches the snapshot the deployment runs" means none.
- The Live diff tab shows the same data as a diff of whole objects. See Compare snapshots.
- The API:
api() { curl -fsS -H "Authorization: Bearer $WARDN_TOKEN" -H 'Content-Type: application/json' "$@"; }
api "$WARDN_API_URL/api/v1/deployments/$DEPLOYMENT_ID/drift" # objects and fields that drifted, per cluster
api "$WARDN_API_URL/api/v1/deployments/$DEPLOYMENT_ID/live-diff" # live value (from) against the snapshot's value (to)An empty list means no drift. For a deployment on an environment the answer has an entry per cluster, and each action acts on the clusters that drifted.
Choose what to do
On the Drift tab, each drifted object has a row of choices under Your choice: Adopt, Revert or Ignore field. A choice you lack the permission for is disabled, with the permission named ("Needs the drift:revert permission"). Pick one per object and apply them together; Wardn asks you to confirm ("Apply your choices?") and then says how many were adopted, reverted and ignored. Revert all reverts every drifted object, after a confirmation.
Revert
Revert puts the cluster back to what the snapshot says. Wardn queues the running snapshot to be applied again, and server-side apply changes only what differs. A missing object can only be reverted: there is nothing to adopt or ignore.
api -X POST "$WARDN_API_URL/api/v1/deployments/$DEPLOYMENT_ID/drift/revert" -d '{}' # everything that drifted
api -X POST "$WARDN_API_URL/api/v1/deployments/$DEPLOYMENT_ID/drift/revert" \
-d '{"objects": [{"group": "apps", "version": "v1", "kind": "Deployment", "namespace": "shop", "name": "web"}]}'The objects you name must be drifted. The apply covers the whole snapshot, not only those objects, so a revert works on whole objects and any other drift is reverted with it. Needs drift:revert.
Adopt
Adopt is for when the cluster is right and git is wrong, for example an emergency kubectl scale that should have been a commit. Wardn records a pending change: the exact RFC 6902 JSON patch that turns the object in the snapshot into what the cluster runs. The tab shows it as a Patch.
api -X POST "$WARDN_API_URL/api/v1/deployments/$DEPLOYMENT_ID/drift/adopt" \
-d '{"object": {"group": "apps", "version": "v1", "kind": "Deployment", "namespace": "shop", "name": "web"}}'Add pointers to adopt only some fields of the object, and clusterId when the deployment drifts on more than one cluster.
Wardn does not push the patch to git for you. Take it to the repository yourself, then record the outcome under Adoptions: Mark merged once it is in git, or dismiss it if it will not be (PUT .../drift/adoptions/{id}). Only a pending adoption can be decided. Secrets cannot be adopted, because their values are masked.
Needs drift:adopt. GET .../drift/adoptions lists them. Once the change is in git, the next snapshot contains it and the drift clears on its own.
Ignore
Ignore field is a standing rule: for one object and one JSON pointer in it (for example /spec/replicas), including everything below the pointer, drift is not reported.
api -X POST "$WARDN_API_URL/api/v1/deployments/$DEPLOYMENT_ID/drift/ignores" -d '{
"object": {"group": "apps", "version": "v1", "kind": "Deployment", "namespace": "shop", "name": "web"},
"pointer": "/spec/replicas",
"reason": "managed by the autoscaler"
}'
api -X DELETE "$WARDN_API_URL/api/v1/deployments/$DEPLOYMENT_ID/drift/ignores/$RULE_ID"The drift already on record is filtered at once, and the rule goes to the operator with the next apply. The rule is listed under Ignored fields, where deleting it turns reporting back on. Needs drift:ignore; GET .../drift/ignores lists the rules.
Let Wardn revert drift
By default a deployment only detects drift. A deployment's Settings tab has a Drift section with When it drifts:
| Choice | Meaning |
|---|---|
| Detect only | Record and show drift. The default. |
| Revert after | Revert what still differs after 15 minutes, 1 hour, 4 hours or 1 day, counted from when the drift was found. Drift that clears first is let go. |
| Revert at once | Revert as soon as drift is found. |
In the API these are the drift field of the deployment's settings (PUT /deployments/{id}/settings, deployment:manage): mode is detect, revert_after or revert, and revertAfterSeconds is 60 to 86400 and only for revert_after. See Deployment settings.
An automatic revert is the same action as a manual one, run as the system, and is recorded in Activity as deployment.drift_auto_revert. A deployment set to Observe only only detects, whatever the policy. Choose a delay when people sometimes patch production on purpose during an incident: it leaves time to adopt or ignore the change before it is reverted.
Where it shows up
Drift appearing and clearing are recorded as deployment.drift_detected and deployment.drift_cleared, and your choices as drift.adopt, drift.adoption_merged, drift.adoption_dismissed, drift.revert, drift.ignore and drift.ignore_removed. Open Activity and filter by deployment; see Timelines and Activity. The churn that surrounds drift, such as pods restarting or nodes coming and going, belongs to the cluster's and the deployment's timelines instead.
Drift also appears in the deployment's Snapshots history as an event ("changed outside Wardn", with Review drift). It is a history event, not a snapshot, and it cannot be promoted until it is adopted.
Permissions
| Action | Permission |
|---|---|
| See drift, adoptions and ignore rules | deployment:read |
| Revert | drift:revert |
| Adopt, and mark an adoption merged or dismissed | drift:adopt |
| Add or remove an ignore rule | drift:ignore |
| Change the drift policy | deployment:manage |
The owners of a deployment, cluster, environment or app hold all three drift permissions.
Next
Restore and rollback
Go back to an earlier snapshot when reverting drift is not enough.
Compare snapshots
See drift as a diff against the running or the next snapshot.
Deployment settings
Where the drift policy and observe-only live.
Related: Drift concept, Health.
Compare snapshots
See exactly what changed between two snapshots, and what differs between a snapshot and the live cluster, before and after you promote or restore.
Restore and rollback
Go back to an earlier snapshot, with a preflight that checks images, secrets and the target first, and an automatic rollback when a job fails.