From 79797678120b356c9bed994fbbb021c60aa9b06d Mon Sep 17 00:00:00 2001 From: Rui Vieira Date: Mon, 14 Oct 2024 15:38:57 +0100 Subject: [PATCH] Add readiness probes (#312) --- controllers/database.go | 1 - controllers/statuses.go | 7 ++++++- controllers/templates/service/deployment.tmpl.yaml | 14 ++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/controllers/database.go b/controllers/database.go index 96679d01..1c5d26a1 100644 --- a/controllers/database.go +++ b/controllers/database.go @@ -12,7 +12,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" ) -// checkDatabaseAccessible checks if the TrustyAI service pod failed with database issues. func (r *TrustyAIServiceReconciler) checkDatabaseAccessible(ctx context.Context, instance *trustyaiopendatahubiov1alpha1.TrustyAIService) (bool, error) { deployment := &appsv1.Deployment{} err := r.Get(ctx, types.NamespacedName{Name: instance.Name, Namespace: instance.Namespace}, deployment) diff --git a/controllers/statuses.go b/controllers/statuses.go index 9236e81b..b43bbbd1 100644 --- a/controllers/statuses.go +++ b/controllers/statuses.go @@ -87,7 +87,12 @@ func (r *TrustyAIServiceReconciler) reconcileStatuses(ctx context.Context, insta UpdateRouteAvailable(saved) if instance.Spec.Storage.IsStorageDatabase() || instance.IsMigration() { - UpdateDBAvailable(saved) + if status.DBReady { + UpdateDBAvailable(saved) + } else { + UpdateDBConnectionError(saved) + return + } } UpdateTrustyAIServiceAvailable(saved) diff --git a/controllers/templates/service/deployment.tmpl.yaml b/controllers/templates/service/deployment.tmpl.yaml index f1e429f1..e87091c6 100644 --- a/controllers/templates/service/deployment.tmpl.yaml +++ b/controllers/templates/service/deployment.tmpl.yaml @@ -122,6 +122,20 @@ spec: - name: STORAGE_MIGRATION_CONFIG_FROM_FILENAME value: {{ .Instance.Spec.Data.Filename }} {{ end }} + readinessProbe: + httpGet: + path: /q/health/ready + port: 8080 + initialDelaySeconds: 10 + periodSeconds: 5 + timeoutSeconds: 2 + livenessProbe: + httpGet: + path: /q/health/live + port: 8080 + initialDelaySeconds: 10 + periodSeconds: 5 + timeoutSeconds: 2 volumeMounts: - name: {{ .Instance.Name }}-internal readOnly: false