> For the complete MongoDB documentation index, see www.mongodb.com/docs/llms.txt

<!--
Tab options on this page. Append to the .md URL to filter:
  ?tabs=<id,...>   select specific tabs (e.g. ?tabs=nodejs,shell)
  ?allTabs=true    include every tab
  (no param)       default: one tab per tabset

Available tabs:
  other tabs: kubectl-dry-run, atlas-cli-dry-run
-->

# Atlas Kubernetes Operator Dry Run

Atlas Kubernetes Operator doesn't support Atlas Infinite Database clusters in public preview. To learn which features Atlas Infinite Database supports in public preview, see [Atlas Infinite Database Edition](https://www.mongodb.com/docs/atlas/infinite/atlas-infinite-landing/). To learn more about preview features, see [Preview Features](https://www.mongodb.com/docs/preview-features/).

The Atlas Kubernetes Operator Dry Run feature is in public preview. The feature and the corresponding documentation might change at any time during the Preview period. To learn more, see [Preview Features](https://www.mongodb.com/docs/preview-features/).

With the Atlas Kubernetes Operator Dry Run feature, you can see what Atlas Kubernetes Operator is going to change in Atlas, with those custom resources applied to the K8S cluster. The Atlas Kubernetes Operator emits events for every resource that it is going to create/update/delete in Atlas. Events emitted by the Atlas Kubernetes Operator running in Dry Run mode can be filtered by "Dry Run" reason. This feature is useful for [upgrading your Atlas Operator resources.](https://www.mongodb.com/docs/atlas/operator/current/upgrade-ako-v1-to-v2.md#std-label-upgrade-atlas-operator)

## Prerequisites

In order to use the Atlas Kubernetes Operator Dry Run feature, you need to:

- Have access to a **new Kubernetes or OpenShift cluster**.

- Apply Atlas Kubernetes Operator custom resources to your **new Kubernetes cluster**. When you apply your resources, make sure you provide a [secret with credentials](https://www.mongodb.com/docs/atlas/operator/stable/ak8so-quick-start/#create-a-secret-with-your-api-keys-and-organization-id). You need a new cluster, because upgrading CRDs on your existing Kubernetes cluster might leave Atlas Kubernetes Operator unable to reconcile existing custom resources. Moreover, the CRDs that are applied can be a newer version with potential breaking changes.

  **Note:**

  Only one version of the AKO CRDs can exist in a specific Kubernetes cluster. This means that to test upgrading to a new version of the Atlas Kubernetes Operator, you need to deploy a new Kubernetes cluster (possibly a temporary cluster) to execute the dry run.

- Install CRDs to your cluster for the version of the Atlas Kubernetes Operator you want to execute dry-run for.

- Create a `mongodb-atlas-operator` service account in your Kubernetes cluster.

- Create a [role](https://github.com/mongodb/mongodb-atlas-kubernetes/blob/main/releases/v2.13.0/deploy/openshift/openshift.yaml) and [rolebinding](https://github.com/mongodb/mongodb-atlas-kubernetes/blob/main/config/rbac/clusterwide/role_binding.yaml) for your [service account](https://github.com/mongodb/mongodb-atlas-kubernetes/blob/main/config/rbac/service_account.yaml) with the following permissions related to your Atlas Kubernetes Operator custom resources. You can either create these resources manually or with the [Atlas CLI.](https://www.mongodb.com/docs/atlas/operator/current/ak8so-quick-start.md#std-label-ak8so-quick-start-ref)

  - `list`

  - `get`

  - `create`

  - `update`

  - `delete`

## Dry Run Events

The Dry Run process emits either the following message types, each of which can be either of the type `Normal` or `Warning`:

- `Would [verb] ([HTTP-Method]) [Atlas resource URL]`

  - A description of a given Atlas Kubernetes Operator resource and the Kubernetes required Kubernetes process should the change be applied to your Atlas environment. When in Dry Run mode, Atlas Kubernetes Operator only emits dry-run events for HTTP verbs that would create/update/delete resources in Atlas, such as `POST`, `PATCH`, `PUT`, `DELETE`.

- `Done`

  - No further dry-run events will be reported.

- `Finished`

  - The Kubernetes Job running the dry-run process has completed.

## Procedure

### kubectl

1. Apply the following Kubernetes Job.

   Save the following example in a file called `dry-run-job.yaml` and apply it to your cluster by running `kubectl apply -f dry-run-job.yaml`. This will start Atlas Kubernetes Operator as a Kubernetes Job with the `--dry-run` parameter. Every reconciliation in the Atlas Kubernetes Operator will run only once, emitting events for each resource if there are changes between the resource spec and its state in Atlas.

   You can run this command multiple times without making any changes to your Atlas resources.

   ```yaml
   apiVersion: batch/v1
   kind: Job
   metadata:
     name: ako-dry-run
     namespace: mongodb-atlas-system
   spec:
     backoffLimit: 1
     template:
       spec:
         containers:
           - args:
               - --atlas-domain=https://cloud.mongodb.com/
               - --log-level=info
               - --log-encoder=json
               - --dry-run
             command:
               - /manager
             env:
               - name: OPERATOR_POD_NAME
                 value: ako-dry-run
               - name: OPERATOR_NAMESPACE
                 value: mongodb-atlas-system
               - name: WATCH_NAMESPACE
                 value: mongodb-atlas-system
               - name: JOB_NAME
                 value: ako-dry-run
             image: quay.io/mongodb/mongodb-atlas-kubernetes-operator:2.8.0
             imagePullPolicy: Always
             livenessProbe:
               failureThreshold: 3
               httpGet:
                 path: /healthz
                 port: 8081
                 scheme: HTTP
               initialDelaySeconds: 15
               periodSeconds: 20
               successThreshold: 1
               timeoutSeconds: 1
             name: ako-dry-run
         restartPolicy: Never
         serviceAccountName: mongodb-atlas-operator

   ```

2. List the dry-run output.

   When the Kubernetes Job is finished, you can list the events emitted by running the following command:

   ```bash
   kubectl -n mongodb-atlas-system get events --field-selector reason=DryRun
   ```

   This command will return output similar to the following:

   ```bash
   LAST SEEN   TYPE      REASON   OBJECT                    MESSAGE
   103s        Normal    DryRun   atlasproject/my-project   Would delete (DELETE) /api/atlas/v1.0/groups/6558f184beba40022cbb2043/integrations/SLACK
   101s        Warning   DryRun   atlasproject/my-project   finished dry run
   ```

## Log Resource Diffs

When `--log-level` is set to `debug`, the Atlas Kubernetes Operator provides a detailed diff of the changes that you make to Atlas resources that are managed by the Atlas Kubernetes Operator. This diff is particularly useful when used in conjunction with the Dry Run feature, as it allows you to see the differences between the current state of your Atlas Kubernetes Operator custom resources and the state that the Atlas Kubernetes Operator would apply to your Atlas environment.

This diff feature is informed by comparing the result of any PUT or PATCH requests sent to Atlas with the current state of the Atlas Kubernetes Operator custom resources in your Atlas environment.

**Note:**

To facilitate this comparison, the Atlas Kubernetes Operator makes a GET request to Atlas to learn the current state of resources in Atlas. As such, we recommend that you only set the log level to debug in non-production environments, as this feature can increase the load on Atlas.

To see the differences, you need to set the `--log-level=debug` flag when running the Atlas Kubernetes Operator command. Because the Atlas Kubernetes Operator uses structured logging, we recommend analyzing the JSON diff in a structured logging viewer for better human readability. The following example shows a rendered Atlas Kubernetes Operator `DEBUG` log line in YAML format, as displayed in a structured logging viewer:

```yaml
apiVersion: atlas.mongodb.com/v1
kind: AtlasDeployment
metadata:
  name: test
  namespace: flex
spec:
  flexSpec:
    name: test
    providerSettings:
      backingProviderName: AWS
      regionName: US_EAST_1
    terminationProtectionEnabled: true -> false
  projectRef:
    name: test
```

**Output:**

```text
 1 | diff: |
 2 |    {
 3 |   -  "backupSettings": {
 4 |   -    "enabled": true
 5 |   -  },
 6 |   -  "clusterType": "REPLICASET",
 7 |   -  "connectionStrings": {
 8 |   -    "standard": "...",
 9 |   -    "standardSrv": "..."
10 |   -  },
11 |   -  "createDate": "2025-07-21T09:52:06Z",
12 |   -  "groupId": "687e0db8823af91...",
13 |   -  "id": "687e0dc6426db7026...",
14 |   -  "mongoDBVersion": "8.0.11",
15 |   -  "name": "test",
16 |   -  "providerSettings": {
17 |   -    "backingProviderName": "AWS",
18 |   -    "diskSizeGB": 5,
19 |   -    "providerName": "FLEX",
20 |   -    "regionName": "US_EAST_1"
21 |   -  },
22 |   -  "stateName": "IDLE",
23 |      "tags": [
24 |      ],
25 |   -  "terminationProtectionEnabled": false,
26 |   +  "terminationProtectionEnabled": true,
27 |   -  "versionReleaseSystem": "LTS"
28 |    }
29 | level: DEBUG
30 | msg: JSON diff
31 | time: 2025-07-22T18:07:01.163+0200
32 | url: https://...
```
