Skip to content
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

feat(RELEASE-1252): make run-file-updates task idempotent #727

Open
wants to merge 1 commit into
base: development
Choose a base branch
from

Conversation

jinqi7
Copy link
Collaborator

@jinqi7 jinqi7 commented Dec 5, 2024

The PR is to make the task idempotent by ensuring that a new MR isn't
created unnecessarily when one already exists with the same content
in the seed and replacements of paths parameter.
And it added some logic to check the keys in the paths parameter. If the
keys exist but their content does not require any replacement, return
success.

Copy link

openshift-ci bot commented Dec 5, 2024

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@jinqi7 jinqi7 force-pushed the RELEASE-1252 branch 14 times, most recently from 5cc7967 to c315bf0 Compare December 6, 2024 04:30
@jinqi7 jinqi7 marked this pull request as ready for review December 6, 2024 04:52
@jinqi7 jinqi7 requested a review from a team as a code owner December 6, 2024 04:52
@jinqi7
Copy link
Collaborator Author

jinqi7 commented Dec 6, 2024

/retest

@jinqi7 jinqi7 marked this pull request as draft December 6, 2024 06:43
@jinqi7 jinqi7 force-pushed the RELEASE-1252 branch 7 times, most recently from 633faea to 2aa1a0e Compare December 6, 2024 11:11
@jinqi7 jinqi7 force-pushed the RELEASE-1252 branch 6 times, most recently from c92d6fd to 3336302 Compare December 10, 2024 00:47
@jinqi7 jinqi7 marked this pull request as ready for review December 10, 2024 00:47
@jinqi7
Copy link
Collaborator Author

jinqi7 commented Dec 10, 2024

/retest

2 similar comments
@jinqi7
Copy link
Collaborator Author

jinqi7 commented Dec 10, 2024

/retest

@jinqi7
Copy link
Collaborator Author

jinqi7 commented Dec 10, 2024

/retest

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you provide more details in the commit message and PR description? At least some basic description of how it's being made idempotent.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

fi

openMRList=$(glab mr list -R "${UPSTREAM_REPO}" --search "Konflux release" |grep "^!"| cut -f1 | tr -d '!')
for mrNum in ${openMRList} ; do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me this whole logic is only for the use case that there is replacement to be done, but maybe one of the open MRs already contains it. That's definitely a valid use case.

But what if the change has already been merged? Then we will probably fail on line 235, saying there is nothing to change, right? But if you run the same release repeatedly, that use case shouldn't fail.

Now the question is how to handle this - we will need to separate these two cases:

  • there is substitution to be done because the files already contain the new strings -> pass
  • there is substitution to be done for some other reason, e.g. we didn't find the lines to be updated -> fail

Copy link
Collaborator Author

@jinqi7 jinqi7 Dec 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But what if the change has already been merged? Then we will probably fail on line 235, saying there is nothing to change, right? But if you run the same release repeatedly, that use case shouldn't fail.

How to differentiate the MR is merged and the file doesn't need to be changed at all? Do we still need to check the merged PRs?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might need to discuss this with the whole team to decide how to handle this. Originally when this was implemented, the idea was that if there is nothing to be updated, then there's definitely something wrong. But now that we want to take a release pipeline rerun into account, we shouldn't automatically fail on this. We will need to be more granular. If we can find the file to update and then we search for the line to update and find it, but the line already contains the target string, then that's still ok. We only fail if we cannot find the file to update or cannot match the line to update.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need to check the merged PRs?

I guess that would be one way to handle it. But probably not necessary. It would be difficult to decide how far into the history we want to go.

Copy link
Collaborator

@johnbieren johnbieren Dec 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, if the "goal string" aka the string you are trying to insert already exists in the proper file, exit 0. No need to check merged MRs. If an MR is open with the exact change already, say that (idempotent) and exit 0 (ideally printing the existing MR url). If the file to be changed doesn't exist, exit 1. I think this is in agreement with what Martin has been commenting

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But yes, the case where the change is already merged seems already addressed. It just has to be updated to no longer fail (the line 235 piece Martin mentioned)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If only the return value is changed from "Failed" to "Success" in the block of "line 235", the test case of "test-process-file-updates-replacements-error.yaml" fails. I added a variable of "keyNotFound" to check if the key is correct. And if the file is not valid, it's handled in line 157. Is that ok?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am reading through what the script does and I am not sure now. Until now, if a key is not found, that replacement will be skipped, but at the end we check that at least one replacement happened, otherwise we fail.

So yes, I think what you say sounds correct - we should fail if we cannot find the target file or the target key. But if those are found and there is no diff once the replacement is applied, it's still ok.

But I noticed there is also this seed option. It seems that one should be ok - if you run it again, it will just override the file with the seed string again, so there will be no diff. Previously this would fail on "no diff", but as we said, we will no longer fail on "no diff".

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Until now, if a key is not found, that replacement will be skipped, but at the end we check that at least one replacement happened, otherwise we fail.

I didn't change the logic of seed/replacement before, just add/set the "keyNotFound" variable. If there is no replacement and all the keys can be found, it return true because the MR may be merged. If some key can't be found, it fails.


if [[ -s "${TEMP}"/tempMRFile.diff ]]; then
# replacements exist
awk '/^@@/ {match($0, /@@ ([^@]+) @@/, arr); print arr[1]}' "${TEMP}"/tempMRFile.diff |\
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this do? Can you add a comment explaining what it will print?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's to deal with a line like "@@ -4,7 +4,7 @@ $schema: /app-interface/app-interface-settings-1.yml". Usually it should be "@@ -4,7 +4,7 @@" in a line and " $schema: /app-interface/app-interface-settings-1.yml" in a seperated line.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't get it 😂 but can you make that comment in the code? This will be lost once this is merged

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Added a comment.

@jinqi7 jinqi7 force-pushed the RELEASE-1252 branch 5 times, most recently from 2327d8a to 5904751 Compare December 11, 2024 12:45

if [[ ! -s "${TEMP}"/lineFile ]]; then
# only seed files
foundMR=false
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed since it is set on line 264?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed. Thanks

@jinqi7 jinqi7 force-pushed the RELEASE-1252 branch 2 times, most recently from 7feb933 to 1cb83b1 Compare December 13, 2024 04:10
@jinqi7 jinqi7 marked this pull request as draft December 13, 2024 04:51
@jinqi7 jinqi7 marked this pull request as ready for review December 13, 2024 04:58
Signed-off-by: Jing Qi <[email protected]>

The PR is to make the task idempotent by ensuring that a new MR isn't
 created unnecessarily when one already exists with the same content
in the seed and replacements of paths parameter.
And it added some logic to check the keys in the paths parameter. If the
 keys exist but their content does not require any replacement, return
 success.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants