Skip to content

Commit f7dfd16

Browse files
committed
hack: scripts and helpers
Signed-off-by: Bharath Nallapeta <[email protected]>
1 parent bf62a91 commit f7dfd16

File tree

6 files changed

+343
-0
lines changed

6 files changed

+343
-0
lines changed

.gopls.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
build:
2+
buildFlags:
3+
- "-tags=e2e"
4+
env:
5+
CGO_ENABLED: "1"

cleanup-hcp-test.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
# Cleanup script for failed HCP test resources
3+
4+
# Set OpenStack environment
5+
export OS_CLOUD=openstack
6+
export OS_CLOUD_YAML_FILE=/Users/bnr/work/openstack/clouds.yaml
7+
8+
echo "🧹 Cleaning up HCP test resources..."
9+
10+
# Delete the specific instances from your screenshot
11+
echo "Deleting OpenStack instances..."
12+
openstack server delete hcp-mgmt-hcp-mgmt-hcp-1752250951-al4m23-bastion
13+
openstack server delete hcp-mgmt-hcp-mgmt-hcp-1752250951-al4m23-control-plane-sinpp5-bastion
14+
15+
# Clean up any floating IPs that might be allocated
16+
echo "Cleaning up floating IPs..."
17+
openstack floating ip list --status DOWN -f value -c ID | xargs -r openstack floating ip delete
18+
19+
# Clean up security groups (if any were created)
20+
echo "Cleaning up security groups..."
21+
openstack security group list --project $(openstack token issue -c project_id -f value) | grep "hcp-mgmt\|cluster-api" | awk '{print $2}' | xargs -r openstack security group delete
22+
23+
# Clean up keypairs (if any were created)
24+
echo "Cleaning up keypairs..."
25+
openstack keypair list | grep "cluster-api-provider-openstack-sigs-k8s-io" | awk '{print $2}' | xargs -r openstack keypair delete
26+
27+
# Clean up networks and subnets (if any were created)
28+
echo "Cleaning up networks..."
29+
openstack network list | grep "hcp-mgmt\|cluster-api" | awk '{print $2}' | xargs -r openstack network delete
30+
31+
# Clean up any volumes
32+
echo "Cleaning up volumes..."
33+
openstack volume list --status available | grep "hcp-mgmt\|cluster-api" | awk '{print $2}' | xargs -r openstack volume delete
34+
35+
echo "✅ Cleanup completed!"
36+
echo ""
37+
echo "Manual verification commands:"
38+
echo "openstack server list"
39+
echo "openstack floating ip list"
40+
echo "openstack security group list"
41+
echo "openstack network list"

cleanup-proper-order.sh

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#!/bin/bash
2+
# Proper OpenStack cleanup script - deletes in correct dependency order
3+
4+
export OS_CLOUD=openstack
5+
export OS_CLOUD_YAML_FILE=/Users/bnr/work/openstack/clouds.yaml
6+
7+
echo "🧹 Starting proper OpenStack cleanup (dependency order)..."
8+
9+
# 1. First, delete servers (instances)
10+
echo "=== Step 1: Deleting Servers ==="
11+
openstack server list -f value -c ID -c Name | grep -E "(hcp|e2e|cluster-api)" | while read id name; do
12+
echo "Deleting server: $name ($id)"
13+
openstack server delete "$id" || true
14+
done
15+
16+
# Wait a bit for servers to be deleted
17+
echo "Waiting for servers to be deleted..."
18+
sleep 10
19+
20+
# 2. Delete floating IPs
21+
echo "=== Step 2: Deleting Floating IPs ==="
22+
openstack floating ip list -f value -c ID | xargs -r -I {} bash -c 'echo "Deleting floating IP: {}"; openstack floating ip delete {} || true'
23+
24+
# 3. Delete load balancers (if any)
25+
echo "=== Step 3: Deleting Load Balancers ==="
26+
openstack loadbalancer list -f value -c id -c name | grep -E "(hcp|e2e|cluster-api)" | while read id name; do
27+
echo "Deleting loadbalancer: $name ($id)"
28+
openstack loadbalancer delete "$id" --cascade || true
29+
done
30+
31+
# Wait for load balancers to be deleted
32+
echo "Waiting for load balancers to be deleted..."
33+
sleep 15
34+
35+
# 4. Delete router interfaces and routers
36+
echo "=== Step 4: Deleting Routers ==="
37+
openstack router list -f value -c ID -c Name | grep -E "(hcp|e2e|cluster-api)" | while read id name; do
38+
echo "Processing router: $name ($id)"
39+
40+
# First remove all interfaces from the router
41+
echo " Removing interfaces from router $name"
42+
openstack port list --router "$id" -f value -c ID | while read port_id; do
43+
echo " Removing interface $port_id"
44+
openstack router remove port "$id" "$port_id" || true
45+
done
46+
47+
# Then delete the router
48+
echo " Deleting router $name"
49+
openstack router delete "$id" || true
50+
done
51+
52+
# 5. Delete ports
53+
echo "=== Step 5: Deleting Ports ==="
54+
openstack port list -f value -c ID -c Name | grep -E "(hcp|e2e|cluster-api)" | while read id name; do
55+
echo "Deleting port: $name ($id)"
56+
openstack port delete "$id" || true
57+
done
58+
59+
# 6. Delete subnets
60+
echo "=== Step 6: Deleting Subnets ==="
61+
openstack subnet list -f value -c ID -c Name | grep -E "(hcp|e2e|cluster-api)" | while read id name; do
62+
echo "Deleting subnet: $name ($id)"
63+
openstack subnet delete "$id" || true
64+
done
65+
66+
# 7. Finally, delete networks
67+
echo "=== Step 7: Deleting Networks ==="
68+
openstack network list -f value -c ID -c Name | grep -E "(hcp|e2e|cluster-api)" | while read id name; do
69+
echo "Deleting network: $name ($id)"
70+
openstack network delete "$id" || true
71+
done
72+
73+
# 8. Delete security groups
74+
echo "=== Step 8: Deleting Security Groups ==="
75+
openstack security group list -f value -c ID -c Name | grep -E "(hcp|e2e|cluster-api)" | while read id name; do
76+
echo "Deleting security group: $name ($id)"
77+
openstack security group delete "$id" || true
78+
done
79+
80+
# 9. Delete keypairs
81+
echo "=== Step 9: Deleting Keypairs ==="
82+
openstack keypair list -f value -c Name | grep -E "(hcp|e2e|cluster-api)" | while read name; do
83+
echo "Deleting keypair: $name"
84+
openstack keypair delete "$name" || true
85+
done
86+
87+
# 10. Delete volumes
88+
echo "=== Step 10: Deleting Volumes ==="
89+
openstack volume list --status available -f value -c ID -c Name | grep -E "(hcp|e2e|cluster-api)" | while read id name; do
90+
echo "Deleting volume: $name ($id)"
91+
openstack volume delete "$id" || true
92+
done
93+
94+
echo "✅ Cleanup completed!"
95+
echo ""
96+
echo "Verification commands:"
97+
echo "openstack server list"
98+
echo "openstack network list | grep -E '(hcp|e2e|cluster-api)'"
99+
echo "openstack router list | grep -E '(hcp|e2e|cluster-api)'"
100+
echo "openstack security group list | grep -E '(hcp|e2e|cluster-api)'"

cleanup_openstack.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
set -e
3+
4+
echo "=== Cleaning up Security Groups ==="
5+
openstack security group list -f value -c ID -c Name | grep -E "(hcp|k8s-cluster.*e2e)" | awk '{print $1}' | xargs -I {} openstack security group delete {}
6+
7+
echo "=== Cleaning up Load Balancers ==="
8+
openstack loadbalancer list -f value -c id -c name | grep -E "(hcp|e2e)" | awk '{print $1}' | xargs -I {} openstack loadbalancer delete {} || true
9+
10+
echo "=== Cleaning up Routers ==="
11+
openstack router list -f value -c ID -c Name | grep -E "(hcp|e2e)" | while read router_id router_name; do
12+
echo "Cleaning router: $router_name ($router_id)"
13+
# Remove external gateway
14+
openstack router unset --external-gateway $router_id 2>/dev/null || true
15+
# Remove all ports
16+
openstack port list --router $router_id -f value -c ID | xargs -I {} openstack router remove port $router_id {} 2>/dev/null || true
17+
# Delete router
18+
openstack router delete $router_id
19+
done
20+
21+
echo "=== Cleaning up Subnets ==="
22+
openstack subnet list -f value -c ID -c Name | grep -E "(hcp|e2e)" | awk '{print $1}' | xargs -I {} openstack subnet delete {}
23+
24+
echo "=== Cleaning up Networks ==="
25+
openstack network list -f value -c ID -c Name | grep -E "(hcp|e2e)" | awk '{print $1}' | xargs -I {} openstack network delete {}
26+
27+
echo "=== Cleaning up Floating IPs ==="
28+
openstack floating ip list -f value -c ID -c Description | grep -E "(hcp|e2e|cluster)" | awk '{print $1}' | xargs -I {} openstack floating ip delete {} || true
29+
30+
echo "=== Cleanup Complete ==="

hcp-test-vars.sh

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/bin/bash
2+
# Complete environment variables for CAPO HCP testing
3+
# Usage: source hcp-test-vars.sh && make test-hcp
4+
5+
# CRITICAL: Kubernetes version must match your image
6+
# Check your ubuntu-22.04 image and set accordingly (probably v1.28.x, v1.29.x, or v1.30.x)
7+
export KUBERNETES_VERSION="v1.30.2" # CHANGE THIS to match your image's k8s version
8+
9+
# OpenStack Configuration
10+
export OPENSTACK_CLOUD="openstack"
11+
export OPENSTACK_CLOUD_ADMIN="openstack" # Same as OPENSTACK_CLOUD for most setups
12+
export OPENSTACK_CLOUD_YAML_FILE="/Users/bnr/work/openstack/clouds.yaml"
13+
14+
# Image Configuration - Use existing image with dummy URLs to pass validation
15+
export OPENSTACK_IMAGE_NAME="ubuntu-2404-kube-v1.33.1"
16+
export OPENSTACK_IMAGE_URL="file:///dev/null" # Dummy URL - image already exists
17+
export OPENSTACK_BASTION_IMAGE_NAME="ubuntu-2404-kube-v1.33.1" # Use same image for bastion
18+
export OPENSTACK_BASTION_IMAGE_URL="file:///dev/null" # Dummy URL - image already exists
19+
20+
# Flavor Configuration - ADJUST based on your OpenStack
21+
export OPENSTACK_CONTROL_PLANE_MACHINE_FLAVOR="m1.medium"
22+
export OPENSTACK_NODE_MACHINE_FLAVOR="m1.small"
23+
export OPENSTACK_BASTION_MACHINE_FLAVOR="m1.small"
24+
25+
# Network Configuration - ADJUST based on your OpenStack
26+
export OPENSTACK_EXTERNAL_NETWORK_NAME="public" # Check: openstack network list --external
27+
export OPENSTACK_DNS_NAMESERVERS="8.8.8.8" # or your preferred DNS
28+
export OPENSTACK_FAILURE_DOMAIN="nova" # Check: openstack availability zone list
29+
30+
# SSH Key - CRITICAL
31+
export OPENSTACK_SSH_KEY_NAME="cluster-api-provider-openstack-sigs-k8s-io" # Must exist in OpenStack
32+
33+
# HCP Specific Configuration
34+
export KAMAJI_VERSION="v0.15.3" # Stable version instead of edge
35+
export KAMAJI_NAMESPACE="kamaji-system"
36+
export CLUSTER_DATASTORE="default"
37+
export HCP_SERVICE_TYPE="LoadBalancer"
38+
export HCP_CPU_LIMIT="1000m"
39+
export HCP_MEMORY_LIMIT="1Gi"
40+
export HCP_CPU_REQUEST="100m"
41+
export HCP_MEMORY_REQUEST="300Mi"
42+
43+
# Test Configuration
44+
export E2E_GINKGO_FOCUS="Management cluster verification"
45+
46+
# Timeout adjustments for slower environments
47+
export GINKGO_ARGS="-v --progress --timeout=45m"
48+
49+
echo "✅ Environment variables set for HCP testing"
50+
echo "🔍 Key settings:"
51+
echo " Kubernetes Version: $KUBERNETES_VERSION"
52+
echo " Image Name: $OPENSTACK_IMAGE_NAME"
53+
echo " Control Plane Flavor: $OPENSTACK_CONTROL_PLANE_MACHINE_FLAVOR"
54+
echo " External Network: $OPENSTACK_EXTERNAL_NETWORK_NAME"
55+
echo " SSH Key: $OPENSTACK_SSH_KEY_NAME"
56+
echo ""
57+
echo "⚠️ VERIFY these match your OpenStack environment:"
58+
echo " 1. Check image exists: openstack image show $OPENSTACK_IMAGE_NAME"
59+
echo " 2. Check flavors exist: openstack flavor show $OPENSTACK_CONTROL_PLANE_MACHINE_FLAVOR"
60+
echo " 3. Check SSH key exists: openstack keypair show $OPENSTACK_SSH_KEY_NAME"
61+
echo " 4. Check external network: openstack network show $OPENSTACK_EXTERNAL_NETWORK_NAME"
62+
echo ""
63+
echo "🚀 Run: make test-hcp"

test/e2e/suites/hcp/README.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# HCP (Hosted Control Plane) E2E Tests
2+
3+
This directory contains end-to-end tests for Hosted Control Plane (HCP) functionality using Kamaji as the control plane provider.
4+
5+
## Overview
6+
7+
The HCP tests verify that:
8+
9+
1. **Management Cluster**: A traditional CAPO cluster can be configured to host control planes for other clusters
10+
2. **Workload Cluster**: Worker-only clusters can be created with external control planes managed by Kamaji
11+
3. **Graceful Failures**: Broken configurations fail gracefully without panics or nil pointer exceptions
12+
13+
## Test Structure
14+
15+
### Test Suites
16+
17+
- **Management Cluster Test**: Creates a CAPO cluster with HCP hosting capabilities
18+
- **Workload Cluster Test**: Creates worker-only clusters using KamajiControlPlane
19+
- **Graceful Failure Tests**: Validates error handling for broken configurations
20+
21+
### Test Flow
22+
23+
1. **Suite Setup**: Creates shared management cluster with Kamaji installed
24+
2. **Workload Tests**: Creates multiple workload clusters using the shared management cluster
25+
3. **Failure Tests**: Tests broken scenarios to ensure graceful error handling
26+
4. **Suite Cleanup**: Cleans up shared resources
27+
28+
## Running Tests
29+
30+
### Prerequisites
31+
32+
- OpenStack environment configured
33+
- `OPENSTACK_CLOUD_YAML_FILE` environment variable set
34+
- Docker installed ([[memory:2673423]])
35+
36+
### Run HCP Tests
37+
38+
```bash
39+
# Run all HCP tests
40+
make test-hcp
41+
42+
# Run with specific focus
43+
E2E_GINKGO_FOCUS="Management cluster" make test-hcp
44+
45+
# Run with existing cluster
46+
E2E_ARGS="-use-existing-cluster=true" make test-hcp
47+
```
48+
49+
### Test Configuration
50+
51+
Tests use the same configuration as other e2e tests:
52+
- Config: `test/e2e/data/e2e_conf.yaml`
53+
- Templates: `test/e2e/data/kustomize/hcp-*`
54+
- Artifacts: `_artifacts/` directory
55+
56+
## Template Structure
57+
58+
### HCP Management (`hcp-management`)
59+
- Traditional CAPO cluster with larger worker nodes
60+
- Additional security rules for hosting control planes
61+
- Kamaji installation and configuration
62+
63+
### HCP Workload (`hcp-workload`)
64+
- Worker-only cluster configuration
65+
- Uses `KamajiControlPlane` instead of `KubeadmControlPlane`
66+
- Different network CIDRs to avoid conflicts
67+
68+
### HCP Broken (`hcp-broken`)
69+
- Intentionally broken networking configuration
70+
- Used to test graceful failure scenarios
71+
72+
## Test Intervals
73+
74+
HCP tests use dedicated intervals defined in `e2e_conf.yaml`:
75+
76+
```yaml
77+
intervals:
78+
hcp/wait-kamaji-install: ["10m", "30s"]
79+
hcp/wait-kamaji-control-plane: ["15m", "30s"]
80+
hcp/wait-cluster: ["25m", "10s"]
81+
hcp/wait-control-plane: ["30m", "10s"]
82+
hcp/wait-worker-nodes: ["30m", "10s"]
83+
```
84+
85+
## Debugging
86+
87+
### Log Collection
88+
Logs are automatically collected in `_artifacts/clusters/` for failed tests.
89+
90+
### Manual Debug
91+
Use the `skip-cleanup` flag to preserve resources for investigation:
92+
93+
```bash
94+
E2E_ARGS="-skip-cleanup=true" make test-hcp
95+
```
96+
97+
### Kamaji Resources
98+
Check Kamaji-specific resources:
99+
100+
```bash
101+
kubectl get kamajicontrolplane -A
102+
kubectl get datastore -A
103+
kubectl get -n kamaji-system pods
104+
```

0 commit comments

Comments
 (0)