Skip to content

Commit 10554f9

Browse files
[cozystack-scheduler] Publish SchedulingClass demo (#2252)
## What this PR does Publish the scripts used for running the Cozystack scheduler demo at the community meetup on 19.03.2026. ### Release note ```release-note [cozystack-scheduler] Add demo scripts to the cozystack-scheduler system packages. ``` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added a complete set of interactive Bash demo scripts covering scheduling classes: creating scheduling classes and tenants, colocating pods on a single node, spreading replicas evenly, enforcing one-pod-per-node anti-affinity, and pinning workloads to a specific node. * Included guided scaling steps plus cleanup and teardown scripts to remove demo resources. * **Documentation** * Introduced a shared demo helper with colored, step-by-step terminal logging and Kubernetes polling to wait for pods and Redis readiness, improving clarity and consistency across demos. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2 parents e16df56 + 337bb49 commit 10554f9

14 files changed

Lines changed: 951 additions & 0 deletions
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#!/bin/bash
2+
# Helper functions for the scheduling classes demo
3+
# Source this file in other scripts: source "$(dirname "$0")/00-helpers.sh"
4+
5+
# ANSI color codes
6+
export RED='\033[0;31m'
7+
export GREEN='\033[0;32m'
8+
export YELLOW='\033[1;33m'
9+
export BLUE='\033[0;34m'
10+
export MAGENTA='\033[0;35m'
11+
export CYAN='\033[0;36m'
12+
export WHITE='\033[1;37m'
13+
export NC='\033[0m' # No Color
14+
export BOLD='\033[1m'
15+
16+
log_info() {
17+
echo -e "${BLUE}ℹ${NC} $*" >&2
18+
}
19+
20+
log_success() {
21+
echo -e "${GREEN}✔${NC} $*" >&2
22+
}
23+
24+
log_warning() {
25+
echo -e "${YELLOW}⚠${NC} $*" >&2
26+
}
27+
28+
log_error() {
29+
echo -e "${RED}✖${NC} $*" >&2
30+
}
31+
32+
log_step() {
33+
echo -e "\n${MAGENTA}${BOLD}▶ $*${NC}" >&2
34+
}
35+
36+
log_command() {
37+
echo -e "${WHITE} \$ $*${NC}" >&2
38+
}
39+
40+
separator() {
41+
echo -e "\n${CYAN}────────────────────────────────────────────────────────────${NC}\n" >&2
42+
}
43+
44+
print_header() {
45+
local title="$1"
46+
echo -e "\n${MAGENTA}${BOLD}╔════════════════════════════════════════════════════════════╗${NC}" >&2
47+
echo -e "${MAGENTA}${BOLD}║${NC} ${WHITE}${BOLD}$title${NC}" >&2
48+
echo -e "${MAGENTA}${BOLD}╚════════════════════════════════════════════════════════════╝${NC}\n" >&2
49+
}
50+
51+
# Display a YAML manifest with syntax highlighting (just colored output)
52+
show_manifest() {
53+
echo -e "${YELLOW}$1${NC}" >&2
54+
}
55+
56+
# Wait for user to press any key
57+
pause() {
58+
echo -e "\n${CYAN}Press any key to continue...${NC}" >&2
59+
read -rsn1
60+
}
61+
62+
# Wait for pods to appear and stabilize
63+
wait_for_pods() {
64+
local namespace="$1"
65+
local label="${2:-}"
66+
local timeout="${3:-120}"
67+
local elapsed=0
68+
69+
log_info "Waiting for pods in $namespace..."
70+
while true; do
71+
local count
72+
if [[ -n "$label" ]]; then
73+
count=$(kubectl get pods -n "$namespace" -l "$label" --no-headers 2>/dev/null | wc -l)
74+
else
75+
count=$(kubectl get pods -n "$namespace" --no-headers 2>/dev/null | wc -l)
76+
fi
77+
if [[ "$count" -gt 0 ]]; then
78+
break
79+
fi
80+
if [[ $elapsed -ge $timeout ]]; then
81+
log_warning "Timed out waiting for pods"
82+
return 1
83+
fi
84+
sleep 2
85+
elapsed=$((elapsed + 2))
86+
done
87+
# Give pods a moment to get node assignments
88+
sleep 3
89+
}
90+
91+
# Show pods with node placement
92+
show_pods() {
93+
local namespace="$1"
94+
echo "" >&2
95+
kubectl get pods -n "$namespace" -o wide 2>&1 >&2
96+
echo "" >&2
97+
}
98+
99+
# Wait for a Redis resource to be ready (HelmRelease applied)
100+
wait_for_redis_ready() {
101+
local namespace="$1"
102+
local name="$2"
103+
local timeout="${3:-180}"
104+
local elapsed=0
105+
106+
log_info "Waiting for Redis $name in $namespace to become ready..."
107+
while true; do
108+
local phase
109+
phase=$(kubectl get redis "$name" -n "$namespace" -o jsonpath='{.status.conditions[0].status}' 2>/dev/null || echo "")
110+
if [[ "$phase" == "True" ]]; then
111+
log_success "Redis $name is ready"
112+
break
113+
fi
114+
if [[ $elapsed -ge $timeout ]]; then
115+
log_warning "Timed out waiting for Redis to be ready, continuing anyway..."
116+
break
117+
fi
118+
sleep 5
119+
elapsed=$((elapsed + 5))
120+
done
121+
}
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
#!/bin/bash
2+
# Script 01: Create SchedulingClasses
3+
set -euo pipefail
4+
5+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6+
source "$SCRIPT_DIR/00-helpers.sh"
7+
8+
print_header "Step 1: Create SchedulingClasses"
9+
10+
# --- pin-to-node2 ---
11+
log_step "SchedulingClass: pin-to-node2"
12+
log_info "All pods will always be scheduled to node2."
13+
14+
show_manifest "apiVersion: cozystack.io/v1alpha1
15+
kind: SchedulingClass
16+
metadata:
17+
name: pin-to-node2
18+
spec:
19+
nodeSelector:
20+
kubernetes.io/hostname: node2"
21+
22+
pause
23+
24+
kubectl apply -f - <<'EOF'
25+
apiVersion: cozystack.io/v1alpha1
26+
kind: SchedulingClass
27+
metadata:
28+
name: pin-to-node2
29+
spec:
30+
nodeSelector:
31+
kubernetes.io/hostname: node2
32+
EOF
33+
34+
log_success "Created SchedulingClass pin-to-node2"
35+
36+
separator
37+
38+
# --- one-per-node ---
39+
log_step "SchedulingClass: one-per-node"
40+
log_info "Pods of the same application will never share a node."
41+
42+
show_manifest "apiVersion: cozystack.io/v1alpha1
43+
kind: SchedulingClass
44+
metadata:
45+
name: one-per-node
46+
spec:
47+
podAntiAffinity:
48+
requiredDuringSchedulingIgnoredDuringExecution:
49+
- topologyKey: kubernetes.io/hostname"
50+
51+
pause
52+
53+
kubectl apply -f - <<'EOF'
54+
apiVersion: cozystack.io/v1alpha1
55+
kind: SchedulingClass
56+
metadata:
57+
name: one-per-node
58+
spec:
59+
podAntiAffinity:
60+
requiredDuringSchedulingIgnoredDuringExecution:
61+
- topologyKey: kubernetes.io/hostname
62+
EOF
63+
64+
log_success "Created SchedulingClass one-per-node"
65+
66+
separator
67+
68+
# --- spread-evenly ---
69+
log_step "SchedulingClass: spread-evenly"
70+
log_info "Pods will be spread evenly across nodes (maxSkew=1)."
71+
72+
show_manifest "apiVersion: cozystack.io/v1alpha1
73+
kind: SchedulingClass
74+
metadata:
75+
name: spread-evenly
76+
spec:
77+
topologySpreadConstraints:
78+
- maxSkew: 1
79+
topologyKey: kubernetes.io/hostname
80+
whenUnsatisfiable: DoNotSchedule"
81+
82+
pause
83+
84+
kubectl apply -f - <<'EOF'
85+
apiVersion: cozystack.io/v1alpha1
86+
kind: SchedulingClass
87+
metadata:
88+
name: spread-evenly
89+
spec:
90+
topologySpreadConstraints:
91+
- maxSkew: 1
92+
topologyKey: kubernetes.io/hostname
93+
whenUnsatisfiable: DoNotSchedule
94+
EOF
95+
96+
log_success "Created SchedulingClass spread-evenly"
97+
98+
separator
99+
100+
# --- colocate ---
101+
log_step "SchedulingClass: colocate"
102+
log_info "All pods of the same application will land on the same node."
103+
104+
show_manifest "apiVersion: cozystack.io/v1alpha1
105+
kind: SchedulingClass
106+
metadata:
107+
name: colocate
108+
spec:
109+
podAffinity:
110+
requiredDuringSchedulingIgnoredDuringExecution:
111+
- topologyKey: kubernetes.io/hostname"
112+
113+
pause
114+
115+
kubectl apply -f - <<'EOF'
116+
apiVersion: cozystack.io/v1alpha1
117+
kind: SchedulingClass
118+
metadata:
119+
name: colocate
120+
spec:
121+
podAffinity:
122+
requiredDuringSchedulingIgnoredDuringExecution:
123+
- topologyKey: kubernetes.io/hostname
124+
EOF
125+
126+
log_success "Created SchedulingClass colocate"
127+
128+
separator
129+
log_success "All SchedulingClasses created."
130+
log_command "kubectl get schedulingclasses"
131+
kubectl get schedulingclasses >&2
132+
133+
echo -e "\n${GREEN}${BOLD}Next step:${NC} ./02-create-tenants.sh"
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#!/bin/bash
2+
# Script 02: Create tenants, one per scheduling class
3+
set -euo pipefail
4+
5+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6+
source "$SCRIPT_DIR/00-helpers.sh"
7+
8+
print_header "Step 2: Create Tenants"
9+
10+
# --- tenant colocate ---
11+
log_step "Tenant: colocate (schedulingClass: colocate)"
12+
13+
show_manifest "apiVersion: apps.cozystack.io/v1alpha1
14+
kind: Tenant
15+
metadata:
16+
name: colocate
17+
namespace: tenant-root
18+
spec:
19+
schedulingClass: colocate"
20+
21+
pause
22+
23+
kubectl apply -f - <<'EOF'
24+
apiVersion: apps.cozystack.io/v1alpha1
25+
kind: Tenant
26+
metadata:
27+
name: colocate
28+
namespace: tenant-root
29+
spec:
30+
schedulingClass: colocate
31+
EOF
32+
33+
log_success "Created tenant colocate"
34+
35+
separator
36+
37+
# --- tenant onepernode ---
38+
log_step "Tenant: onepernode (schedulingClass: one-per-node)"
39+
40+
show_manifest "apiVersion: apps.cozystack.io/v1alpha1
41+
kind: Tenant
42+
metadata:
43+
name: onepernode
44+
namespace: tenant-root
45+
spec:
46+
schedulingClass: one-per-node"
47+
48+
pause
49+
50+
kubectl apply -f - <<'EOF'
51+
apiVersion: apps.cozystack.io/v1alpha1
52+
kind: Tenant
53+
metadata:
54+
name: onepernode
55+
namespace: tenant-root
56+
spec:
57+
schedulingClass: one-per-node
58+
EOF
59+
60+
log_success "Created tenant onepernode"
61+
62+
separator
63+
64+
# --- tenant spread ---
65+
log_step "Tenant: spread (schedulingClass: spread-evenly)"
66+
67+
show_manifest "apiVersion: apps.cozystack.io/v1alpha1
68+
kind: Tenant
69+
metadata:
70+
name: spread
71+
namespace: tenant-root
72+
spec:
73+
schedulingClass: spread-evenly"
74+
75+
pause
76+
77+
kubectl apply -f - <<'EOF'
78+
apiVersion: apps.cozystack.io/v1alpha1
79+
kind: Tenant
80+
metadata:
81+
name: spread
82+
namespace: tenant-root
83+
spec:
84+
schedulingClass: spread-evenly
85+
EOF
86+
87+
log_success "Created tenant spread"
88+
89+
separator
90+
91+
# --- tenant node2 ---
92+
log_step "Tenant: node2 (schedulingClass: pin-to-node2)"
93+
94+
show_manifest "apiVersion: apps.cozystack.io/v1alpha1
95+
kind: Tenant
96+
metadata:
97+
name: node2
98+
namespace: tenant-root
99+
spec:
100+
schedulingClass: pin-to-node2"
101+
102+
pause
103+
104+
kubectl apply -f - <<'EOF'
105+
apiVersion: apps.cozystack.io/v1alpha1
106+
kind: Tenant
107+
metadata:
108+
name: node2
109+
namespace: tenant-root
110+
spec:
111+
schedulingClass: pin-to-node2
112+
EOF
113+
114+
log_success "Created tenant node2"
115+
116+
separator
117+
log_success "All tenants created."
118+
log_command "kubectl get tenants -n tenant-root"
119+
kubectl get tenants -n tenant-root >&2
120+
121+
echo -e "\n${GREEN}${BOLD}Next step:${NC} ./03-colocate-demo.sh"

0 commit comments

Comments
 (0)