From e8c548dc91df2ab5de494c7a7645191f1bd9e321 Mon Sep 17 00:00:00 2001 From: Pieszka Date: Thu, 12 Sep 2024 15:04:57 +0200 Subject: [PATCH] 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 + } } }