<p>Not sure why this is required since Kubernetes is declarative and will not do anything is nothing has changed. Nonetheless, you can run it with the <code>--server-dry-run=true</code> flag. What attributes are going to be changed in the resource will not be mentioned but it does mention which resource(s) will be changed in the apply. You will need to parse the output message to identify if something changed or not since the exit code is always 1.
Sample outputs:</p>
<pre><code>$ kubectl apply --server-dry-run=true -f ./configmap.yaml # First run
secret/my-conf created
$ kubectl apply --server-dry-run=true -f ./configmap.yaml # Re-run without modifications
secret/my-conf unchanged
$ kubectl apply --server-dry-run=true -f ./configmap.yaml # Re-run with modifications
secret/my-conf configured
</code></pre>

CC BY-SA 4.0
2020-06-23T09:10:04.237Z
Thanks. This is for automation, where  i need this feedback for further action (either applied if something has changed, or not if nothing has changed)
Mandragor
CC BY-SA 4.0
2020-06-23T08:49:22.717Z
2020-06-23T08:49:22.717Z
Mikhail Advani
<p>How can I check if an operator has not changed, and then not apply it?</p>

<p>usually, I would apply an operator like this</p>

<pre><code>kubectl apply -f openebs.yml    
</code></pre>

<p>In an automated script, I would like to test if Kubernetes is running this operator already - and only apply it if it has changed or even stop if there are changes.</p>

<p>How can I achieve this?</p>

<kubernetes><kubectl>
kubernetes How to test if an operator has already been applied
Mandragor
# kubernetes How to test if an operator has already been applied

(Asked by: username_0 on 2019-09-07)

How can I check if an operator has not changed, and then not apply it?
usually, I would apply an operator like this
kubectl apply -f openebs.yml    

In an automated script, I would like to test if Kubernetes is running this operator already - and only apply it if it has changed or even stop if there are changes.
How can I achieve this?

**Tags:** kubernetes, kubectl


---

## 1 answers

### Answer by username_1 on 2020-06-23. Score: 1 | Accepted answer

Not sure why this is required since Kubernetes is declarative and will not do anything is nothing has changed. Nonetheless, you can run it with the --server-dry-run=true flag. What attributes are going to be changed in the resource will not be mentioned but it does mention which resource(s) will be changed in the apply. You will need to parse the output message to identify if something changed or not since the exit code is always 1.
Sample outputs:
$ kubectl apply --server-dry-run=true -f ./configmap.yaml # First run
secret/my-conf created
$ kubectl apply --server-dry-run=true -f ./configmap.yaml # Re-run without modifications
secret/my-conf unchanged
$ kubectl apply --server-dry-run=true -f ./configmap.yaml # Re-run with modifications
secret/my-conf configured

> **Comments:**
> **username_0**: Thanks. This is for automation, where  i need this feedback for further action (either applied if something has changed, or not if nothing has changed)  

---

