Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/logs #338

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions api/v1alpha1/cachedimage_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,19 @@
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).
For(r).

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

View workflow job for this annotation

GitHub Actions / Static Analysis

cannot use r (variable of type *CachedImage) as "k8s.io/apimachinery/pkg/runtime".Object value in argument to ctrl.NewWebhookManagedBy(mgr).WithDefaulter(r).For: *CachedImage does not implement "k8s.io/apimachinery/pkg/runtime".Object (missing method DeepCopyObject)

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

View workflow job for this annotation

GitHub Actions / Static Analysis

cannot use r (variable of type *CachedImage) as "k8s.io/apimachinery/pkg/runtime".Object value in argument to ctrl.NewWebhookManagedBy(mgr).WithDefaulter(r).For: *CachedImage does not implement "k8s.io/apimachinery/pkg/runtime".Object (missing method DeepCopyObject)
Complete()
}

//+kubebuilder:webhook:path=/mutate-kuik-enix-io-v1alpha1-cachedimage,mutating=true,failurePolicy=fail,sideEffects=None,groups=kuik.enix.io,resources=cachedimages,verbs=create;update,versions=v1alpha1,name=mcachedimage.kb.io,admissionReviewVersions=v1

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
4 changes: 4 additions & 0 deletions helm/kube-image-keeper/templates/controller-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ spec:
readinessProbe:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.controllers.livenessProbe }}
livenessProbe:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.controllers.resources }}
resources:
{{- toYaml . | nindent 12 }}
Expand Down
14 changes: 12 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 All @@ -95,6 +97,14 @@ spec:
readinessProbe:
{{- $readinessProbe | toYaml | nindent 12 }}
{{- end }}
{{- $livenessProbe := deepCopy .Values.proxy.livenessProbe }}
{{- if .Values.proxy.hostNetwork }}
{{- $livenessProbe := merge $livenessProbe.httpGet (dict "host" "localhost") }}
{{- end }}
{{- with .Values.proxy.livenessProbe }}
livenessProbe:
{{- $livenessProbe | toYaml | nindent 12 }}
{{- end }}
{{- with .Values.proxy.resources }}
resources:
{{- toYaml . | nindent 12 }}
Expand Down
4 changes: 4 additions & 0 deletions helm/kube-image-keeper/templates/registry-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ spec:
readinessProbe:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.registry.livenessProbe }}
livenessProbe:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.registry.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
Expand Down
4 changes: 4 additions & 0 deletions helm/kube-image-keeper/templates/registry-statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ spec:
readinessProbe:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.registry.livenessProbe }}
livenessProbe:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.registry.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
Expand Down
17 changes: 16 additions & 1 deletion helm/kube-image-keeper/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ controllers:
httpGet:
path: /readyz
port: 8081
# -- Liveness probe definition for the controllers pod
livenessProbe:
httpGet:
path: /healthz
port: 8081
resources:
requests:
# -- Cpu requests for the controller pod
Expand Down Expand Up @@ -162,7 +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: /healthz
port: 7439
resources:
requests:
Expand Down Expand Up @@ -239,6 +249,11 @@ registry:
httpGet:
path: /v2/
port: 5000
# -- Liveness probe definition for the proxy pod
livenessProbe:
httpGet:
path: /v2/
port: 5000
resources:
requests:
# -- Cpu requests for the registry pod
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
Loading