-
Notifications
You must be signed in to change notification settings - Fork 0
Test out a more sophisticated approach to the readiness probe #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: Role | ||
| metadata: | ||
| name: valkey-pod-reader | ||
| namespace: system | ||
| rules: | ||
| - apiGroups: [""] | ||
| resources: ["pods"] | ||
| verbs: ["get", "list"] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: RoleBinding | ||
| metadata: | ||
| name: valkey-pod-reader-binding | ||
| namespace: system | ||
| roleRef: | ||
| apiGroup: rbac.authorization.k8s.io | ||
| kind: Role | ||
| name: valkey-pod-reader | ||
| subjects: | ||
| - kind: ServiceAccount | ||
| name: valkey-pod | ||
| namespace: system |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| apiVersion: v1 | ||
| kind: ServiceAccount | ||
| metadata: | ||
| name: valkey-pod | ||
| namespace: system |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,124 @@ | ||||||
| #!/bin/bash | ||||||
|
|
||||||
| # Valkey Node Startup Check for Kubernetes | ||||||
| # Returns 0 (started) if any of these conditions are met: | ||||||
| # 1. Cluster state is "ok" | ||||||
| # 2. Node has zero slots allocated | ||||||
| # 3. Node doesn't know about any other nodes (single node) | ||||||
| # 4. 300 seconds have elapsed since pod started | ||||||
|
|
||||||
| set -x | ||||||
|
|
||||||
| # shellcheck source=./utils.sh | ||||||
| . /scripts/utils.sh | ||||||
|
|
||||||
| # Configuration | ||||||
| TIMEOUT_SECONDS="${TIMEOUT_SECONDS:-300}" | ||||||
|
|
||||||
| # Function to check if timeout has elapsed since Valkey started | ||||||
| check_timeout() { | ||||||
| local info_output | ||||||
| info_output=$(valkey_cli 127.0.0.1 6379 -t 1 -c INFO server 2>/dev/null || echo "") | ||||||
|
|
||||||
| # Extract uptime_in_seconds from INFO output | ||||||
| local uptime | ||||||
| uptime=$(echo "$info_output" | grep "^uptime_in_seconds:" | cut -d: -f2 | tr -d '\r') | ||||||
|
|
||||||
| if [ -z "$uptime" ]; then | ||||||
| echo "Warning: Could not retrieve Valkey uptime" >&2 | ||||||
| return 1 | ||||||
| fi | ||||||
|
|
||||||
| if [ "$uptime" -ge $TIMEOUT_SECONDS ]; then | ||||||
| echo "Startup check passed: Valkey uptime of ${uptime}s exceeds timeout of ${TIMEOUT_SECONDS}s" | ||||||
| return 0 | ||||||
| fi | ||||||
| return 1 | ||||||
| } | ||||||
|
|
||||||
| # Function to check cluster state | ||||||
| check_cluster_state() { | ||||||
| local cluster_info | ||||||
| cluster_info=$(valkey_cli 127.0.0.1 6379 -t 1 -c CLUSTER INFO 2>/dev/null || echo "") | ||||||
|
|
||||||
| if echo "$cluster_info" | grep -q "cluster_state:ok"; then | ||||||
| echo "Startup check passed: cluster state is ok" | ||||||
| return 0 | ||||||
| fi | ||||||
| return 1 | ||||||
| } | ||||||
|
|
||||||
| # Function to check slot allocation | ||||||
| check_slots() { | ||||||
| local nodes_info | ||||||
| nodes_info=$(valkey_cli 127.0.0.1 6379 -t 1 -c CLUSTER NODES 2>/dev/null || echo "") | ||||||
|
|
||||||
| # Find the current node (marked with "myself") | ||||||
| local myself_line | ||||||
| myself_line=$(echo "$nodes_info" | grep "myself" || echo "") | ||||||
|
|
||||||
| if [ -z "$myself_line" ]; then | ||||||
| echo "Warning: Could not find current node in cluster nodes output" >&2 | ||||||
| return 1 | ||||||
| fi | ||||||
|
|
||||||
| # Check if the line contains any slot ranges (format: [slot-slot] or single slots) | ||||||
| # Slots appear after the address and flags, typically after the 8th field | ||||||
| if ! echo "$myself_line" | grep -qE '\[?[0-9]+-?[0-9]*\]?'; then | ||||||
|
||||||
| if ! echo "$myself_line" | grep -qE '\[?[0-9]+-?[0-9]*\]?'; then | |
| if ! echo "$myself_line" | grep -qE '\b[0-9]+-[0-9]+\b|\b[0-9]+\b'; then |
Copilot
AI
Oct 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pattern \"^\" matches every line including empty lines. This could produce incorrect counts if there are blank lines in the output. Use grep -c . or wc -l on non-empty output instead.
| node_count=$(echo "$nodes_info" | grep -c "^") | |
| node_count=$(echo "$nodes_info" | grep -c .) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing quotes around variable expansion. Should be
\"$TIMEOUT_SECONDS\"to prevent potential issues if the variable contains spaces or special characters.