From e4194266052a2218f3935997068b8056d5b9dd69 Mon Sep 17 00:00:00 2001 From: Paul Laffitte Date: Thu, 23 May 2024 14:16:25 +0200 Subject: [PATCH] fix: remove some unnecessary logs --- api/v1alpha1/cachedimage_webhook.go | 4 --- .../templates/proxy-daemonset.yaml | 6 ++-- helm/kube-image-keeper/values.yaml | 4 +-- internal/proxy/server.go | 32 ++++++++++++------- 4 files changed, 27 insertions(+), 19 deletions(-) diff --git a/api/v1alpha1/cachedimage_webhook.go b/api/v1alpha1/cachedimage_webhook.go index d3acdafc..baa98b58 100644 --- a/api/v1alpha1/cachedimage_webhook.go +++ b/api/v1alpha1/cachedimage_webhook.go @@ -8,11 +8,8 @@ import ( runtime "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/validation/field" ctrl "sigs.k8s.io/controller-runtime" - logf "sigs.k8s.io/controller-runtime/pkg/log" ) -var cachedimagelog = logf.Log.WithName("cachedimage-resource") - func (r *CachedImage) SetupWebhookWithManager(mgr ctrl.Manager) error { return ctrl.NewWebhookManagedBy(mgr). WithDefaulter(r). @@ -24,7 +21,6 @@ func (r *CachedImage) SetupWebhookWithManager(mgr ctrl.Manager) error { func (r *CachedImage) Default(ctx context.Context, obj runtime.Object) error { cachedImage := obj.(*CachedImage) - cachedimagelog.Info("defaulting", "name", cachedImage.Name) named, err := reference.ParseNormalizedNamed(cachedImage.Spec.SourceImage) if err != nil { diff --git a/helm/kube-image-keeper/templates/proxy-daemonset.yaml b/helm/kube-image-keeper/templates/proxy-daemonset.yaml index 91606ee0..427b8965 100644 --- a/helm/kube-image-keeper/templates/proxy-daemonset.yaml +++ b/helm/kube-image-keeper/templates/proxy-daemonset.yaml @@ -77,11 +77,13 @@ spec: {{- else }} - -bind-address=:{{ .Values.proxy.hostPort }} {{- end }} - {{- if .Values.rootCertificateAuthorities }} - {{- with .Values.proxy.env }} env: + {{- with .Values.proxy.env }} {{- toYaml . | nindent 12 }} {{- end }} + - name: GIN_MODE + value: release + {{- if .Values.rootCertificateAuthorities }} volumeMounts: - mountPath: /etc/ssl/certs/registry-certificate-authorities name: registry-certificate-authorities diff --git a/helm/kube-image-keeper/values.yaml b/helm/kube-image-keeper/values.yaml index b7b1d27c..939cde73 100644 --- a/helm/kube-image-keeper/values.yaml +++ b/helm/kube-image-keeper/values.yaml @@ -167,12 +167,12 @@ proxy: # -- Readiness probe definition for the proxy pod readinessProbe: httpGet: - path: /v2/ + path: /readyz port: 7439 # -- Liveness probe definition for the proxy pod livenessProbe: httpGet: - path: /v2/ + path: /healthz port: 7439 resources: requests: diff --git a/internal/proxy/server.go b/internal/proxy/server.go index 3cf926e5..d2ff6c8b 100644 --- a/internal/proxy/server.go +++ b/internal/proxy/server.go @@ -39,7 +39,7 @@ func New(k8sClient client.Client, metricsAddr string, insecureRegistries []strin collector := NewCollector() return &Proxy{ k8sClient: k8sClient, - engine: gin.Default(), + engine: gin.New(), collector: collector, exporter: metrics.New(collector, metricsAddr), insecureRegistries: insecureRegistries, @@ -57,14 +57,24 @@ func NewWithEngine(k8sClient client.Client, engine *gin.Engine) *Proxy { func (p *Proxy) Serve() *Proxy { r := p.engine - r.Use(recoveryMiddleware()) - r.Use(func(c *gin.Context) { - c.Next() - registry := c.Param("originRegistry") - if registry == "" { - return - } - p.collector.IncHTTPCall(registry, c.Writer.Status(), c.GetBool("cacheHit")) + r.Use( + gin.LoggerWithWriter(gin.DefaultWriter, "/readyz", "/healthz"), + recoveryMiddleware(), + func(c *gin.Context) { + c.Next() + registry := c.Param("originRegistry") + if registry == "" { + return + } + p.collector.IncHTTPCall(registry, c.Writer.Status(), c.GetBool("cacheHit")) + }, + ) + + r.GET("/readyz", func(c *gin.Context) { + c.Status(http.StatusOK) + }) + r.GET("/healthz", func(c *gin.Context) { + c.Status(http.StatusOK) }) v2 := r.Group("/v2") @@ -80,7 +90,7 @@ func (p *Proxy) Serve() *Proxy { subMatches := pathRegex.FindStringSubmatch(subPath) if subMatches == nil { - c.Status(404) + c.Status(http.StatusNotFound) return } @@ -134,7 +144,7 @@ func (p *Proxy) Run(proxyAddr string) chan struct{} { func (p *Proxy) v2Endpoint(c *gin.Context) { c.Header("Docker-Distribution-Api-Version", "registry/2.0") c.Header("X-Content-Type-Options", "nosniff") - c.JSON(200, map[string]string{}) + c.JSON(http.StatusOK, map[string]string{}) } func (p *Proxy) routeProxy(c *gin.Context) {