How could I differ oldDeployment and newDeployment is the equal #2515
-
Suppose I have a controller, which used to control the deployment, such as the following yaml file.
The above yaml file will create a deployment, named myDeploymentCrontroller-sample and with port: 80, image: nginx:alpine (let's call this version1) After myDeploymentCrontroller created the deployment, somebody modify the deployment with the cmd: kubectl edit deploy myDeploymentCrontroller-sample (let's call this version2) My question is how could I distinguish version2 and version1 is equal with myDeploymentCrontroller code, so that I can decide whether to call r.Client.Update() method to update the deployment. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi,
In summary, you don't have to compare version1 and version2 manually. The reconciliation loop will ensure your resources' desired state is achieved. Just focus on the desired state, and let Kubernetes handle the rest! I would either suggest you read the content of the PR https://github.com/kubernetes-sigs/kubebuilder/pull/3596/files I think it will make more clear how the things work. I hope that answer your question. |
Beta Was this translation helpful? Give feedback.
Hi,
Reconciliation Triggers: When you use the Kubebuilder/controller-runtime framework to watch a resource, any change to that resource will trigger the reconciliation loop for the controller. This means if somebody modifies the Deployment using
kubectl edit
, your controller will automatically be notified and the reconciliation will start.Avoiding Diffing: Generally, controllers shouldn't worry about diffing the old and new versions of resources. The main idea behind Kubernetes controllers is to ensure the current state of the resource matches the desired state. So, your controller should always a…