Skip to content

Commit

Permalink
Refactors script to manage all instances of Gatewayb API version
Browse files Browse the repository at this point in the history
Signed-off-by: Daneyon Hansen <daneyon.hansen@solo.io>
  • Loading branch information
danehans committed Dec 9, 2024
1 parent 7bbf6fa commit ca3135c
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 13 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ generated-code: go-generate-all generate-cli-docs getter-check mod-tidy
generated-code: verify-enterprise-protos generate-helm-files update-licenses
generated-code: generate-crd-reference-docs
generated-code: fmt
generated-code: sync-gateway-api # Sync Gateway API version with the provided $CONFORMANCE_VERSION

.PHONY: go-generate-all
go-generate-all: clean-vendor-any ## Run all go generate directives in the repo, including codegen for protos, mockgen, and more
Expand Down Expand Up @@ -1259,8 +1260,8 @@ conformance-%: $(TEST_ASSET_DIR)/conformance/conformance_test.go

.PHONY: sync-gateway-crds

sync-gateway-crds: ## Syncronize Gateway API CRDs in the repo with the CI configuration
@./ci/sync-gateway-crds.sh
sync-gateway-api: ## Syncronize the Gateway API version used by the repo with the provided $CONFORMANCE_VERSION.
@./ci/sync-gateway-api.sh

#----------------------------------------------------------------------------------
# Security Scan
Expand Down
6 changes: 6 additions & 0 deletions changelog/v1.19.0-beta2/issue_10445.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
changelog:
- type: FIX
issueLink: https://github.com/solo-io/gloo/issues/10445
resolvesIssue: true
description: >-
Adds the `sync-gateway-api` Make target for managing Gateway API version dependencies.
95 changes: 84 additions & 11 deletions ci/sync-gateway-crds.sh → ci/sync-gateway-api.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,53 @@

set -euo pipefail

# File containing CONFORMANCE_VERSION and CONFORMANCE_CHANNEL
SETUP_KIND_FILE="./ci/kind/setup-kind.sh"

# Function to source specific variables from the setup-kind.sh script
source_specific_vars() {
local file="./ci/kind/setup-kind.sh"
local vars_to_source=("CONFORMANCE_VERSION" "CONFORMANCE_CHANNEL")

for var in "${vars_to_source[@]}"; do
eval $(grep "^$var=" "$file")
eval $(grep "^$var=" "$SETUP_KIND_FILE")
done
}

# Function to update the CONFORMANCE_VERSION variable in setup-kind.sh
update_conformance_version_in_setup_kind() {
local key="CONFORMANCE_VERSION"
local value="$1"

if grep -q "^${key}=" "$SETUP_KIND_FILE"; then
current_value=$(grep "^${key}=" "$SETUP_KIND_FILE" | sed -E 's/^.*:-([^}]+)}/\1/')
if [ "$current_value" != "$value" ]; then
echo "Updating $key in $SETUP_KIND_FILE from \"${current_value}\" to \"${value}\"..."
sed -i.bak "s|^\(${key}=\"\${${key}:-\)[^\}]*\(}\"\)|\1${value}\2|" "$SETUP_KIND_FILE"
rm "$SETUP_KIND_FILE.bak"
echo "Updated $key to \"${value}\"."
else
echo "$key is already set to \"${value}\"."
fi
else
echo "$key not found in $SETUP_KIND_FILE. Adding it..."
echo "${key}=\"\${${key}:-${value}}\"" >> "$SETUP_KIND_FILE"
echo "Added $key with value \"${value}\"."
fi
}

# Source the required variables
source_specific_vars

# Update CONFORMANCE_VERSION in ./ci/kind/setup-kind.sh if needed
update_conformance_version_in_setup_kind "$CONFORMANCE_VERSION"

# Capitalize the first letter of CONFORMANCE_CHANNEL
CAPITALIZED_CHANNEL="$(echo "${CONFORMANCE_CHANNEL:0:1}" | tr '[:lower:]' '[:upper:]')${CONFORMANCE_CHANNEL:1}"

# Define output directory and filenames
OUT_DIR="${OUT_DIR:-projects/gateway2/crds}"
OUT_FILENAME="${OUT_FILENAME:-gateway-crds.yaml}"
TCPROUTE_FILENAME="tcproute-crd.yaml"
TCPROUTE_FILENAME="${TCPROUTE_FILENAME:-"tcproute-crd.yaml"}"

# Create the output directory if it doesn't exist
mkdir -p "${OUT_DIR}"
Expand Down Expand Up @@ -90,11 +117,11 @@ download_tcproute_crd() {
echo "Downloading TCPRoute CRD from $url to $dest..."
curl -sLo "$dest.tmp" "$url"

if [ -f "$dest" ]; then
# Prepend header to the temporary file
echo "$HEADER" > "$dest.tmp.full"
cat "$dest.tmp" >> "$dest.tmp.full"
# Always create the temporary file with the header
echo "$HEADER" > "$dest.tmp.full"
cat "$dest.tmp" >> "$dest.tmp.full"

if [ -f "$dest" ]; then
# Compare files ignoring the header
if compare_files_no_header "$dest" "$dest.tmp.full"; then
echo "No changes detected in $dest."
Expand All @@ -104,16 +131,62 @@ download_tcproute_crd() {
fi

# Update the file with the new content and header
echo "$HEADER" > "$dest"
cat "$dest.tmp" >> "$dest"
rm "$dest.tmp" "$dest.tmp.full"
mv "$dest.tmp.full" "$dest"
rm "$dest.tmp"
echo "Updated $dest."
}

# Update sigs.k8s.io/gateway-api in go.mod
update_go_mod() {
local module="sigs.k8s.io/gateway-api"
if grep -q "$module" go.mod; then
current_version=$(grep "$module" go.mod | awk '{print $2}')
if [ "$current_version" != "$CONFORMANCE_VERSION" ]; then
echo "Updating $module from $current_version to $CONFORMANCE_VERSION..."
go get "$module@$CONFORMANCE_VERSION"
go mod tidy
echo "Updated $module to $CONFORMANCE_VERSION."
else
echo "$module is already at version $CONFORMANCE_VERSION."
fi
else
echo "$module not found in go.mod."
fi
}

# Update k8sgateway_api_version in nightly-tests/max_versions.env
update_max_versions_env() {
local env_file=".github/workflows/.env/nightly-tests/max_versions.env"
local key="k8sgateway_api_version="
if [ -f "$env_file" ]; then
if grep -q "$key" "$env_file"; then
current_version=$(grep "$key" "$env_file" | cut -d '=' -f 2 | tr -d "'")
if [ "$current_version" != "$CONFORMANCE_VERSION" ]; then
echo "Updating $key in $env_file from '$current_version' to '$CONFORMANCE_VERSION'..."
sed -i.bak "s|^$key.*|$key'$CONFORMANCE_VERSION'|" "$env_file"
rm "$env_file.bak"
echo "Updated $key to '$CONFORMANCE_VERSION'."
else
echo "$key is already set to '$CONFORMANCE_VERSION'."
fi
else
echo "$key not found in $env_file. Adding it..."
echo "$key'$CONFORMANCE_VERSION'" >> "$env_file"
echo "Added $key with value '$CONFORMANCE_VERSION'."
fi
else
echo "$env_file not found."
fi
}

# Download Gateway API CRDs (leave as is)
download_gateway_crd "$GATEWAY_CRD_URL" "${OUT_DIR}/${OUT_FILENAME}"

# Download TCPRoute CRD (manage header)
download_tcproute_crd "$TCPROUTE_CRD_URL" "${OUT_DIR}/${TCPROUTE_FILENAME}"

echo "CRD sync complete."
# Update dependencies and environment
update_go_mod
update_max_versions_env

echo "Gateway API sync complete."

0 comments on commit ca3135c

Please sign in to comment.