Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions scripts/felix-config-update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/bin/bash

set -eu -o pipefail

# Load versions
VERSIONS=($(jq -r '.[]' calico_versions.json))

# Get updates from master branch

update_felix_config() {
#This function prints the target and source locations and
#copies the source file to the target file.

TMPFILE=$(mktemp /tmp/remote-url-output.XXXXXX)
trap 'rm -f "$TMPFILE"' EXIT

printf "%s\n\n" "Begin processing $VERSION"
printf "%s\n" "Target path: $LOCAL_PATH"
printf "%s\n" "Source URL: $REMOTE_URL"

curl -fsSL -o "$TMPFILE" "$REMOTE_URL"

if jq -e . "$TMPFILE" >/dev/null 2>&1; then
echo "Success: $TMPFILE is valid JSON."
else
echo "Error: $TMPFILE contains invalid JSON."
exit 1
fi

curl -fsSL -o "$LOCAL_PATH" "$REMOTE_URL"
printf "%s\n\n\n" "Finished processing $VERSION."
}

update_master () {
# This function updates the configuration from the master branch.
VERSION="master"
LOCAL_PATH="calico/_includes/components/FelixConfig/config-params.json"
REMOTE_URL="https://raw.githubusercontent.com/projectcalico/calico/refs/heads/master/felix/docs/config-params.json"
update_felix_config
}

update_versions() {
# This function updates the configurations from the versioned branches.
for i in "${!VERSIONS[@]}"; do
VERSION="${VERSIONS[$i]}"
LOCAL_PATH="calico_versioned_docs/version-${VERSION}/_includes/components/FelixConfig/config-params.json"
REMOTE_URL="https://raw.githubusercontent.com/projectcalico/calico/refs/heads/release-v${VERSION}/felix/docs/config-params.json"

# Exclude version 3.29, which came before direct-from-source method.
if [ "$VERSION" == "3.29" ]; then
printf "%s\n" "Skipping $VERSION: No action required."
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can use echo "blah blah" instead of printf "%s\n" "blah blah" unless you're doing more complex variable printing (like trying to print values as hex or formatting a number in a specific way). Tends to be more readable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I got to that after having trouble with newlines. I think I'll leave it for now, but I take the point that it's cleaner with a plain echo statement.

continue
fi

update_felix_config

done
}

update_master
update_versions

printf "%s\n" "All updates are complete."

exit 0