Updating a file in place
The Deployment terminated the old Pods and created two new Pods that comply with the updated Deployment spec. This is not always what happens when you use a strategic merge patch on a list. With a strategic merge patch, a list is either replaced or merged depending on its patch strategy.
Then, read the next five bytes in the file and store them in the buffer (this is why I recommend two buffers, so you can just swap references as opposed to having to copy all the bytes around in a single buffer).
Other commands for updating API objects include kubectl annotate, kubectl edit, kubectl replace, kubectl scale, and kubectl apply. If you have a specific, answerable question about how to use Kubernetes, ask it on Stack Overflow.
Open an issue in the Git Hub repo if you want to report a problem or suggest an improvement.
You cannot safely write to a file you are also reading, as any changes you make to the file could overwrite content you have not read yet.
To do it safely you'd have to read the file into a buffer, updating any lines as required, and then re-write the file.David, You can't just update a few lines in the middle of a file.