Files
2026-03-29 09:08:01 +08:00

24 lines
1.2 KiB
YAML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 可复用:断言 Endpoints 存在至少一个 address与 nodejs-demo 等用例一致)。
# 必填verify_endpoints_service
# 可选verify_endpoints_namespace默认 default、verify_endpoints_assertion_label日志、k3s_kubeconfig
- name: Assert verify_endpoints_service for kubectl-endpoints-ready
ansible.builtin.assert:
that:
- verify_endpoints_service is defined
- (verify_endpoints_service | trim | length) > 0
fail_msg: "verify_common kubectl-endpoints-readyverify_endpoints_service 为空"
- name: Endpoints have addresses (verify_common)
ansible.builtin.shell: |
set -euo pipefail
KUBECONFIG="{{ k3s_kubeconfig | default('/etc/rancher/k3s/k3s.yaml') }}"
svc="{{ verify_endpoints_service | trim }}"
ns="{{ verify_endpoints_namespace | default('default') }}"
label="{{ verify_endpoints_assertion_label | default('endpoints_ready') }}"
eps=$(kubectl get endpoints "$svc" -n "$ns" -o jsonpath='{.subsets[0].addresses[0].ip}' 2>/dev/null || true)
echo "[OC-ASSERT] assertion=${label} svc=${svc} namespace=${ns} endpoints.ip=${eps:-}"
test -n "$eps"
args:
executable: /bin/bash
changed_when: false