Allow edit operation to reuse proxy port of the old proxy #3200
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Prior to this PR, the edit API endpoint would not allow the proxy port to be reused. This was because the run config validation happened before stopping the old instance of the workload, and thus the port appeared to be still in use.
This PR adds some tweaks to the validation logic to allow port reuse for the edit case. It also tweaks the edit endpoint to reuse the previous port of the workload if a proxy port is not specified - this feels like a more natural behaviour than picking a new random port. This implementation also allows a new port to be selected if the caller desires.
There is a potential race condition in this implementation: if a new workload is created between the termination of the previous proxy process and the creation of the new one, it could potentially "steal" the port and cause the edit to fail after validation has completed. I think this is an acceptable risk for now - fixing it will require us to build some kind of locking mechanism for ports.
Fixes: #3182