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

fix: clean up logic around config.toml handling #1222

Closed
wants to merge 4 commits into from

Conversation

ralphbean
Copy link
Member

No description provided.

@ralphbean
Copy link
Member Author

echo "Using the ${CONFIG_TOML_FILE} file found in the repository root!"
else
echo "No ${CONFIG_TOML_FILE} file found in the repository. Set params.${CONFIG_TOML_FILE}_FILE to a valid config.toml file."
exit 1
Copy link
Member

Choose a reason for hiding this comment

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

This will make it impossible for the task to run if there is no file regardless as to whether the parameter was specified or not. Is that desired?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think so. Right? Like, what's the behavior of bib if there is literally no config.toml at all?

Copy link
Member

Choose a reason for hiding this comment

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

This is effectively a breaking change. If we want to make it explicit like this then will we have to bump the version?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know if the file is missing, but bib is fine if the file is empty

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not interested in introducing a breaking change. I'm just trying to clean it up.

If bib is happy if the file is empty, I'll drop this part.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK - I revised this to drop the exit 1 and restore the touch line. (Now I understand what that line was for. I assumed bib would balk at an empty config.toml file.)

if [ -f "/var/workdir/source/${CONFIG_TOML_FILE}" ]; then
echo "Using the ${CONFIG_TOML_FILE} file found in the repository root!"
else
echo "No ${CONFIG_TOML_FILE} file found in the repository. Set params.${CONFIG_TOML_FILE}_FILE to a valid config.toml file."
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
echo "No ${CONFIG_TOML_FILE} file found in the repository. Set params.${CONFIG_TOML_FILE}_FILE to a valid config.toml file."
echo "No ${CONFIG_TOML_FILE} file found in the repository. Set params.CONFIG_TOML_FILE to a valid config.toml file."

?

@pastequo
Copy link
Contributor

Maybe the PR title doesn't reflect what you want to achieve, but the CONFIG_TOML_FILE is taken into account (at least in our pipeline it seems ok)

@chmeliik
Copy link
Contributor

chmeliik commented Jul 31, 2024

Maybe the PR title doesn't reflect what you want to achieve, but the CONFIG_TOML_FILE is taken into account (at least in our pipeline it seems ok)

Looking at https://gitlab.com/redhat/rhel-ai/disk-images/nvidia-bootc/-/merge_requests/56, it's not up to date with the current build-definitions main. Maybe the behavior is already fixed?

A very nasty bug in the gitlab version is

if [! -n "${CONFIG_TOML_FILE}" ]; then

This is just a much harder to spot if nonexistent-command (if you're not running ShellCheck, which spots it for you)

#!/bin/bash
set -e

if [! -n "" ]; then
    echo 'true'
else
    echo 'false'
fi
$ bash /tmp/x.bash
/tmp/x.bash: line 4: [!: command not found
false

pastequo and others added 2 commits July 31, 2024 08:29
The logic here was pretty confusing. Trying to straighten it out.
@ralphbean ralphbean changed the title fix: actually use CONFIG_TOML_FILE param if provided fix: clean up logic around config.toml handling Jul 31, 2024
Andrew pointed out in code review that it's too specific to claim that
it is found in the repository root. It could be in a subdir.
else
echo "No ${CONFIG_TOML_FILE} file found. Using an empty configuration."
touch "/var/workdir/source/${CONFIG_TOML_FILE}"
fi
Copy link
Contributor

@chmeliik chmeliik Jul 31, 2024

Choose a reason for hiding this comment

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

With the old version of the task, explicitly passing a non-existent CONFIG_TOML_FILE would result in a failure (intentionally) rather than ignoring the problem and creating an empty config.

IMO that's the saner behavior that one would expect from most tools, but there seems to be a natural pull towards creating the empty config instead (both in your and in Andrew's PRs 😄 )

I'm fine with it either way, the log message should make it clear why e.g. a mis-spelled config file path is being ignored

Copy link
Member

Choose a reason for hiding this comment

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

Aha. Now that you say that, I do remember those iterations two weeks back. I think that the reason that both @ralphbean and myself did that is because it enables cleaner/clearer logic.

Once I tried to allow failures when a nonexistent file is specified, the logic became more confusing.

Copy link
Member

Choose a reason for hiding this comment

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

See the table for intended behavior from the prior PR: #1171 (comment)

Copy link
Contributor

@chmeliik chmeliik Jul 31, 2024

Choose a reason for hiding this comment

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

I wouldn't say it enables cleaner logic, it's just a touch easier to make it clean. Can still be clean and behave nicely though

if [ -z "$CONFIG_TOML_FILE" ]; then
    CONFIG_TOML_FILE=config.toml
    touch "/var/workdir/source/$CONFIG_TOML_FILE"
elif ! [ -f "/var/workdir/source/$CONFIG_TOML_FILE" ]; then
    echo "Config file doesn't exist: $CONFIG_TOML_FILE"
    exit 1
fi

Copy link
Member Author

Choose a reason for hiding this comment

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

I fear I've made a mess. I wasn't aware of the conversations you guys had the other week about this and I assumed this section of code was just carelessly written in the first place during fast-hacking to make vm building work in early June, when in reality you guys had really thought it through. The code was written more recently than I knew!

My real goal here was to get https://gitlab.com/redhat/rhel-ai/disk-images/nvidia-bootc/-/commit/3ab9e272069e9469abc2ace36bf11b63a438f456 to happen - and it did.

I'm inclined to drop this PR without merging it, just to let it exist as you guys defined it in #1171 (comment). WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Member

Choose a reason for hiding this comment

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

@ralphbean , @chmeliik 's suggestion above is similar to what you proposed. It still defines the failure criteria and clearly describes why a failure happens instead of falling back to other processes to fail (i.e. rsync). I think this would still be an improvement.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ack, if we adopt that - we'll need a version bump per this comment, true?

Copy link
Member

Choose a reason for hiding this comment

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

No, If the only failure is a user specifying a file path that does not exist then that is consistent. The breaking change previously is if no file was specified. We would not create an empty file for them.

@ralphbean
Copy link
Member Author

Hey guys, I'm going to drop this. Focusing on other things.

@ralphbean ralphbean closed this Sep 14, 2024
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