Avoid overwriting label when re-initialising Deployment object #145
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.
When I run the first example using the latest version on pip (0.4.2), the Nginx test fails with:
Some debugging showed that
_add_kubetest_labels()
is called twice: once by theapplymanifests
decorator, and once duringdeployments.get_deployments()
. This results in the Deployment and Pods having differed UIDs, which causesget_pods()
to return an empty list.This patch fixes the problem by first checking to see if the deployment already has a UID label in its metadata. If so it is retrieved from the Deployment's label, instead of overwritten by a new UID.
There are already some PRs relating to this issue (e.g. #142), but label-based matching seems like a nice solution to the problem and disabling it entirely might lead to unpredictable results in more advanced multi-deployment test cases.
I lack sufficient familiarity with the codebase to know if this is the correct fix, but it is enough to get the example tests working as expected. I only tested deployments but statefulsets/daemonsets share the same code so presumably have the same issue.