Skip to content

Commit 03c1ad3

Browse files
fix: add argument parsing
1 parent fedbb43 commit 03c1ad3

File tree

4 files changed

+241
-58
lines changed

4 files changed

+241
-58
lines changed

tests/README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
2. Install [bats](https://github.com/bats-core/bats-core).
55
3. If running multi-arch/multi-auth tests, install GNU Parallel (`brew install parallel`).
66
4. `cd` into the `tests/` directory
7-
5. Create a Python virtual environment and install `boto3`. E.g. using `uv`:
7+
5. Create a Python virtual environment and install `boto3` and `argparse`. The `run-tests.sh` script will automatically activate the virtual environment. E.g. using `uv`:
88

99
```bash
1010
uv venv
11-
uv pip install boto3
12-
source .venv/bin/activate
11+
uv pip install boto3 argparse
1312
```
1413

1514
6. Ensure that the `PRIVREPO` environment variable is set (not required if using `--addon` flag, see step 9).
@@ -55,4 +54,4 @@ aws iam attach-role-policy \
5554
- `./run-tests.sh arm-irsa` will run only ARM IRSA tests
5655
- `./run-tests.sh arm-pod-identity` will run only ARM Pod Identity tests
5756
- Add `--addon` flag to use EKS add-on installation instead of Helm (e.g., `./run-tests.sh --addon` or `./run-tests.sh x64-irsa --addon`)
58-
- Add `--version` flag to select which EKS add-on version to test. (e.g. `./ren-tests.sh --addon --version v2.1.1-eksbuild.1`)
57+
- Add `--version` flag to select which EKS add-on version to test. (e.g. `./run-tests.sh pod-identity --addon --version v2.1.1-eksbuild.1`)

tests/integration.bats.template

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ setup_file() {
4242
--node-type ${{NODE_TYPE_VAR}} \
4343
--nodes 3 \
4444
--region $REGION \
45-
--kubeconfig=${{KUBECONFIG_VAR}}
46-
47-
{{AUTH_SETUP}}
45+
--kubeconfig=${{KUBECONFIG_VAR}} >&3 2>&1
4846

4947
{{INSTALL_METHOD}}
5048

49+
{{AUTH_SETUP}}
50+
5151
log "Cluster setup completed for $CLUSTER_NAME"
5252
}
5353

@@ -56,7 +56,7 @@ teardown_file() {
5656

5757
eksctl delete cluster \
5858
--name $CLUSTER_NAME \
59-
--region $REGION
59+
--region $REGION >&3 2>&1
6060

6161
log "Cleaning up kubeconfig file"
6262
rm -f ${{KUBECONFIG_VAR}}

tests/run-tests.sh

Lines changed: 111 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/bin/bash
22

3+
REGION="${REGION:-us-west-2}"
34
USE_ADDON=false
45
ADDON_VERSION=""
56

@@ -16,12 +17,14 @@ check_parallel() {
1617
}
1718

1819
generate_test_files() {
19-
echo "Generating test files from templates..."
20-
if [[ ! -f "generate-test-files.py" ]]; then
21-
echo "Error: generate-test-files.py not found!"
20+
if [[ ! -f "test-manager.py" ]]; then
21+
echo "Error: test-manager.py not found!"
2222
exit 1
2323
fi
2424

25+
source .venv/bin/activate
26+
python3 test-manager.py cleanup-files
27+
2528
ARGS=()
2629
if [[ "$USE_ADDON" == "true" ]]; then
2730
ARGS+=(--addon)
@@ -30,51 +33,120 @@ generate_test_files() {
3033
ARGS+=(--version "$ADDON_VERSION")
3134
fi
3235

33-
python3 generate-test-files.py "${ARGS[@]}"
36+
echo "Generating test files from templates..."
37+
python3 test-manager.py "${ARGS[@]}"
3438

3539
if [[ $? -ne 0 ]]; then
40+
deactivate
3641
echo "Error: Failed to generate test files from templates"
3742
exit 1
3843
fi
44+
deactivate
3945
echo "Test files generated successfully"
4046
}
4147

4248
cleanup_generated_files() {
4349
echo "Cleaning up generated test files..."
44-
rm -f x64-irsa.bats x64-pod-identity.bats arm-irsa.bats arm-pod-identity.bats
45-
rm -f BasicTestMountSPC-x64-irsa.yaml BasicTestMountSPC-x64-pod-identity.yaml BasicTestMountSPC-arm-irsa.yaml BasicTestMountSPC-arm-pod-identity.yaml
46-
rm -f BasicTestMount-x64-irsa.yaml BasicTestMount-x64-pod-identity.yaml BasicTestMount-arm-irsa.yaml BasicTestMount-arm-pod-identity.yaml
47-
echo "Generated test files cleaned up"
50+
source .venv/bin/activate
51+
python3 test-manager.py cleanup-files
52+
deactivate
4853
}
4954

5055
delete_cluster() {
5156
eksctl delete cluster --name $1 --parallel 25
5257
}
5358

59+
check_and_cleanup_clusters() {
60+
local targets=("$@")
61+
local clusters_to_check=()
62+
63+
# Determine which clusters to check based on targets
64+
for target in "${targets[@]}"; do
65+
case "$target" in
66+
""|"all")
67+
clusters_to_check=("integ-cluster-x64-irsa" "integ-cluster-x64-pod-identity" "integ-cluster-arm-irsa" "integ-cluster-arm-pod-identity")
68+
break
69+
;;
70+
"x64")
71+
clusters_to_check+=("integ-cluster-x64-irsa" "integ-cluster-x64-pod-identity")
72+
;;
73+
"arm")
74+
clusters_to_check+=("integ-cluster-arm-irsa" "integ-cluster-arm-pod-identity")
75+
;;
76+
"irsa")
77+
clusters_to_check+=("integ-cluster-x64-irsa" "integ-cluster-arm-irsa")
78+
;;
79+
"pod-identity")
80+
clusters_to_check+=("integ-cluster-x64-pod-identity" "integ-cluster-arm-pod-identity")
81+
;;
82+
"x64-irsa")
83+
clusters_to_check+=("integ-cluster-x64-irsa")
84+
;;
85+
"x64-pod-identity")
86+
clusters_to_check+=("integ-cluster-x64-pod-identity")
87+
;;
88+
"arm-irsa")
89+
clusters_to_check+=("integ-cluster-arm-irsa")
90+
;;
91+
"arm-pod-identity")
92+
clusters_to_check+=("integ-cluster-arm-pod-identity")
93+
;;
94+
esac
95+
done
96+
97+
# Check if any clusters exist and delete them
98+
for cluster in "${clusters_to_check[@]}"; do
99+
if eksctl get cluster --name "$cluster" --region "$REGION" >/dev/null 2>&1; then
100+
echo "⚠ Cluster $cluster already exists, deleting..."
101+
delete_cluster "$cluster"
102+
fi
103+
done
104+
}
105+
54106
cleanup_secrets() {
55107
echo "Cleaning up secrets and parameters..."
56-
python3 generate-test-files.py cleanup-secrets
108+
source .venv/bin/activate
109+
python3 test-manager.py cleanup-secrets
110+
deactivate
57111
}
58112

59-
# Parse arguments
113+
# Parse arguments - test target must come before flags
60114
TEST_TARGET=""
61-
for i in "${!@}"; do
62-
arg="${!i}"
63-
if [[ "$arg" == "--addon" ]]; then
64-
USE_ADDON=true
65-
elif [[ "$arg" == "--version" ]]; then
66-
next_i=$((i + 1))
67-
ADDON_VERSION="${!next_i}"
68-
elif [[ "$arg" != "--"* ]] && [[ "$arg" != "$ADDON_VERSION" ]]; then
69-
TEST_TARGET="$arg"
70-
fi
115+
if [[ $# -gt 0 ]] && [[ "$1" != "--"* ]]; then
116+
TEST_TARGET="$1"
117+
shift
118+
fi
119+
120+
while [[ $# -gt 0 ]]; do
121+
case "$1" in
122+
--addon)
123+
USE_ADDON=true
124+
shift
125+
;;
126+
--version)
127+
ADDON_VERSION="$2"
128+
shift 2
129+
;;
130+
*)
131+
echo "Error: Unknown argument '$1' or test target must come before flags"
132+
exit 1
133+
;;
134+
esac
71135
done
72136

73137
if [[ -n "$ADDON_VERSION" ]] && [[ "$USE_ADDON" != "true" ]]; then
74138
echo "Error: --version flag requires --addon flag"
75139
exit 1
76140
fi
77141

142+
# Validate POD_IDENTITY_ROLE_ARN for pod-identity targets
143+
if [[ "$TEST_TARGET" == *"pod-identity"* ]] || [[ "$TEST_TARGET" == "" ]] || [[ "$TEST_TARGET" == "all" ]]; then
144+
if [[ -z "${POD_IDENTITY_ROLE_ARN}" ]]; then
145+
echo "Error: POD_IDENTITY_ROLE_ARN environment variable is not set (required for pod-identity tests)"
146+
exit 1
147+
fi
148+
fi
149+
78150
if [[ "$TEST_TARGET" == "clean" ]]; then
79151
cleanup
80152

@@ -95,6 +167,25 @@ if [[ "$TEST_TARGET" == "clean" ]]; then
95167
exit $?
96168
fi
97169

170+
# Validate PRIVREPO image if not using addon
171+
if [[ "$USE_ADDON" != "true" ]]; then
172+
if [[ -z "${PRIVREPO}" ]]; then
173+
echo "Error: PRIVREPO environment variable is not set"
174+
exit 1
175+
fi
176+
echo "Validating ECR image: $PRIVREPO"
177+
source .venv/bin/activate
178+
python3 test-manager.py validate-image
179+
if [[ $? -ne 0 ]]; then
180+
deactivate
181+
exit 1
182+
fi
183+
deactivate
184+
fi
185+
186+
# Check and cleanup any existing clusters for the target
187+
check_and_cleanup_clusters "$TEST_TARGET"
188+
98189
# Generate test files from templates (this also creates secrets)
99190
generate_test_files
100191

0 commit comments

Comments
 (0)