cronjobs.yaml (11530B)
1 # Common env vars injected into every k6 TestRun runner via the CronJob shell scripts: 2 # K6_PROMETHEUS_RW_SERVER_URL — pushes metrics to Prometheus remote-write receiver 3 # K6_PROMETHEUS_RW_STALE_MARKERS — marks stale series when the test ends 4 # BASE_URL — connectivity-tester-stage internal cluster address 5 # 6 # SERVER_NAMES is intentionally NOT set; config.js default (mtrnord.blog) is used. 7 # 8 # cleanup: "post" on every TestRun tells the operator to delete the TestRun object 9 # after all pods complete, so stale objects don't accumulate even if the CronJob 10 # pod crashes before it can run its own kubectl delete at the end. 11 --- 12 # ── Smoke: every 5 minutes, ~10 s, sanity check all endpoints ────────────── 13 apiVersion: batch/v1 14 kind: CronJob 15 metadata: 16 name: k6-smoke 17 namespace: k6-operator 18 spec: 19 schedule: "*/5 * * * *" 20 concurrencyPolicy: Forbid 21 successfulJobsHistoryLimit: 3 22 failedJobsHistoryLimit: 3 23 jobTemplate: 24 spec: 25 ttlSecondsAfterFinished: 3600 26 template: 27 spec: 28 serviceAccountName: k6-cronjob 29 restartPolicy: OnFailure 30 securityContext: 31 runAsNonRoot: true 32 runAsUser: 65534 33 runAsGroup: 65534 34 seccompProfile: 35 type: RuntimeDefault 36 containers: 37 - name: runner 38 image: docker.io/alpine/k8s:1.32.3 39 securityContext: 40 allowPrivilegeEscalation: false 41 capabilities: 42 drop: 43 - ALL 44 command: 45 - /bin/sh 46 - -c 47 - | 48 set -e 49 NAME="k6-smoke-$(date +%s)" 50 kubectl -n matrix apply -f - << EOF 51 apiVersion: k6.io/v1alpha1 52 kind: TestRun 53 metadata: 54 name: ${NAME} 55 namespace: matrix 56 spec: 57 parallelism: 1 58 cleanup: "post" 59 script: 60 configMap: 61 name: k6-scripts 62 file: smoke.js 63 arguments: --out experimental-prometheus-rw 64 runner: 65 env: 66 - name: K6_PROMETHEUS_RW_SERVER_URL 67 value: http://prometheus-operated.monitoring.svc.cluster.local:9090/api/v1/write 68 - name: K6_PROMETHEUS_RW_STALE_MARKERS 69 value: "true" 70 - name: BASE_URL 71 value: http://connectivity-tester-stage.matrix.svc.cluster.local:8080 72 EOF 73 TIMEOUT=300 74 START=$(date +%s) 75 while true; do 76 STAGE=$(kubectl -n matrix get testrun/"${NAME}" -o jsonpath='{.status.stage}' 2>/dev/null) || break 77 echo "Stage: ${STAGE}" 78 case "${STAGE}" in finished|error) break ;; esac 79 [ $(($(date +%s) - START)) -ge ${TIMEOUT} ] && { echo "Timed out"; break; } 80 sleep 10 81 done 82 kubectl -n matrix delete testrun/"${NAME}" --ignore-not-found 83 --- 84 # ── Health: every 30 minutes, 30 s, /healthz load baseline ───────────────── 85 apiVersion: batch/v1 86 kind: CronJob 87 metadata: 88 name: k6-health 89 namespace: k6-operator 90 spec: 91 schedule: "*/30 * * * *" 92 concurrencyPolicy: Forbid 93 successfulJobsHistoryLimit: 3 94 failedJobsHistoryLimit: 3 95 jobTemplate: 96 spec: 97 ttlSecondsAfterFinished: 3600 98 template: 99 spec: 100 serviceAccountName: k6-cronjob 101 restartPolicy: OnFailure 102 securityContext: 103 runAsNonRoot: true 104 runAsUser: 65534 105 runAsGroup: 65534 106 seccompProfile: 107 type: RuntimeDefault 108 containers: 109 - name: runner 110 image: docker.io/alpine/k8s:1.32.3 111 securityContext: 112 allowPrivilegeEscalation: false 113 capabilities: 114 drop: 115 - ALL 116 command: 117 - /bin/sh 118 - -c 119 - | 120 set -e 121 NAME="k6-health-$(date +%s)" 122 kubectl -n matrix apply -f - << EOF 123 apiVersion: k6.io/v1alpha1 124 kind: TestRun 125 metadata: 126 name: ${NAME} 127 namespace: matrix 128 spec: 129 parallelism: 1 130 cleanup: "post" 131 script: 132 configMap: 133 name: k6-scripts 134 file: health.js 135 arguments: --out experimental-prometheus-rw 136 runner: 137 env: 138 - name: K6_PROMETHEUS_RW_SERVER_URL 139 value: http://prometheus-operated.monitoring.svc.cluster.local:9090/api/v1/write 140 - name: K6_PROMETHEUS_RW_STALE_MARKERS 141 value: "true" 142 - name: BASE_URL 143 value: http://connectivity-tester-stage.matrix.svc.cluster.local:8080 144 EOF 145 TIMEOUT=300 146 START=$(date +%s) 147 while true; do 148 STAGE=$(kubectl -n matrix get testrun/"${NAME}" -o jsonpath='{.status.stage}' 2>/dev/null) || break 149 echo "Stage: ${STAGE}" 150 case "${STAGE}" in finished|error) break ;; esac 151 [ $(($(date +%s) - START)) -ge ${TIMEOUT} ] && { echo "Timed out"; break; } 152 sleep 10 153 done 154 kubectl -n matrix delete testrun/"${NAME}" --ignore-not-found 155 --- 156 # ── Federation: every 30 minutes, ~60 s, 3+5 VUs across two scenarios ────── 157 apiVersion: batch/v1 158 kind: CronJob 159 metadata: 160 name: k6-federation 161 namespace: k6-operator 162 spec: 163 schedule: "15,45 * * * *" 164 concurrencyPolicy: Forbid 165 successfulJobsHistoryLimit: 3 166 failedJobsHistoryLimit: 3 167 jobTemplate: 168 spec: 169 ttlSecondsAfterFinished: 3600 170 template: 171 spec: 172 serviceAccountName: k6-cronjob 173 restartPolicy: OnFailure 174 securityContext: 175 runAsNonRoot: true 176 runAsUser: 65534 177 runAsGroup: 65534 178 seccompProfile: 179 type: RuntimeDefault 180 containers: 181 - name: runner 182 image: docker.io/alpine/k8s:1.32.3 183 securityContext: 184 allowPrivilegeEscalation: false 185 capabilities: 186 drop: 187 - ALL 188 command: 189 - /bin/sh 190 - -c 191 - | 192 set -e 193 NAME="k6-federation-$(date +%s)" 194 kubectl -n matrix apply -f - << EOF 195 apiVersion: k6.io/v1alpha1 196 kind: TestRun 197 metadata: 198 name: ${NAME} 199 namespace: matrix 200 spec: 201 parallelism: 1 202 cleanup: "post" 203 script: 204 configMap: 205 name: k6-scripts 206 file: federation.js 207 arguments: --out experimental-prometheus-rw 208 runner: 209 env: 210 - name: K6_PROMETHEUS_RW_SERVER_URL 211 value: http://prometheus-operated.monitoring.svc.cluster.local:9090/api/v1/write 212 - name: K6_PROMETHEUS_RW_STALE_MARKERS 213 value: "true" 214 - name: BASE_URL 215 value: http://connectivity-tester-stage.matrix.svc.cluster.local:8080 216 EOF 217 TIMEOUT=600 218 START=$(date +%s) 219 while true; do 220 STAGE=$(kubectl -n matrix get testrun/"${NAME}" -o jsonpath='{.status.stage}' 2>/dev/null) || break 221 echo "Stage: ${STAGE}" 222 case "${STAGE}" in finished|error) break ;; esac 223 [ $(($(date +%s) - START)) -ge ${TIMEOUT} ] && { echo "Timed out"; break; } 224 sleep 10 225 done 226 kubectl -n matrix delete testrun/"${NAME}" --ignore-not-found 227 --- 228 # ── Soak: every 6 hours (on the hour), 30 min, memory leak detection ──────── 229 apiVersion: batch/v1 230 kind: CronJob 231 metadata: 232 name: k6-soak 233 namespace: k6-operator 234 spec: 235 schedule: "0 */6 * * *" 236 concurrencyPolicy: Forbid 237 successfulJobsHistoryLimit: 3 238 failedJobsHistoryLimit: 3 239 jobTemplate: 240 spec: 241 ttlSecondsAfterFinished: 3600 242 template: 243 spec: 244 serviceAccountName: k6-cronjob 245 restartPolicy: OnFailure 246 securityContext: 247 runAsNonRoot: true 248 runAsUser: 65534 249 runAsGroup: 65534 250 seccompProfile: 251 type: RuntimeDefault 252 containers: 253 - name: runner 254 image: docker.io/alpine/k8s:1.32.3 255 securityContext: 256 allowPrivilegeEscalation: false 257 capabilities: 258 drop: 259 - ALL 260 command: 261 - /bin/sh 262 - -c 263 - | 264 set -e 265 NAME="k6-soak-$(date +%s)" 266 kubectl -n matrix apply -f - << EOF 267 apiVersion: k6.io/v1alpha1 268 kind: TestRun 269 metadata: 270 name: ${NAME} 271 namespace: matrix 272 spec: 273 parallelism: 1 274 cleanup: "post" 275 script: 276 configMap: 277 name: k6-scripts 278 file: soak-with-memory-check.js 279 arguments: --out experimental-prometheus-rw 280 runner: 281 env: 282 - name: K6_PROMETHEUS_RW_SERVER_URL 283 value: http://prometheus-operated.monitoring.svc.cluster.local:9090/api/v1/write 284 - name: K6_PROMETHEUS_RW_STALE_MARKERS 285 value: "true" 286 - name: BASE_URL 287 value: http://connectivity-tester-stage.matrix.svc.cluster.local:8080 288 - name: PROMETHEUS_URL 289 value: http://prometheus-operated.monitoring.svc.cluster.local:9090 290 - name: MEMORY_GROWTH_THRESHOLD 291 value: "0.30" 292 EOF 293 TIMEOUT=2700 294 START=$(date +%s) 295 while true; do 296 STAGE=$(kubectl -n matrix get testrun/"${NAME}" -o jsonpath='{.status.stage}' 2>/dev/null) || break 297 echo "Stage: ${STAGE}" 298 case "${STAGE}" in finished|error) break ;; esac 299 [ $(($(date +%s) - START)) -ge ${TIMEOUT} ] && { echo "Timed out"; break; } 300 sleep 30 301 done 302 kubectl -n matrix delete testrun/"${NAME}" --ignore-not-found