|
| 1 | +# Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +name: 'Check Control Plane Health' |
| 16 | +description: 'Fails if Kind control-plane static pods are missing, unready, or restarted.' |
| 17 | + |
| 18 | +inputs: |
| 19 | + cluster_name: |
| 20 | + description: 'Kind cluster name' |
| 21 | + required: true |
| 22 | + namespace: |
| 23 | + description: 'Namespace that contains the control-plane pods' |
| 24 | + required: false |
| 25 | + default: kube-system |
| 26 | + components: |
| 27 | + description: 'Space-separated component label values to check' |
| 28 | + required: false |
| 29 | + default: kube-apiserver kube-controller-manager kube-scheduler etcd |
| 30 | + wait_timeout: |
| 31 | + description: 'Timeout for each component readiness wait' |
| 32 | + required: false |
| 33 | + default: 60s |
| 34 | + max_restarts: |
| 35 | + description: 'Maximum tolerated restart count for each control-plane container' |
| 36 | + required: false |
| 37 | + default: '1' |
| 38 | + |
| 39 | +runs: |
| 40 | + using: 'composite' |
| 41 | + steps: |
| 42 | + - name: Check control-plane pods |
| 43 | + shell: bash |
| 44 | + env: |
| 45 | + KIND_CLUSTER_NAME: ${{ inputs.cluster_name }} |
| 46 | + NAMESPACE: ${{ inputs.namespace }} |
| 47 | + COMPONENTS: ${{ inputs.components }} |
| 48 | + WAIT_TIMEOUT: ${{ inputs.wait_timeout }} |
| 49 | + MAX_RESTARTS: ${{ inputs.max_restarts }} |
| 50 | + run: | |
| 51 | + set -euo pipefail |
| 52 | +
|
| 53 | + kubectl --context="kind-${KIND_CLUSTER_NAME}" get --raw='/readyz' || true |
| 54 | +
|
| 55 | + check_component() { |
| 56 | + local component="$1" |
| 57 | + local selector="component=${component}" |
| 58 | + local pods |
| 59 | +
|
| 60 | + pods=$(kubectl --context="kind-${KIND_CLUSTER_NAME}" -n "${NAMESPACE}" \ |
| 61 | + get pod -l "${selector}" -o name) |
| 62 | + if [[ -z "${pods}" ]]; then |
| 63 | + echo "::error::no ${component} pods found in ${NAMESPACE} with selector ${selector}" |
| 64 | + kubectl --context="kind-${KIND_CLUSTER_NAME}" -n "${NAMESPACE}" \ |
| 65 | + get pods -o wide || true |
| 66 | + exit 1 |
| 67 | + fi |
| 68 | +
|
| 69 | + if ! kubectl --context="kind-${KIND_CLUSTER_NAME}" -n "${NAMESPACE}" \ |
| 70 | + wait --for=condition=Ready pod -l "${selector}" --timeout="${WAIT_TIMEOUT}"; then |
| 71 | + echo "::error::${component} pods did not become Ready within ${WAIT_TIMEOUT}" |
| 72 | + kubectl --context="kind-${KIND_CLUSTER_NAME}" -n "${NAMESPACE}" \ |
| 73 | + get pod -l "${selector}" -o wide || true |
| 74 | + kubectl --context="kind-${KIND_CLUSTER_NAME}" -n "${NAMESPACE}" \ |
| 75 | + describe pod -l "${selector}" || true |
| 76 | + kubectl --context="kind-${KIND_CLUSTER_NAME}" -n "${NAMESPACE}" \ |
| 77 | + get events --sort-by='.lastTimestamp' 2>/dev/null | tail -30 || true |
| 78 | + kubectl --context="kind-${KIND_CLUSTER_NAME}" get --raw='/readyz' || true |
| 79 | + exit 1 |
| 80 | + fi |
| 81 | +
|
| 82 | + local restart_counts |
| 83 | + restart_counts=$(kubectl --context="kind-${KIND_CLUSTER_NAME}" -n "${NAMESPACE}" \ |
| 84 | + get pod -l "${selector}" \ |
| 85 | + -o jsonpath='{range .items[*]}{range .status.containerStatuses[*]}{.restartCount}{"\n"}{end}{end}') |
| 86 | + if [[ -z "${restart_counts}" ]]; then |
| 87 | + echo "::error::no container statuses found for ${component} pods" |
| 88 | + kubectl --context="kind-${KIND_CLUSTER_NAME}" -n "${NAMESPACE}" \ |
| 89 | + describe pod -l "${selector}" || true |
| 90 | + exit 1 |
| 91 | + fi |
| 92 | +
|
| 93 | + while IFS= read -r restart_count; do |
| 94 | + [[ -z "${restart_count}" ]] && continue |
| 95 | + if (( restart_count > MAX_RESTARTS )); then |
| 96 | + echo "::error::${component} restartCount=${restart_count}" |
| 97 | + kubectl --context="kind-${KIND_CLUSTER_NAME}" -n "${NAMESPACE}" \ |
| 98 | + get pod -l "${selector}" -o wide || true |
| 99 | + kubectl --context="kind-${KIND_CLUSTER_NAME}" -n "${NAMESPACE}" \ |
| 100 | + describe pod -l "${selector}" || true |
| 101 | + exit 1 |
| 102 | + fi |
| 103 | + done <<< "${restart_counts}" |
| 104 | + } |
| 105 | +
|
| 106 | + for component in ${COMPONENTS}; do |
| 107 | + check_component "${component}" |
| 108 | + done |
| 109 | + kubectl --context="kind-${KIND_CLUSTER_NAME}" get --raw='/readyz' |
0 commit comments