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?

1 Answer 1


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
  • 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
    Commented Jun 23, 2020 at 9:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.