Skip to content

Conversation

@zerospiel
Copy link
Contributor

Escapes ampersand (&) symbol in the entrypoint.sh for the k0s, to avoid incorrect substitutions in case kine data source url has two or more options to connect.

Fixes #1299

@zerospiel zerospiel requested a review from a team as a code owner November 20, 2025 11:47
# Substitute the kine datasource URL from the env var
sed -i "s {{ .KineDataSourceURLPlaceholder }} ${K0SMOTRON_KINE_DATASOURCE_URL} g" /etc/k0s/k0s.yaml
sed -i "s {{ .KineDataSourceURLPlaceholder }} ${K0SMOTRON_KINE_DATASOURCE_URL//&/\\&} g" /etc/k0s/k0s.yaml
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like it's not supported by posix shell, only in bash, that's why it fails on CI. We can switch it to

ESCAPED_K0SMOTRON_KINE_DATASOURCE_URL="$(printf '%s' "$K0SMOTRON_KINE_DATASOURCE_URL" | sed 's/&/\\&/g')"
sed -i "s {{ .KineDataSourceURLPlaceholder }} ${ESCAPED_K0SMOTRON_KINE_DATASOURCE_URL} g" /etc/k0s/k0s.yaml

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That one is correct, though the CI found the problem with POSIX-incompatible line, I am now trying to do this with an extra line

The comment is outdated, yes, the probllem is with POSIX

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, seems the unit tests finally work 🎉

# Substitute the kine datasource URL from the env var
sed -i "s {{ .KineDataSourceURLPlaceholder }} ${K0SMOTRON_KINE_DATASOURCE_URL} g" /etc/k0s/k0s.yaml
escaped_url=$(printf '%s' "$K0SMOTRON_KINE_DATASOURCE_URL" | sed 's/[&/\]/\\&/g')
sed -i "s|{{ .KineDataSourceURLPlaceholder }}|$escaped_url|g" /etc/k0s/k0s.yaml
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we switch the separator? I think | unlike space might be in the password.

Copy link
Contributor Author

@zerospiel zerospiel Nov 20, 2025

Choose a reason for hiding this comment

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

Initially it was a bit hard to debug the problem, so I decided to put it there. If spaces are okay in this context, let me revert it

Upd. Reverted

Escapes ampersand (&) symbol in the entrypoint.sh for the k0s, to avoid
incorrect substitutions in case kine data source url has two or more
options to connect.

Fixes k0sproject#1299

Signed-off-by: Michael Morgen <[email protected]>
@makhov makhov merged commit fcc82d2 into k0sproject:main Nov 20, 2025
101 of 102 checks passed
@zerospiel zerospiel deleted the fix_kos_sed branch November 21, 2025 10:26
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.

Incorrect sed leads to corrupted kine data source

2 participants