-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: add unique hash to cloned source to avoid conflict #1136
Conversation
Issue ----- When more than one Terraform resource points to the same git repository, when we clone the Source object, it does not create a new cloned Source object as the PullRequest ID is the same, the source name is the same, and we use only these two values to generate the name of the cloned resource. Solution -------- Add a short and deterministic hash to the name of the cloned Source object. Another thoughts ---------------- It's not necessary to get a deterministic unique string, it could be random as we save the result as SourceRef. I decided to use a short (first 10 bytes of a sha256 hash), because if in the future we have to regenerate the values somehow, then we don't have to care about migration, extra compatibility checks. I know it's not likely we need this, but generating a random number - doesn't yield shorter code. - still doesn't guarantee it will not generate a conflicting name, and knowing computers, I think it's even more likely (still unlikely) to generate the same random value if the two generation happens (nearly) at the same time. Additional changes ------------------ - Removed the hardcoded index-magic from poll_test. For some reasons it was not always in order. I don't know what changed tho. Notes ---- Compatibility: I was thinking about what happens with old resources, but after I spent some time on it, my conclusion is "they are not affected". We don't calculate names when we look up source objects for terraform objects. Their name is already saved as SourceRef. We generate this game only on newly created resources, therefore it does not break anything already in place. Fixes #923 References: - #923 Signed-off-by: Balazs Nadasdi <[email protected]>
Currently testing this. I have 1 source being referenced by 2 TF resources. Making a change to the TF code in a PR, results in 2 planned TF resources (one for each TF resource) and 2 new sources:
|
internal/server/polling/poll_test.go
Outdated
for idx, item := range tfList.Items[1:] { | ||
expectToEqual(t, g, item.Name, fmt.Sprintf("%s-pr-%d", original.Name, idx+1)) | ||
expectToEqual(t, g, item.Spec.SourceRef.Name, fmt.Sprintf("%s-source-pr-%d", original.Name, idx+1)) | ||
for _, item := range tfList.Items[1:] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this start from 0 or rather iterate through the whole slice? Since we skip the item with the same name below.
Signed-off-by: Balazs Nadasdi <[email protected]>
Issue
When more than one Terraform resource points to the same git repository, when we clone the Source object, it does not create a new cloned Source object as the PullRequest ID is the same, the source name is the same, and we use only these two values to generate the name of the cloned resource.
Solution
Add a short and deterministic hash to the name of the cloned Source object.
Another thoughts
It's not necessary to get a deterministic unique string, it could be random as we save the result as SourceRef. I decided to use a short (first 10 bytes of a sha256 hash), because if in the future we have to regenerate the values somehow, then we don't have to care about migration, extra compatibility checks. I know it's not likely we need this, but generating a random number
Additional changes
Notes
Compatibility:
I was thinking about what happens with old resources, but after I spent some time on it, my conclusion is "they are not affected". We don't calculate names when we look up source objects for terraform objects. Their name is already saved as SourceRef. We generate this game only on newly created resources, therefore it does not break anything already in place.
Fixes #923
References: