Skip to content

Commit 95af596

Browse files
author
sivakami
committed
Create pod objects.
1 parent b7b7eb0 commit 95af596

File tree

6 files changed

+233
-32
lines changed

6 files changed

+233
-32
lines changed

.pipelines/swiftv2-long-running/scripts/create_aks.sh

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,31 @@ for i in $(seq 1 "$CLUSTER_COUNT"); do
4444
AZCLI=az REGION=$LOCATION \
4545
SUB=$SUBSCRIPTION_ID \
4646
GROUP=$RG \
47-
CLUSTER=$CLUSTER_NAME \
48-
# NODE_COUNT=$DEFAULT_NODE_COUNT \
49-
# VM_SIZE=$VM_SKU_DEFAULT \
47+
CLUSTER=$CLUSTER_NAME
5048

5149
echo " - waiting for AKS provisioning state..."
5250
wait_for_provisioning "$RG" "$CLUSTER_NAME"
5351

52+
5453
echo "Adding multi-tenant nodepool ' to '$CLUSTER_NAME'"
5554
make -C ./hack/aks linux-swiftv2-nodepool-up \
5655
AZCLI=az REGION=$LOCATION \
5756
GROUP=$RG \
5857
VM_SIZE=$VM_SKU_HIGHNIC \
5958
CLUSTER=$CLUSTER_NAME \
60-
SUB=$SUBSCRIPTION_ID \
59+
SUB=$SUBSCRIPTION_ID
60+
61+
KUBECONFIG_PATH="/tmp/${CLUSTER_NAME}.kubeconfig"
62+
echo "Exporting admin kubeconfig for '$CLUSTER_NAME' to ${KUBECONFIG_PATH}..."
63+
64+
az aks get-credentials \
65+
--resource-group "$RG" \
66+
--name "$CLUSTER_NAME" \
67+
--overwrite-existing \
68+
--admin \
69+
--file "$KUBECONFIG_PATH"
70+
71+
echo "Kubeconfig saved: ${KUBECONFIG_PATH}"
6172

6273
done
6374
echo "All done. Created $CLUSTER_COUNT cluster set(s)."

.pipelines/swiftv2-long-running/scripts/create_pn.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ if [[ -z "$KUBECONFIG_PATH" || -z "$POD_NETWORK_NAME" || -z "$VNET_GUID" || -z "
1616
fi
1717

1818
# === STEP 2: Build PodNetwork YAML ===
19+
export KUBECONFIG=$KUBECONFIG_PATH
1920
TMPFILE=$(mktemp)
2021

2122
if [[ -n "$SUBNET_TOKEN" ]]; then
@@ -47,7 +48,7 @@ fi
4748

4849
# === STEP 3: Apply the PodNetwork CRD ===
4950
echo "Creating PodNetwork ${POD_NETWORK_NAME}..."
50-
kubectl --kubeconfig="$KUBECONFIG_PATH" apply -f "$TMPFILE" || true
51+
kubectl apply -f "$TMPFILE" || true
5152

5253
# === STEP 4: Wait until the CRD becomes Ready (if subnetToken not provided) ===
5354
if [[ -z "$SUBNET_TOKEN" ]]; then

.pipelines/swiftv2-long-running/scripts/create_pni.sh

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,22 @@ PNI_NAME=$3
1616
POD_NETWORK_NAME=$4
1717
PNI_TYPE=$5 # "explicit" or "implicit"
1818
RESERVATIONS=${6:-0} # only used for explicit
19-
DEFAULT_DENY=${7:-false} # true or false
2019

2120
export KUBECONFIG=$KUBECONFIG_PATH
2221

23-
echo "🔧 Creating PodNetworkInstance:"
22+
if ! kubectl get namespace "$NAMESPACE" >/dev/null 2>&1; then
23+
echo "Namespace '$NAMESPACE' not found. Creating it..."
24+
kubectl create namespace "$NAMESPACE"
25+
else
26+
echo "Namespace '$NAMESPACE' already exists."
27+
fi
28+
29+
echo "Creating PodNetworkInstance:"
2430
echo " Namespace: $NAMESPACE"
2531
echo " Name: $PNI_NAME"
2632
echo " Network: $POD_NETWORK_NAME"
2733
echo " Type: $PNI_TYPE"
2834
echo " Reservations: $RESERVATIONS"
29-
echo " Default Deny: $DEFAULT_DENY"
3035
echo
3136

3237
# --- Apply PNI manifest ---
@@ -41,7 +46,6 @@ spec:
4146
podNetworkConfigs:
4247
- podNetwork: $POD_NETWORK_NAME
4348
podIPReservationSize: $RESERVATIONS
44-
defaultDenyACL: $DEFAULT_DENY
4549
EOF
4650
else
4751
cat <<EOF | kubectl apply -f -
@@ -53,14 +57,13 @@ metadata:
5357
spec:
5458
podNetworkConfigs:
5559
- podNetwork: $POD_NETWORK_NAME
56-
defaultDenyACL: $DEFAULT_DENY
5760
EOF
5861
fi
5962

6063
echo "PodNetworkInstance '$PNI_NAME' applied."
6164

6265
# --- Wait for readiness ---
63-
echo "Waiting for PodNetworkInstance '$PNI_NAME' to become Ready..."
66+
echo "Waiting for PodNetworkInstance '$PNI_NAME' to become Ready..."
6467

6568
MAX_ATTEMPTS=30
6669
SLEEP_INTERVAL=10
Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,60 @@
11
#!/bin/bash
22
# Usage:
3-
# ./create_pod.sh <RESOURCE_GROUP> <CLUSTER_NAME> <NAMESPACE> <POD_NAME> <NODE_NAME> [IMAGE]
3+
# ./create_pod.sh <POD_NAME> <NODE_NAME> <OS> <PN_NAME> <PNI_NAME> [IMAGE]
4+
# Example:
5+
# ./create_pod.sh netpod1 aks-node1 linux podnet-a pni-exp praqma/network-multitool
46

57
set -euo pipefail
68

7-
RESOURCE_GROUP=$1
8-
CLUSTER_NAME=$2
9-
NAMESPACE=$3
10-
POD_NAME=$4
11-
NODE_NAME=$5
12-
IMAGE=${6:-nginx}
13-
14-
echo "Getting AKS credentials..."
15-
az aks get-credentials -g "$RESOURCE_GROUP" -n "$CLUSTER_NAME" --overwrite-existing
16-
17-
echo "Creating namespace (if not exists)..."
18-
kubectl get ns "$NAMESPACE" >/dev/null 2>&1 || kubectl create ns "$NAMESPACE"
9+
POD_NAME=$1
10+
NODE_NAME=$2
11+
OS=$3
12+
PN_NAME=$4
13+
PNI_NAME=$5
14+
IMAGE=${6:-weibeld/ubuntu-networking}
15+
KUBECONFIG_PATH=$7
1916

2017
echo "Creating pod '$POD_NAME' on node '$NODE_NAME' using image '$IMAGE'..."
18+
echo "PodNetwork: $PN_NAME, PodNetworkInstance: $PNI_NAME, OS: $OS"
2119

20+
export KUBECONFIG=$KUBECONFIG_PATH
2221
cat <<EOF | kubectl apply -f -
2322
apiVersion: v1
2423
kind: Pod
2524
metadata:
2625
name: $POD_NAME
27-
namespace: $NAMESPACE
2826
labels:
29-
app: $POD_NAME
27+
kubernetes.azure.com/pod-network-instance: $PNI_NAME
28+
kubernetes.azure.com/pod-network: $PN_NAME
3029
spec:
30+
nodeName: $NODE_NAME
3131
nodeSelector:
32-
kubernetes.io/hostname: $NODE_NAME
32+
kubernetes.io/os: $OS
3333
containers:
34-
- name: main
34+
- name: net-debugger
3535
image: $IMAGE
36-
command: ["sleep", "3600"]
37-
imagePullPolicy: IfNotPresent
36+
command: ["/bin/sh", "-c"]
37+
args:
38+
- |
39+
echo "Pod Network Diagnostics started on \$(hostname)";
40+
echo "----------------------------------------------";
41+
while true; do
42+
echo "[$(date)] Running net tests...";
43+
ip addr show;
44+
ip route show;
45+
sleep 60;
46+
done
47+
resources:
48+
limits:
49+
cpu: 300m
50+
memory: 600Mi
51+
requests:
52+
cpu: 300m
53+
memory: 600Mi
54+
securityContext:
55+
privileged: true
3856
restartPolicy: Always
3957
EOF
4058

41-
echo "Pod '$POD_NAME' created successfully in namespace '$NAMESPACE'."
42-
kubectl get pod "$POD_NAME" -n "$NAMESPACE" -o wide
59+
echo "Pod '$POD_NAME' created successfully."
60+
kubectl get pod "$POD_NAME" -o wide
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# --------------------------
5+
# Parameters / Environment
6+
# --------------------------
7+
RG=$1
8+
BUILD_ID=$2
9+
10+
# Clusters
11+
CLUSTER1="aks-1"
12+
CLUSTER2="aks-2"
13+
14+
# VNet/Subnet mappings for test
15+
declare -A VN_SUB_MAP
16+
VN_SUB_MAP["vnet_a1"]="s1 s2"
17+
VN_SUB_MAP["vnet_a2"]="s1"
18+
VN_SUB_MAP["vnet_a3"]="s1"
19+
VN_SUB_MAP["vnet_b1"]="s1"
20+
21+
# PN/PNI base names
22+
PN_PREFIX="pn-${BUILD_ID}"
23+
PNI_PREFIX="pni-${BUILD_ID}"
24+
25+
source ./helpers_network_ids.sh
26+
27+
# Create PodNetwork in a specific cluster
28+
create_pn() {
29+
local cluster_context=$1 # kubeconfig or context name
30+
local pn_name=$2 # PodNetwork name
31+
local vnet_name=$3
32+
local subnet_name=$4
33+
34+
echo "=== Creating PodNetwork ${pn_name} in cluster ${cluster_context} ==="
35+
36+
# --- Fetch IDs ---
37+
VNET_GUID=$(get_vnet_guid "$RG" "$vnet_name")
38+
SUBNET_ARM_ID=$(get_subnet_arm_id "$RG" "$vnet_name" "$subnet_name")
39+
SUBNET_GUID=$(get_subnet_guid "$RG" "$vnet_name" "$subnet_name")
40+
41+
echo "VNET_GUID: $VNET_GUID"
42+
echo "SUBNET_GUID: $SUBNET_GUID"
43+
echo "SUBNET_ARM_ID: $SUBNET_ARM_ID"
44+
45+
# --- Create PodNetwork ---
46+
./create_pn.sh \
47+
"$cluster_context" \
48+
"$pn_name" \
49+
"$VNET_GUID" \
50+
"$SUBNET_GUID" \
51+
"$SUBNET_ARM_ID"
52+
53+
echo "PodNetwork ${pn_name} submitted successfully."
54+
}
55+
56+
57+
create_pni() {
58+
local KUBECONFIG_PATH=$1
59+
local NAMESPACE=$2
60+
local pni_name=$3
61+
local pod_network_name=$4
62+
local pni_type=$5
63+
local reservations=${6:-0}
64+
local cluster=$7
65+
66+
echo "Creating PodNetworkInstance $pni_name for PN $pod_network_name on $cluster"
67+
./create_pni.sh "$KUBECONFIG_PATH" "$NAMESPACE" "$pni_name" "$pod_network_name" "$pni_type" "$reservations" "$cluster"
68+
}
69+
70+
create_pod_on_node() {
71+
local cluster="$1"
72+
local pn_name="$2"
73+
local pni_name="$3"
74+
local node_name="$4"
75+
local pod_name="$5"
76+
77+
KUBECONFIG_PATH="/tmp/${cluster}.kubeconfig"
78+
echo "Creating pod '$pod_name' on node '$node_name' (PN: $pn_name, PNI: $pni_name)..."
79+
./create_pod.sh "$pod_name" "$node_name" "linux" "$pn_name" "$pni_name" "weibeld/ubuntu-networking" "$KUBECONFIG_PATH"
80+
}
81+
82+
get_nodes() {
83+
local cluster=$1
84+
kubectl --context "$cluster" get nodes -o name | sed 's|node/||'
85+
}
86+
87+
88+
# --- Part 1: Customer2 in aks-2 / vnet_b1/s1 ---
89+
PN_C2="${PN_PREFIX}-c2"
90+
PNI_C2="${PNI_PREFIX}-c2"
91+
92+
create_pn "/tmp/${CLUSTER2}.kubeconfig" "$PN_C2" "vnet_b1" "s1"
93+
create_pni "/tmp/${CLUSTER2}.kubeconfig" "$PN_C2" "$PNI_C2" "$PN_C2" "explicit" "2" "$CLUSTER2"
94+
95+
# Create 2 pods for Customer2, one per node in aks-2
96+
NODES_CLUSTER2=($(get_nodes "$CLUSTER2"))
97+
for i in 0 1; do
98+
POD_NAME="pod-c2-$i"
99+
NODE_NAME="${NODES_CLUSTER2[$i]}"
100+
create_pod_on_node "$CLUSTER2" "$PN_C2" "$PNI_C2" "$NODE_NAME" "$POD_NAME"
101+
done
102+
103+
# # --- Part 2: Other PNs/PNIs across multiple subnets ---
104+
# PN_LIST=()
105+
# PNI_LIST=()
106+
107+
# for vnet in "${!VN_SUB_MAP[@]}"; do
108+
# for subnet in ${VN_SUB_MAP[$vnet]}; do
109+
# PN_NAME="${PN_PREFIX}-${vnet}-${subnet}"
110+
# PNI_NAME="${PNI_PREFIX}-${vnet}-${subnet}"
111+
# PN_LIST+=("$PN_NAME")
112+
# PNI_LIST+=("$PNI_NAME")
113+
# # Assume cluster selection: default to aks-1 unless aks-2 needs pods
114+
# CLUSTER="$CLUSTER1"
115+
# create_pn "$CLUSTER" "$PN_NAME"
116+
# create_pni "$CLUSTER" "$PNI_NAME" "$PN_NAME" "$vnet" "$subnet"
117+
# done
118+
# done
119+
120+
# # --- Part 3: Create 6 pods under these PN/PNI ---
121+
# # 4 pods go to aks-1 nodes, 2 pods go to remaining aks-2 nodes
122+
123+
# # Get node lists
124+
# NODES_CLUSTER1=($(get_nodes "$CLUSTER1"))
125+
# NODES_CLUSTER2=($(get_nodes "$CLUSTER2"))
126+
127+
# # 4 pods in aks-1, assign one per node
128+
# for i in 0 1 2 3; do
129+
# POD_NAME="pod-${BUILD_ID}-c1-$i"
130+
# PN_IDX=$((i % ${#PN_LIST[@]}))
131+
# create_pod_on_node "$CLUSTER1" "${PN_LIST[$PN_IDX]}" "${PNI_LIST[$PN_IDX]}" "${NODES_CLUSTER1[$i]}" "$POD_NAME"
132+
# done
133+
134+
# # Remaining 2 pods in aks-2, assign to leftover nodes
135+
# for i in 0 1; do
136+
# POD_NAME="pod-${BUILD_ID}-c2-$i"
137+
# PN_IDX=$(( (i+4) % ${#PN_LIST[@]} ))
138+
# NODE_IDX=$i
139+
# create_pod_on_node "$CLUSTER2" "${PN_LIST[$PN_IDX]}" "${PNI_LIST[$PN_IDX]}" "${NODES_CLUSTER2[$NODE_IDX]}" "$POD_NAME"
140+
# done
141+
142+
# echo "Datapath test pods created successfully."

.pipelines/swiftv2-long-running/template/long-running-pipeline-template.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,29 @@ stages:
140140
${{ parameters.location }}
141141
${{ parameters.resourceGroupName }}
142142
$(CreateStorageAccounts.StorageAccount1)
143+
# =================================================================
144+
# Stage 2: Datapath Tests
145+
# =================================================================
146+
- stage: DataPathTests
147+
displayName: "Stage: Swiftv2 Data Path Tests"
148+
dependsOn: AKSClusterAndNetworking
149+
condition: succeeded()
150+
jobs:
151+
- job: RunDataPathTests
152+
displayName: "Run PodNetwork and Data Path Tests"
153+
timeoutInMinutes: 0 # Run indefinitely
154+
pool:
155+
vmImage: ubuntu-latest
156+
steps:
157+
- checkout: self
158+
159+
- task: AzureCLI@2
160+
displayName: "Run datapath_tests.sh to create PN, PNI, and pods"
161+
inputs:
162+
azureSubscription: ${{ parameters.serviceConnection }}
163+
scriptType: bash
164+
scriptLocation: scriptPath
165+
scriptPath: ".pipelines/swiftv2-long-running/scripts/datapath_tests.sh"
166+
arguments: >
167+
${{ parameters.resourceGroupName }}
168+
$(Build.BuildId)

0 commit comments

Comments
 (0)