Skip to content

Commit a77dd36

Browse files
committed
added bash script to update data.yaml
1 parent 905d50c commit a77dd36

File tree

10 files changed

+298
-0
lines changed

10 files changed

+298
-0
lines changed

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ require (
171171
github.com/mailru/easyjson v0.7.7 // indirect
172172
github.com/mattn/go-colorable v0.1.13 // indirect
173173
github.com/mattn/go-isatty v0.0.20 // indirect
174+
github.com/mattn/go-runewidth v0.0.15 // indirect
174175
github.com/mdlayher/socket v0.4.1 // indirect
175176
github.com/mdlayher/vsock v1.2.1 // indirect
176177
github.com/mitchellh/go-homedir v1.1.0 // indirect
@@ -187,6 +188,7 @@ require (
187188
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
188189
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
189190
github.com/prometheus/procfs v0.16.1 // indirect
191+
github.com/rivo/uniseg v0.4.7 // indirect
190192
github.com/ryanuber/go-glob v1.0.0 // indirect
191193
github.com/sagikazarmark/locafero v0.7.0 // indirect
192194
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
@@ -259,6 +261,7 @@ tool (
259261
github.com/campoy/embedmd
260262
github.com/google/go-jsonnet/cmd/jsonnet
261263
github.com/hairyhenderson/gomplate/v4/cmd/gomplate
264+
github.com/itchyny/gojq/cmd/gojq
262265
github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb
263266
golang.org/x/perf/cmd/benchstat
264267
)

go.sum

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,8 @@ github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27k
491491
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
492492
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
493493
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
494+
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
495+
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
494496
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
495497
github.com/mdlayher/socket v0.4.1 h1:eM9y2/jlbs1M615oshPQOHZzj6R6wMT7bX5NPiQvn2U=
496498
github.com/mdlayher/socket v0.4.1/go.mod h1:cAqeGjoufqdxWkD7DkpyS+wcefOtmu5OQ8KuoJGIReA=
@@ -579,6 +581,9 @@ github.com/protocolbuffers/txtpbfmt v0.0.0-20240823084532-8e6b51fa9bef h1:ej+64j
579581
github.com/protocolbuffers/txtpbfmt v0.0.0-20240823084532-8e6b51fa9bef/go.mod h1:jgxiZysxFPM+iWKwQwPR+y+Jvo54ARd4EisXxKYpB5c=
580582
github.com/redis/go-redis/v9 v9.6.1 h1:HHDteefn6ZkTtY5fGUE8tj8uy85AHk6zP7CpzIAM0y4=
581583
github.com/redis/go-redis/v9 v9.6.1/go.mod h1:0C0c6ycQsdpVNQpxb1njEQIqkx5UcsM8FJCQLgE9+RA=
584+
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
585+
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
586+
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
582587
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
583588
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
584589
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# The purpose of this config is to keep all versions in a single file and make them machine accessible
2+
3+
# Marks the latest release
4+
version: "2.17.0"
5+
6+
# List at max 5 releases here + the main branch
7+
compat:
8+
- version: "v2.14.0"
9+
kubernetes: "1.31"
10+
- version: "v2.15.0"
11+
kubernetes: "1.32"
12+
- version: "v2.16.0"
13+
kubernetes: "1.32"
14+
- version: "v2.17.0"
15+
kubernetes: "1.33"
16+
- version: "main"
17+
kubernetes: "1.33"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# The purpose of this config is to keep all versions in a single file and make them machine accessible
2+
3+
# Marks the latest release
4+
version: "2.17.0"
5+
6+
# List at max 5 releases here + the main branch
7+
compat:
8+
- version: "v2.13.0"
9+
kubernetes: "1.30"
10+
- version: "v2.14.0"
11+
kubernetes: "1.31"
12+
- version: "v2.15.0"
13+
kubernetes: "1.32"
14+
- version: "v2.16.0"
15+
kubernetes: "1.32"
16+
- version: "v2.17.0"
17+
kubernetes: "1.33"
18+
- version: "main"
19+
kubernetes: "1.33"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# The purpose of this config is to keep all versions in a single file and make them machine accessible
2+
3+
# Marks the latest release
4+
version: "2.17.0"
5+
6+
# List at max 5 releases here + the main branch
7+
compat:
8+
- version: "v2.14.0"
9+
kubernetes: "1.31"
10+
- version: "v2.15.0"
11+
kubernetes: "1.32"
12+
- version: "v2.16.0"
13+
kubernetes: "1.32"
14+
- version: "v2.17.0"
15+
kubernetes: "1.33"
16+
- version: "v2.18.0"
17+
kubernetes: "1.33"
18+
- version: "main"
19+
kubernetes: "1.33"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# This configuration tracks the last five releases, and acts as the source of truth for those entries in the README.
2+
#
3+
# This marks the latest release.
4+
version: "2.18.0"
5+
6+
# List KSM-to-K8s version mapping for the last five releases here, and the default branch.
7+
compat:
8+
- version: "v2.14.0"
9+
kubernetes: "1.31"
10+
- version: "v2.15.0"
11+
kubernetes: "1.32"
12+
- version: "v2.16.0"
13+
kubernetes: "1.32"
14+
- version: "v2.17.0"
15+
kubernetes: "1.33"
16+
- version: "v2.18.0"
17+
kubernetes: "1.33"
18+
- version: "main"
19+
kubernetes: "1.33"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# This configuration tracks the last five releases, and acts as the source of truth for those entries in the README.
2+
#
3+
# This marks the latest release.
4+
version: "2.18.0"
5+
6+
# List KSM-to-K8s version mapping for the last five releases here, and the default branch.
7+
compat:
8+
- version: "v2.14.0"
9+
kubernetes: "1.31"
10+
- version: "v2.15.0"
11+
kubernetes: "1.32"
12+
- version: "v2.16.0"
13+
kubernetes: "1.32"
14+
- version: "v2.17.0"
15+
kubernetes: "1.33"
16+
- version: "v2.18.0"
17+
kubernetes: "1.33"
18+
- version: "main"
19+
kubernetes: "1.33"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# The purpose of this config is to keep all versions in a single file and make them machine accessible
2+
3+
# Marks the latest release
4+
version: "2.17.0"
5+
6+
# List at max 5 releases here + the main branch
7+
compat:
8+
- version: "v2.14.0"
9+
kubernetes: "1.31"
10+
- version: "v2.15.0"
11+
kubernetes: "1.32"
12+
- version: "v2.16.0"
13+
kubernetes: "1.32"
14+
- version: "v2.17.0"
15+
kubernetes: "1.33"
16+
- version: "v2.18.0"
17+
kubernetes: "1.33"
18+
- version: "main"
19+
kubernetes: "1.33"
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &>/dev/null && pwd )
5+
PROJECT_ROOT=$( cd -- "${SCRIPT_DIR}/../../.." &>/dev/null && pwd )
6+
7+
INPUT_DIR="${SCRIPT_DIR}/inputs"
8+
OUTPUT_DIR="${SCRIPT_DIR}/outputs"
9+
mkdir -p "${OUTPUT_DIR}"
10+
11+
# Backup root data.yaml once
12+
ROOT_DATA="${PROJECT_ROOT}/data.yaml"
13+
TMP_DATA=$(mktemp)
14+
cp "${ROOT_DATA}" "${TMP_DATA}"
15+
16+
for input_file in "${INPUT_DIR}"/*.yaml; do
17+
base=$(basename "${input_file}" .yaml)
18+
echo "Processing ${base}.yaml ..."
19+
20+
cp "${input_file}" "${ROOT_DATA}"
21+
"${PROJECT_ROOT}/scripts/update-data-yaml.sh" v2.18.0
22+
cp "${ROOT_DATA}" "${OUTPUT_DIR}/${base}.out.yaml"
23+
done
24+
25+
# Restore original data.yaml
26+
mv "${TMP_DATA}" "${ROOT_DATA}"
27+
28+
echo "All done. Results in ${OUTPUT_DIR}"

scripts/update-data-yaml.sh

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
5+
REPO_ROOT=$( cd -- "${SCRIPT_DIR}/.." &> /dev/null && pwd )
6+
DATA_FILE="${REPO_ROOT}/data.yaml"
7+
NUM_RELEASES_TO_KEEP=5
8+
9+
GOJQ="go tool github.com/itchyny/gojq/cmd/gojq"
10+
11+
check_command() {
12+
if ! command -v "$1" &> /dev/null; then
13+
echo "Error: Required command '$1' not found. Please install it to continue." >&2
14+
exit 1
15+
fi
16+
}
17+
18+
check_command "go"
19+
check_command "sort"
20+
21+
if [ -z "$1" ]; then
22+
echo "Usage: $0 <new_version>"
23+
echo "Example: $0 v2.17.0"
24+
exit 1
25+
fi
26+
27+
if [ ! -f "${DATA_FILE}" ]; then
28+
echo "Error: Data file not found at ${DATA_FILE}" >&2
29+
exit 1
30+
fi
31+
32+
NEW_VERSION_WITH_V=$1
33+
NEW_VERSION_WITHOUT_V=${NEW_VERSION_WITH_V#v}
34+
35+
echo "Starting update process for version ${NEW_VERSION_WITH_V}..."
36+
37+
echo "Checking k8s.io/client-go version from go.mod..."
38+
GO_MOD="${REPO_ROOT}/go.mod"
39+
40+
if [ ! -f "${GO_MOD}" ]; then
41+
echo "Error: go.mod file not found at ${GO_MOD}" >&2
42+
exit 1
43+
fi
44+
45+
CLIENT_GO_VERSION=$(go list -m -f '{{.Version}}' k8s.io/client-go)
46+
47+
if [ -z "$CLIENT_GO_VERSION" ]; then
48+
echo "Error: Could not find k8s.io/client-go version in go.mod." >&2
49+
exit 1
50+
fi
51+
52+
K8S_MINOR=$(echo "${CLIENT_GO_VERSION}" | cut -d. -f2)
53+
54+
K8S_VERSION_FOR_NEW_RELEASE="1.${K8S_MINOR}"
55+
echo "New release ${NEW_VERSION_WITH_V} will be mapped to Kubernetes: ${K8S_VERSION_FOR_NEW_RELEASE}"
56+
57+
# Convert YAML data file to JSON format
58+
DATA_FILE_JSON_DATA=$(${GOJQ} -r --yaml-input '.' "${DATA_FILE}")
59+
60+
EXISTING_EXACT_MATCH=$(\
61+
echo "${DATA_FILE_JSON_DATA}" |\
62+
# Query for existing entry with same version and k8s mapping
63+
${GOJQ} -r --arg version "${NEW_VERSION_WITH_V}" --arg k8s "${K8S_VERSION_FOR_NEW_RELEASE}" ".compat[] | select(.version == \$version and .kubernetes == \$k8s) | .version // empty"\
64+
)
65+
66+
if [ -n "${EXISTING_EXACT_MATCH}" ]; then
67+
echo "Entry for ${NEW_VERSION_WITH_V} with Kubernetes ${K8S_VERSION_FOR_NEW_RELEASE} already exists. No changes needed."
68+
exit 0
69+
fi
70+
71+
EXISTING_KSM_VERSION_ENTRY=$(\
72+
echo "${DATA_FILE_JSON_DATA}" |\
73+
# Check if KSM version already exists (with different k8s mapping)
74+
${GOJQ} -r --arg version "${NEW_VERSION_WITH_V}" ".compat[] | select(.version == \$version) | .version // empty"\
75+
)
76+
77+
if [ -n "${EXISTING_KSM_VERSION_ENTRY}" ]; then
78+
echo "Version ${NEW_VERSION_WITH_V} found with a different K8s mapping. Updating..."
79+
cat > "${DATA_FILE}" << EOF
80+
# This configuration tracks the last five releases, and acts as the source of truth for those entries in the README.
81+
#
82+
# This marks the latest release.
83+
version: "${NEW_VERSION_WITHOUT_V}"
84+
85+
# List KSM-to-K8s version mapping for the last five releases here, and the default branch.
86+
compat:
87+
EOF
88+
89+
90+
{
91+
echo "${DATA_FILE_JSON_DATA}" |\
92+
# Filter out the version being updated and format as YAML
93+
${GOJQ} -r --arg version "${NEW_VERSION_WITH_V}" --arg k8s "${K8S_VERSION_FOR_NEW_RELEASE}" \
94+
".compat[] | select(.version != \$version) | \" - kubernetes: \\\"\" + .kubernetes + \"\\\"\\n version: \" + .version"
95+
96+
echo " - kubernetes: \"${K8S_VERSION_FOR_NEW_RELEASE}\""
97+
echo " version: ${NEW_VERSION_WITH_V}"
98+
} >> "${DATA_FILE}"
99+
100+
echo "Successfully updated existing entry for ${NEW_VERSION_WITH_V}."
101+
echo "--- Final ${DATA_FILE} content ---"
102+
cat "${DATA_FILE}"
103+
exit 0
104+
fi
105+
106+
echo "Adding new version ${NEW_VERSION_WITH_V} and pruning old releases..."
107+
108+
VERSIONS_LIST_WITHOUT_MAIN=$(\
109+
echo "${DATA_FILE_JSON_DATA}" |\
110+
# Extract version|kubernetes pairs, excluding main branch
111+
${GOJQ} -r ".compat[] | select(.version != \"main\") | \"\(.version)|\(.kubernetes)\"" 2>/dev/null || true\
112+
)
113+
114+
FULL_VERSIONS_LIST=$(printf "%s\n%s|%s" "${VERSIONS_LIST_WITHOUT_MAIN}" "${NEW_VERSION_WITH_V}" "${K8S_VERSION_FOR_NEW_RELEASE}")
115+
116+
SORTED_VERSIONS=$(\
117+
echo "${FULL_VERSIONS_LIST}" |\
118+
# Remove empty lines
119+
grep -v '^$' |\
120+
# Sort by version (ascending) using version sort
121+
sort -t'|' -k1,1 -V |\
122+
# Keep only the most recent N releases
123+
tail -n "${NUM_RELEASES_TO_KEEP}"\
124+
)
125+
126+
cat > "${DATA_FILE}" << EOF
127+
# This configuration tracks the last five releases, and acts as the source of truth for those entries in the README.
128+
#
129+
# This marks the latest release.
130+
version: "${NEW_VERSION_WITHOUT_V}"
131+
132+
# List KSM-to-K8s version mapping for the last five releases here, and the default branch.
133+
compat:
134+
EOF
135+
136+
while IFS='|' read -r version k8s_ver; do
137+
if [ -n "${version}" ]; then
138+
echo " - version: \"${version}\"" >> "${DATA_FILE}"
139+
echo " kubernetes: \"${k8s_ver}\"" >> "${DATA_FILE}"
140+
fi
141+
done <<< "${SORTED_VERSIONS}"
142+
143+
echo " - version: \"main\"" >> "${DATA_FILE}"
144+
echo " kubernetes: \"${K8S_VERSION_FOR_NEW_RELEASE}\"" >> "${DATA_FILE}"
145+
146+
echo "Successfully updated and pruned ${DATA_FILE}."
147+
echo "New release (${NEW_VERSION_WITH_V}) is mapped to Kubernetes: ${K8S_VERSION_FOR_NEW_RELEASE}"
148+
echo "Main branch is mapped to Kubernetes: ${K8S_VERSION_FOR_NEW_RELEASE}"
149+
echo "--- Final ${DATA_FILE} content ---"
150+
cat "${DATA_FILE}"

0 commit comments

Comments
 (0)