Skip to content

Commit 2204b03

Browse files
authored
Remove gcp bp dependency (#379)
* Add gitea bundle util script and update bundle Signed-off-by: Fiachra Corcoran <fiachra.corcoran@est.tech> * Refactor perf suite to use gitea repos Signed-off-by: Fiachra Corcoran <fiachra.corcoran@est.tech> * Refactor 3pp krm fn suite touse gitea repos Signed-off-by: Fiachra Corcoran <fiachra.corcoran@est.tech> * Remove dep on external GCP test repo Signed-off-by: Fiachra Corcoran <fiachra.corcoran@est.tech> * Add fn to reload the git bundle to gitea Signed-off-by: Fiachra Corcoran <fiachra.corcoran@est.tech> * Remove redundant .env file Signed-off-by: Fiachra Corcoran <fiachra.corcoran@est.tech> * Move testdata to relevant location Signed-off-by: Fiachra Corcoran <fiachra.corcoran@est.tech> * Update bundle tags and output Signed-off-by: Fiachra Corcoran <fiachra.corcoran@est.tech> * Readd Perf CreatePackageDraftF fn Signed-off-by: Fiachra Corcoran <fiachra.corcoran@est.tech> --------- Signed-off-by: Fiachra Corcoran <fiachra.corcoran@est.tech>
1 parent ad97b33 commit 2204b03

36 files changed

Lines changed: 787 additions & 1396 deletions

.env.template

Lines changed: 0 additions & 25 deletions
This file was deleted.

scripts/install-dev-gitea-setup.sh

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ set -u # Must predefine variables
1919
set -o pipefail # Check errors in piped commands
2020

2121
self_dir="$(dirname "$(readlink -f "$0")")"
22-
2322
git_repo_name=${1:-porch-test}
2423
gitea_ip=${2:-172.18.255.200} # should be from the address range in deployments/local/metallb-conf.yaml
2524

2625
git_root="$(readlink -f "${self_dir}/..")"
26+
TEST_BLUEPRINTS_PATH="${git_root}/test/pkgs/test-pkgs/test-blueprints.bundle"
2727
cd "${git_root}"
2828

2929
function h1() {
@@ -32,6 +32,48 @@ function h1() {
3232
echo
3333
}
3434

35+
# Function to reload test-blueprints from bundle
36+
reload_test_blueprints_bundle() {
37+
h1 Reload test-blueprints from bundle
38+
39+
# Setup port-forward
40+
kubectl port-forward -n gitea svc/gitea-lb 3000:3000 >/dev/null 2>&1 &
41+
PORT_FORWARD_PID=$!
42+
sleep 3
43+
44+
# Delete existing repo
45+
h1 "Deleting existing test-blueprints repository"
46+
curl -s -X DELETE "http://nephio:secret@localhost:3000/api/v1/repos/nephio/test-blueprints" >/dev/null 2>&1 || true
47+
48+
# Recreate repo from bundle
49+
h1 "Recreating test-blueprints repository"
50+
curl -s -H "content-type: application/json" "http://nephio:secret@localhost:3000/api/v1/user/repos" --data '{"name":"test-blueprints"}' >/dev/null 2>&1
51+
52+
TEST_BLUEPRINTS_TMP_DIR=$(mktemp -d)
53+
cd "$TEST_BLUEPRINTS_TMP_DIR"
54+
h1 "Cloning from bundle: $TEST_BLUEPRINTS_PATH"
55+
git clone "$TEST_BLUEPRINTS_PATH" -b main
56+
cd test-blueprints
57+
58+
git gc
59+
git remote rename origin upstream
60+
git remote add origin "http://nephio:secret@localhost:3000/nephio/test-blueprints"
61+
git push -u origin --all
62+
git push -u origin --tags
63+
64+
cd "${git_root}"
65+
rm -fr "$TEST_BLUEPRINTS_TMP_DIR"
66+
67+
kill $PORT_FORWARD_PID 2>/dev/null || true
68+
echo "Test-blueprints repo reloaded from bundle"
69+
}
70+
71+
# Check if reload command
72+
if [ $# -gt 0 ] && [ "$1" == "reload" ]; then
73+
reload_test_blueprints_bundle
74+
exit 0
75+
fi
76+
3577
# Retry function for curl commands
3678
function retry_curl() {
3779
local max_attempts=$1
@@ -159,7 +201,7 @@ else
159201
fi
160202
TEST_BLUEPRINTS_TMP_DIR=$(mktemp -d)
161203
cd "$TEST_BLUEPRINTS_TMP_DIR"
162-
git clone "${git_root}/test/pkgs/test-pkgs/test-blueprints.bundle" -b main
204+
git clone "$TEST_BLUEPRINTS_PATH" -b main
163205
cd "$test_git_repo_name"
164206

165207
git gc
Lines changed: 294 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,294 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2025 The kpt and Nephio Authors
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
# modify-gitea-test-blueprints.sh - Manage kpt packages in test-blueprints.bundle
17+
18+
# Stricter error handling
19+
set -e # Exit on error
20+
set -u # Must predefine variables
21+
set -o pipefail # Check errors in piped commands
22+
23+
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
24+
BUNDLE_PATH="$SCRIPT_DIR/../test/pkgs/test-pkgs/test-blueprints.bundle"
25+
26+
# Initialize bundle workspace
27+
init_bundle() {
28+
TEMP_DIR=$(mktemp -d)
29+
trap "rm -rf $TEMP_DIR" EXIT
30+
git clone "$BUNDLE_PATH" "$TEMP_DIR/repo"
31+
cd "$TEMP_DIR/repo"
32+
git config user.name "e2e Test User"
33+
git config user.email "e2etest@example.com"
34+
}
35+
36+
# Check if package or tag exists
37+
check_exists() {
38+
local package_name="$1"
39+
local tag="$2"
40+
41+
if [ -d "$package_name" ]; then
42+
echo "Error: Package '$package_name' already exists"
43+
exit 1
44+
fi
45+
46+
if [ -n "$tag" ] && git tag -l | grep -q "^$tag$"; then
47+
echo "Error: Tag '$tag' already exists"
48+
exit 1
49+
fi
50+
}
51+
52+
# Pull kpt package from repo or local dir
53+
pull_kpt_package() {
54+
local source="$1"
55+
local kpt_ref="$2"
56+
local kpt_dir="$3"
57+
local package_name="$4"
58+
59+
cd "$TEMP_DIR/repo"
60+
61+
if [ -d "$source" ]; then
62+
# Local directory
63+
echo "Copying kpt package from local directory $source"
64+
if [ -n "$kpt_dir" ]; then
65+
cp -r "$source/$kpt_dir" "$package_name"
66+
else
67+
cp -r "$source" "$package_name"
68+
fi
69+
else
70+
# Git repository - use kpt pkg get
71+
# Check if kpt is installed
72+
if ! command -v kpt >/dev/null 2>&1; then
73+
echo "Error: kpt is not installed or not in PATH"
74+
echo "Please install kpt: https://kpt.dev/installation/"
75+
exit 1
76+
fi
77+
78+
echo "Pulling kpt package from $source@$kpt_ref"
79+
80+
# Build kpt pkg get URL
81+
local kpt_url="$source"
82+
if [ -n "$kpt_dir" ]; then
83+
kpt_url="$source/$kpt_dir"
84+
fi
85+
if [ "$kpt_ref" != "main" ]; then
86+
kpt_url="$kpt_url@$kpt_ref"
87+
fi
88+
89+
kpt pkg get "$kpt_url" "$package_name"
90+
fi
91+
92+
# Update Kptfile name
93+
if [ -f "$package_name/Kptfile" ]; then
94+
sed -i "s/name: .*/name: $package_name/" "$package_name/Kptfile"
95+
fi
96+
}
97+
98+
# Commit and tag package
99+
commit_package() {
100+
local package_name="$1"
101+
local source="$2"
102+
local kpt_ref="$3"
103+
local tag="$4"
104+
105+
git add .
106+
if [ -d "$source" ]; then
107+
git commit -m "Add pkg $package_name from local"
108+
else
109+
git commit -m "Add pkg $package_name from $source@$kpt_ref"
110+
fi
111+
112+
if [ -n "$tag" ]; then
113+
git tag "$tag"
114+
fi
115+
}
116+
117+
118+
119+
# Read bundle contents
120+
read_bundle() {
121+
local temp_dir=$(mktemp -d)
122+
trap "rm -rf $temp_dir" EXIT
123+
124+
git clone "$BUNDLE_PATH" "$temp_dir/repo"
125+
cd "$temp_dir/repo"
126+
127+
echo ""
128+
echo "Bundle contents:"
129+
git --no-pager log --oneline --all
130+
echo ""
131+
echo "Packages:"
132+
ls -la
133+
echo ""
134+
echo "Tags:"
135+
git --no-pager tag -l
136+
}
137+
138+
# Revert last commit
139+
revert_bundle() {
140+
local temp_dir=$(mktemp -d)
141+
trap "rm -rf $temp_dir" EXIT
142+
143+
git clone "$BUNDLE_PATH" "$temp_dir/repo"
144+
cd "$temp_dir/repo"
145+
146+
echo "Last commit:"
147+
git --no-pager log -1 --oneline
148+
149+
# Get tags and files before reverting
150+
local tags_to_delete=$(git tag --points-at HEAD)
151+
local files_removed=$(git --no-pager show --name-only --format="" HEAD)
152+
153+
git reset --hard HEAD~1
154+
155+
# Delete tags that were pointing to the reverted commit
156+
if [ -n "$tags_to_delete" ]; then
157+
echo "$tags_to_delete" | xargs -r git tag -d
158+
fi
159+
160+
git bundle create "$BUNDLE_PATH" --all
161+
162+
echo "Reverted last commit from bundle"
163+
echo ""
164+
echo "Removed files:"
165+
echo "$files_removed"
166+
if [ -n "$tags_to_delete" ]; then
167+
echo ""
168+
echo "Removed tags:"
169+
echo "$tags_to_delete"
170+
fi
171+
}
172+
173+
# Main function
174+
add_kpt_package() {
175+
if [ -z "$PACKAGE_NAME" ] || [ -z "$SOURCE" ]; then
176+
echo "Error: --name and --source are required"
177+
return 1
178+
fi
179+
180+
init_bundle
181+
check_exists "$PACKAGE_NAME" "$TAG"
182+
pull_kpt_package "$SOURCE" "$KPT_REF" "$KPT_DIR" "$PACKAGE_NAME"
183+
commit_package "$PACKAGE_NAME" "$SOURCE" "$KPT_REF" "$TAG"
184+
git bundle create "$BUNDLE_PATH" --all
185+
186+
read_bundle
187+
if [ -d "$SOURCE" ]; then
188+
echo "Added pkg $PACKAGE_NAME to test-blueprints bundle from local directory $SOURCE"
189+
else
190+
echo "Added pkg $PACKAGE_NAME to test-blueprints bundle from $SOURCE"
191+
fi
192+
}
193+
194+
# Reload gitea test-blueprints repo
195+
reload_gitea() {
196+
if ! command -v kubectl >/dev/null 2>&1; then
197+
echo "Error: kubectl is not installed or not in PATH"
198+
return 1
199+
fi
200+
201+
if ! kubectl get pods -l app=gitea -n gitea >/dev/null 2>&1; then
202+
echo "Error: Gitea is not running"
203+
return 1
204+
fi
205+
206+
echo "Reloading gitea test-blueprints repo..."
207+
"$SCRIPT_DIR/install-dev-gitea-setup.sh" reload
208+
}
209+
210+
# Parse flags
211+
parse_flags() {
212+
PACKAGE_NAME=""
213+
SOURCE=""
214+
KPT_REF="main"
215+
KPT_DIR=""
216+
TAG=""
217+
218+
while [[ $# -gt 0 ]]; do
219+
case $1 in
220+
-n|--name)
221+
PACKAGE_NAME="$2"
222+
shift 2
223+
;;
224+
-s|--source)
225+
SOURCE="$2"
226+
shift 2
227+
;;
228+
-r|--ref)
229+
KPT_REF="$2"
230+
shift 2
231+
;;
232+
-d|--dir)
233+
KPT_DIR="$2"
234+
shift 2
235+
;;
236+
-t|--tag)
237+
TAG="$2"
238+
shift 2
239+
;;
240+
*)
241+
echo "Unknown option $1"
242+
exit 1
243+
;;
244+
esac
245+
done
246+
}
247+
248+
# Run if called directly
249+
if [ "${BASH_SOURCE[0]}" == "${0}" ]; then
250+
if [ "$1" == "read" ]; then
251+
read_bundle
252+
elif [ "$1" == "revert" ]; then
253+
revert_bundle
254+
elif [ "$1" == "reload" ]; then
255+
reload_gitea
256+
elif [ "$1" == "-h" ] || [ "$1" == "--help" ] || [ $# -eq 0 ]; then
257+
echo "Usage: $0 -n <name> -s <source> [-r <ref>] [-d <dir>] [-t <tag>]"
258+
echo " $0 read"
259+
echo " $0 revert"
260+
echo " $0 reload"
261+
echo ""
262+
echo "Options:"
263+
echo " -n, --name Package name in bundle (required)"
264+
echo " -s, --source Git repository URL or local directory path (required)"
265+
echo " -r, --ref Git ref (branch/tag, default: main)"
266+
echo " -d, --dir Subdirectory in source (optional)"
267+
echo " -t, --tag Git tag to create (optional)"
268+
echo ""
269+
echo "Commands:"
270+
echo " read Show bundle contents"
271+
echo " revert Undo last commit"
272+
echo " reload Reload gitea test-blueprints repo"
273+
echo ""
274+
echo "Examples:"
275+
echo " # Add bucket package from GCP blueprints"
276+
echo " $0 -n bucket -s https://github.com/GoogleCloudPlatform/blueprints.git -r bucket-blueprint-v0.4.3 -d catalog/bucket -t bucket/bucket-blueprint-v0.4.3"
277+
echo ""
278+
echo " # Add package from local directory"
279+
echo " $0 -n bucket -s ~/Downloads/bucket-copy/ -t bucket/bucket-blueprint-v0.4.3"
280+
echo ""
281+
echo " # Show bundle contents"
282+
echo " $0 read"
283+
echo ""
284+
echo " # Revert last change"
285+
echo " $0 revert"
286+
echo ""
287+
echo " # Reload gitea repo"
288+
echo " $0 reload"
289+
exit 1
290+
else
291+
parse_flags "$@"
292+
add_kpt_package
293+
fi
294+
fi

test/e2e/testdata/nested-packages/nested-pkg/Kptfile renamed to test/e2e/cli/test_pkgs/nested-packages/nested-pkg/Kptfile

File renamed without changes.

test/e2e/testdata/nested-packages/nested-pkg/configmap.yaml renamed to test/e2e/cli/test_pkgs/nested-packages/nested-pkg/configmap.yaml

File renamed without changes.

test/e2e/testdata/nested-packages/nested-pkg/fn-config.yaml renamed to test/e2e/cli/test_pkgs/nested-packages/nested-pkg/fn-config.yaml

File renamed without changes.

test/e2e/testdata/nested-packages/nested-pkg/package-context.yaml renamed to test/e2e/cli/test_pkgs/nested-packages/nested-pkg/package-context.yaml

File renamed without changes.

test/e2e/testdata/nested-packages/nested-pkg/subpackage-parameters.yaml renamed to test/e2e/cli/test_pkgs/nested-packages/nested-pkg/subpackage-parameters.yaml

File renamed without changes.

test/e2e/testdata/nested-packages/parent-pkg/Kptfile renamed to test/e2e/cli/test_pkgs/nested-packages/parent-pkg/Kptfile

File renamed without changes.

test/e2e/testdata/nested-packages/parent-pkg/fn-pass-parameters.yaml renamed to test/e2e/cli/test_pkgs/nested-packages/parent-pkg/fn-pass-parameters.yaml

File renamed without changes.

0 commit comments

Comments
 (0)