Skip to content

Commit

Permalink
Operator pod readiness probe to wait for webhook (#280)
Browse files Browse the repository at this point in the history
The controller-runtime added a health check that will return only when the
webhook is up. However, it isn't enabled by default. Instead we just use the
normal 'ping' checking, which returns as soon as the pod is running. This
commit is to change the readiness probe to use the one in controller-runtime
that waits for the webhook.

As part of this, I removed the manual webhook check that we use for the e2e
tests.
  • Loading branch information
spilchen authored Oct 26, 2022
1 parent a918c78 commit dc980b7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 103 deletions.
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -404,10 +404,8 @@ uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified
deploy-operator: manifests kustomize ## Using helm or olm, deploy the operator in the K8s cluster
ifeq ($(DEPLOY_WITH), helm)
helm install --wait -n $(NAMESPACE) $(HELM_RELEASE_NAME) $(OPERATOR_CHART) --set image.repo=null --set image.name=${OPERATOR_IMG} --set logging.dev=${DEV_MODE} --set image.pullPolicy=$(HELM_IMAGE_PULL_POLICY) --set imagePullSecrets[0].name=priv-reg-cred $(HELM_OVERRIDES)
scripts/wait-for-webhook.sh -n $(NAMESPACE) -t 60
else ifeq ($(DEPLOY_WITH), olm)
scripts/deploy-olm.sh -n $(NAMESPACE) $(OLM_TEST_CATALOG_SOURCE)
scripts/wait-for-webhook.sh -n $(NAMESPACE) -t 60
else ifeq ($(DEPLOY_WITH), random)
ifeq ($(shell (( $$RANDOM % 2 )); echo $$?),0)
DEPLOY_WITH=helm $(MAKE) deploy-operator
Expand Down
5 changes: 5 additions & 0 deletions changes/unreleased/Fixed-20221026-141919.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: Fixed
body: Operator pod readiness probe to wait for webhook
time: 2022-10-26T14:19:19.398290964-03:00
custom:
Issue: "280"
12 changes: 11 additions & 1 deletion cmd/operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,16 @@ func setupWebhook(ctx context.Context, mgr manager.Manager, restCfg *rest.Config
return nil
}

// getReadinessProbeCallack returns the check to use for the readiness probe
func getReadinessProbeCallback(mgr ctrl.Manager) healthz.Checker {
// If the webhook is enabled, we use a checker that tests if the webhook is
// able to accept requests.
if getIsWebhookEnabled() {
return mgr.GetWebhookServer().StartedChecker()
}
return healthz.Ping
}

func main() {
flagArgs := &FlagConfig{}
flagArgs.setFlagArgs()
Expand Down Expand Up @@ -369,7 +379,7 @@ func main() {
setupLog.Error(err, "unable to set up health check")
os.Exit(1)
}
if err := mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil {
if err := mgr.AddReadyzCheck("readyz", getReadinessProbeCallback(mgr)); err != nil {
setupLog.Error(err, "unable to set up ready check")
os.Exit(1)
}
Expand Down
100 changes: 0 additions & 100 deletions scripts/wait-for-webhook.sh

This file was deleted.

0 comments on commit dc980b7

Please sign in to comment.