Skip to content

Commit 26904a2

Browse files
fix: resolve JSONPath error in caBundle readiness check by adding kubectl_wait_for_query function (#1429)
By running `make kind-deploy` against a kind cluster or installing the released script from https://operator-framework.github.io/operator-controller/getting-started/olmv1_getting_started/ the following error is faced: ```sh ... deployment.apps/cert-manager-webhook condition met deployment.apps/cert-manager-cainjector condition met deployment.apps/cert-manager condition met error: jsonpath wait format must be --for=jsonpath='{.status.readyReplicas}'=3 ``` This PR fixes an issue with kubectl wait when used to check the caBundle field in `mutatingwebhookconfigurations` and `validatingwebhookconfigurations`. This PR introduces the `kubectl_wait_for_query` function, which replaces `kubectl wait` for this specific use case. The function repeatedly checks the `caBundle` field by using `kubectl get` in a loop, ensuring that the `caBundle` is populated without relying on status-based conditions. This approach provides a more flexible solution compatible with webhook configurations, bypassing the limitations of `kubectl wait`.
1 parent 8cd4a8c commit 26904a2

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

scripts/install.tpl.sh

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,40 @@ function kubectl_wait_rollout() {
4141
kubectl rollout status --namespace="${namespace}" "${runtime}" --timeout="${timeout}"
4242
}
4343

44+
function kubectl_wait_for_query() {
45+
manifest=$1
46+
query=$2
47+
timeout=$3
48+
poll_interval_in_seconds=$4
49+
50+
if [[ -z "$manifest" || -z "$query" || -z "$timeout" || -z "$poll_interval_in_seconds" ]]; then
51+
echo "Error: Missing arguments."
52+
echo "Usage: kubectl_wait_for_query <manifest> <query> <timeout> <poll_interval_in_seconds>"
53+
exit 1
54+
fi
55+
56+
start_time=$(date +%s)
57+
while true; do
58+
val=$(kubectl get "${manifest}" -o jsonpath="${query}" 2>/dev/null || echo "")
59+
if [[ -n "${val}" ]]; then
60+
echo "${manifest} has ${query}."
61+
break
62+
fi
63+
if [[ $(( $(date +%s) - start_time )) -ge ${timeout} ]]; then
64+
echo "Timed out waiting for ${manifest} to have ${query}."
65+
exit 1
66+
fi
67+
sleep ${poll_interval_in_seconds}s
68+
done
69+
}
70+
4471
kubectl apply -f "https://github.com/cert-manager/cert-manager/releases/download/${cert_mgr_version}/cert-manager.yaml"
4572
# Wait for cert-manager to be fully ready
4673
kubectl_wait "cert-manager" "deployment/cert-manager-webhook" "60s"
4774
kubectl_wait "cert-manager" "deployment/cert-manager-cainjector" "60s"
4875
kubectl_wait "cert-manager" "deployment/cert-manager" "60s"
49-
kubectl wait mutatingwebhookconfigurations/cert-manager-webhook --for=jsonpath='{.webhooks[0].clientConfig.caBundle}' --timeout=60s
50-
kubectl wait validatingwebhookconfigurations/cert-manager-webhook --for=jsonpath='{.webhooks[0].clientConfig.caBundle}' --timeout=60s
76+
kubectl_wait_for_query "mutatingwebhookconfigurations/cert-manager-webhook" '{.webhooks[0].clientConfig.caBundle}' 60 5
77+
kubectl_wait_for_query "validatingwebhookconfigurations/cert-manager-webhook" '{.webhooks[0].clientConfig.caBundle}' 60 5
5178

5279
kubectl apply -f "https://github.com/operator-framework/catalogd/releases/download/${catalogd_version}/catalogd.yaml"
5380
# Wait for the rollout, and then wait for the deployment to be Available

0 commit comments

Comments
 (0)