Prevent duplicate clusters ending up in Terraform state #264
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.
This PR aims to address the currently flaky invalid cluster tests in a less invasive manner than #263, which requires further thought with regard to the performance implications.
When looking at this in more detail, I identified 3 separate issues that resulted in these tests being flaky.
Upsert
was set tofalse
when callingCreate
on the cluster client. This meant that we can end up in a situation whereby two Terraform resources are managing the same resource in ArgoCD. This leads to perpetual diffs on these resources and also results in errors like the following when the resources in the tests are subsequently destroyed.Create
method. If both resources are created simultaneously, then both can pass the "distinct cluster" checks covered by the RLock, allowing both resources to be created and end up in Terraform state. So, both the Get and Create calls need to be covered by a full RW lock as per the implementation in argocd_repository_certificate.go.