Skip to content

Commit

Permalink
fix: remove some unnecessary logs
Browse files Browse the repository at this point in the history
  • Loading branch information
paullaffitte committed May 23, 2024
1 parent 5029d2f commit e419426
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 19 deletions.
4 changes: 0 additions & 4 deletions api/v1alpha1/cachedimage_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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)

Check failure on line 23 in api/v1alpha1/cachedimage_webhook.go

View workflow job for this annotation

GitHub Actions / Static Analysis

impossible type assertion: obj.(*CachedImage)

Check failure on line 23 in api/v1alpha1/cachedimage_webhook.go

View workflow job for this annotation

GitHub Actions / Static Analysis

impossible type assertion: obj.(*CachedImage)
cachedimagelog.Info("defaulting", "name", cachedImage.Name)

named, err := reference.ParseNormalizedNamed(cachedImage.Spec.SourceImage)
if err != nil {
Expand Down
6 changes: 4 additions & 2 deletions helm/kube-image-keeper/templates/proxy-daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions helm/kube-image-keeper/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
32 changes: 21 additions & 11 deletions internal/proxy/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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")
Expand All @@ -80,7 +90,7 @@ func (p *Proxy) Serve() *Proxy {

subMatches := pathRegex.FindStringSubmatch(subPath)
if subMatches == nil {
c.Status(404)
c.Status(http.StatusNotFound)
return
}

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit e419426

Please sign in to comment.