Skip to content

Commit ed2af33

Browse files
fix: resolve JSONPath error in caBundle readiness check by adding kubectl_wait_for_query function
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`. dd
1 parent 6bda277 commit ed2af33

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

scripts/install.tpl.sh

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,32 @@ 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+
start_time=$(date +%s)
49+
while true; do
50+
val=$(kubectl get "${manifest}" -o jsonpath="${query}" 2>/dev/null || echo "")
51+
if [[ -n "${val}" ]]; then
52+
echo "${manifest} has ${query}."
53+
break
54+
fi
55+
if [[ $(( $(date +%s) - start_time )) -ge ${timeout} ]]; then
56+
echo "Timed out waiting for ${manifest} to have ${query}."
57+
exit 1
58+
fi
59+
sleep 5
60+
done
61+
}
62+
4463
kubectl apply -f "https://github.com/cert-manager/cert-manager/releases/download/${cert_mgr_version}/cert-manager.yaml"
4564
# Wait for cert-manager to be fully ready
4665
kubectl_wait "cert-manager" "deployment/cert-manager-webhook" "60s"
4766
kubectl_wait "cert-manager" "deployment/cert-manager-cainjector" "60s"
4867
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
68+
kubectl_wait_for_query "mutatingwebhookconfigurations/cert-manager-webhook" '{.webhooks[0].clientConfig.caBundle}' 60
69+
kubectl_wait_for_query "validatingwebhookconfigurations/cert-manager-webhook" '{.webhooks[0].clientConfig.caBundle}' 60
5170

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

0 commit comments

Comments
 (0)