From 0bd6ea0decdccbfba724ba7da11817ab000ce061 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaros=C5=82aw=20Pieszka?= Date: Thu, 12 Sep 2024 15:17:14 +0200 Subject: [PATCH] KIM integration - safer casting during `managedFields` removal (#1131) safer casting --- internal/runtime/handler.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/internal/runtime/handler.go b/internal/runtime/handler.go index 91f8b588fa..0c2d9b4549 100644 --- a/internal/runtime/handler.go +++ b/internal/runtime/handler.go @@ -249,8 +249,15 @@ func (h *Handler) getRuntimes(w http.ResponseWriter, req *http.Request) { dto.RuntimeConfig = nil default: // remove managedFields from the object to reduce the size of the response - delete(runtimeResourceObject.Object["metadata"].(map[string]interface{}), "managedFields") - dto.RuntimeConfig = &runtimeResourceObject.Object + _, ok := runtimeResourceObject.Object["metadata"].(map[string]interface{}) + if !ok { + h.logger.Warn(fmt.Sprintf("unable to get Runtime resource metadata %s/%s: %s", dto.InstanceID, dto.RuntimeID, err.Error())) + dto.RuntimeConfig = nil + + } else { + delete(runtimeResourceObject.Object["metadata"].(map[string]interface{}), "managedFields") + dto.RuntimeConfig = &runtimeResourceObject.Object + } } }