stakater / Reloader

A Kubernetes controller to watch changes in ConfigMap and Secrets and do rolling upgrades on Pods with their associated Deployment, StatefulSet, DaemonSet and DeploymentConfig – [✩Star] if you're using it!
https://docs.stakater.com/reloader/
Apache License 2.0
7.66k stars 511 forks source link

reload-on-create trigger rollingupdate of all deployments if Reloader pod restart #299

Open llavaud opened 2 years ago

llavaud commented 2 years ago

If I start Reloader with the "--reload-on-create=true" argument, everytime reloader pod is restarted it triggers a rolling update of all deployment that are "managed" by Reloader.

Example of Reloader logs after a restart:

time="2022-03-25T14:24:19Z" level=info msg="Environment: Kubernetes"
time="2022-03-25T14:24:19Z" level=info msg="Starting Reloader"
time="2022-03-25T14:24:19Z" level=warning msg="KUBERNETES_NAMESPACE is unset, will detect changes in all namespaces."
time="2022-03-25T14:24:19Z" level=info msg="Starting Controller to watch resource type: secrets"
time="2022-03-25T14:24:19Z" level=info msg="Starting Controller to watch resource type: configMaps"
time="2022-03-25T14:24:20Z" level=info msg="Changes detected in 'nginx' of type 'CONFIGMAP' in namespace 'default'"
time="2022-03-25T14:24:20Z" level=info msg="Updated 'nginx-auto' of type 'Deployment' in namespace 'default'"
time="2022-03-25T14:24:20Z" level=info msg="Changes detected in 'nginx' of type 'CONFIGMAP' in namespace 'default'"
time="2022-03-25T14:24:20Z" level=info msg="Updated 'nginx-search' of type 'Deployment' in namespace 'default'"

I don't think it is an expected behaviour.

faizanahmad055 commented 2 years ago

This is a known issue, this tool has been designed to reload based on any change. The ability to reload based on new resource (secret/configmap) addition is optional and limited. The Kubernetes API return all the resources as new resources at the start and there isn't a way to check which resource was created with different content. So that's why the issue happens. We welcome any suggestions and also accept the contributions via PRs in case you have ideas for how to fix this :)

llavaud commented 2 years ago

It is not possible to trigger rolling update on create/update events that occurs only after the Reloader's pod has started ?

klausenbusk commented 1 year ago

We welcome any suggestions and also accept the contributions via PRs in case you have ideas for how to fix this :)

Assuming --reload-strategy=annotations, shouldn't it be possible to compare the new hash against the hash in the reloader.stakater.com/last-reloaded-from annotation, and only trigger a rolling update if they differ?

mukesh-mohanan-db commented 1 year ago

@faizanahmad055 is it still the case or could you please tell me any plan to implement this in new releases ?

faizanahmad055 commented 1 year ago

This should be fixed now. When reloader restarts it no longer automatically restarts the pods it is watching.