From c7ba18f5b8fd9e00dd9130fcbbfae1b406e16130 Mon Sep 17 00:00:00 2001 From: Ismail Alidzhikov Date: Fri, 6 Oct 2023 18:05:54 +0300 Subject: [PATCH] Add readiness and liveness probe to the registry Pods (#55) --- .../registrycaches/registrycaches.go | 39 ++++++++++++++++++- .../registrycaches/registrycaches_test.go | 20 ++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/pkg/component/registrycaches/registrycaches.go b/pkg/component/registrycaches/registrycaches.go index 3571ff4d..55130425 100644 --- a/pkg/component/registrycaches/registrycaches.go +++ b/pkg/component/registrycaches/registrycaches.go @@ -144,7 +144,10 @@ func computeResourcesDataForRegistryCache(cache *v1alpha1.RegistryCache, image s return nil, fmt.Errorf("registry cache size is required") } - const registryCacheVolumeName = "cache-volume" + const ( + registryCacheVolumeName = "cache-volume" + debugPort = 5001 + ) var ( name = strings.Replace(fmt.Sprintf("registry-%s", strings.Split(cache.Upstream, ":")[0]), ".", "-", -1) @@ -199,6 +202,10 @@ func computeResourcesDataForRegistryCache(cache *v1alpha1.RegistryCache, image s ContainerPort: constants.RegistryCachePort, Name: "registry-cache", }, + { + ContainerPort: debugPort, + Name: "debug", + }, }, Env: []corev1.EnvVar{ { @@ -209,6 +216,36 @@ func computeResourcesDataForRegistryCache(cache *v1alpha1.RegistryCache, image s Name: "REGISTRY_STORAGE_DELETE_ENABLED", Value: strconv.FormatBool(helper.GarbageCollectionEnabled(cache)), }, + { + Name: "REGISTRY_HTTP_ADDR", + Value: fmt.Sprintf(":%d", constants.RegistryCachePort), + }, + { + Name: "REGISTRY_HTTP_DEBUG_ADDR", + Value: fmt.Sprintf(":%d", debugPort), + }, + }, + LivenessProbe: &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + HTTPGet: &corev1.HTTPGetAction{ + Path: "/debug/health", + Port: intstr.FromInt(debugPort), + }, + }, + FailureThreshold: 6, + SuccessThreshold: 1, + PeriodSeconds: 20, + }, + ReadinessProbe: &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + HTTPGet: &corev1.HTTPGetAction{ + Path: "/debug/health", + Port: intstr.FromInt(debugPort), + }, + }, + FailureThreshold: 3, + SuccessThreshold: 1, + PeriodSeconds: 20, }, VolumeMounts: []corev1.VolumeMount{ { diff --git a/pkg/component/registrycaches/registrycaches_test.go b/pkg/component/registrycaches/registrycaches_test.go index d5396bcd..5c3b8579 100644 --- a/pkg/component/registrycaches/registrycaches_test.go +++ b/pkg/component/registrycaches/registrycaches_test.go @@ -158,12 +158,32 @@ spec: value: ` + upstreamURL + ` - name: REGISTRY_STORAGE_DELETE_ENABLED value: "` + strconv.FormatBool(garbageCollectionEnabled) + `" + - name: REGISTRY_HTTP_ADDR + value: :5000 + - name: REGISTRY_HTTP_DEBUG_ADDR + value: :5001 image: ` + image + ` imagePullPolicy: IfNotPresent + livenessProbe: + failureThreshold: 6 + httpGet: + path: /debug/health + port: 5001 + periodSeconds: 20 + successThreshold: 1 name: registry-cache ports: - containerPort: 5000 name: registry-cache + - containerPort: 5001 + name: debug + readinessProbe: + failureThreshold: 3 + httpGet: + path: /debug/health + port: 5001 + periodSeconds: 20 + successThreshold: 1 resources: {} volumeMounts: - mountPath: /var/lib/registry