From 224f768c04226f77c5c0dc3df4c636591df2179d Mon Sep 17 00:00:00 2001 From: air-31 Date: Wed, 8 Jan 2025 14:17:21 +0100 Subject: [PATCH] Add readiness probe --- .../cloudimg-registry/templates/deployment.yaml | 6 ++++++ operators/pkg/ciregistry/handlers.go | 12 ++++++++++++ operators/pkg/ciregistry/router.go | 1 + 3 files changed, 19 insertions(+) diff --git a/operators/deploy/cloudimg-registry/templates/deployment.yaml b/operators/deploy/cloudimg-registry/templates/deployment.yaml index 03343aa47..be584abb4 100644 --- a/operators/deploy/cloudimg-registry/templates/deployment.yaml +++ b/operators/deploy/cloudimg-registry/templates/deployment.yaml @@ -38,6 +38,12 @@ spec: - name: http containerPort: 8080 protocol: TCP + readinessProbe: + httpGet: + path: /healthz + port: http + initialDelaySeconds: 3 + periodSeconds: 3 resources: {{- toYaml .Values.resources | nindent 12 }} volumeMounts: diff --git a/operators/pkg/ciregistry/handlers.go b/operators/pkg/ciregistry/handlers.go index f1481de74..8cf747993 100644 --- a/operators/pkg/ciregistry/handlers.go +++ b/operators/pkg/ciregistry/handlers.go @@ -219,3 +219,15 @@ func HandleDeleteTag(log klog.Logger) usecase.Interactor { return u } + +// HealthzHandler is used for performing readiness probes. +func HealthzHandler() usecase.Interactor { + u := usecase.NewInteractor(func(_ context.Context, _ struct{}, out *BasicJSONReply) error { + out.Success = true + return nil + }) + + u.SetExpectedErrors(status.Unavailable) + + return u +} diff --git a/operators/pkg/ciregistry/router.go b/operators/pkg/ciregistry/router.go index 778404ea6..a2a2b1fd6 100644 --- a/operators/pkg/ciregistry/router.go +++ b/operators/pkg/ciregistry/router.go @@ -36,6 +36,7 @@ func NewRouter() http.Handler { s.OpenAPISchema().SetDescription("API for managing cloudimage repositories and metadata.") s.OpenAPISchema().SetVersion("1.0.0") + s.Get("/healthz", HealthzHandler()) s.Get("/{repo}", HandleGetImages(klog.LoggerWithName(log, "imagelist"))) s.Get("/{repo}/{image}", HandleGetImageTags(klog.LoggerWithName(log, "taglist"))) s.Get("/{repo}/{image}/{tag}", HandleGetImage(klog.LoggerWithName(log, "imagebin")), nethttp.SuccessfulResponseContentType("application/octet-stream"))