handling error for json encode
@@ -216,10 +216,14 @@ func NewWebhookServer(
mux.HandlerFunc("POST", config.VerifyMutatingWebhookServicePath, ws.handlerFunc(ws.verifyHandler, false))
mux.HandlerFunc("GET", config.GetCachePath, func(w http.ResponseWriter, r *http.Request) {
+ logger := ws.log.WithValues("action", "get cache")
defer r.Body.Close()
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
- json.NewEncoder(w).Encode(pCache)
+ err := json.NewEncoder(w).Encode(pCache)
+ if err != nil {
+ logger.Error(err, "error in the JSON encoding")
+ }
})
// Handle Liveness responds to a Kubernetes Liveness probe
