From a632f68c290cac9f9316514efaff83f02c8a2a3d Mon Sep 17 00:00:00 2001 From: loveuer Date: Thu, 13 Nov 2025 14:43:19 +0800 Subject: [PATCH] fix: ensure Kind and APIVersion are set in returned YAML --- internal/module/k8s/handler.resource.go | 28 +++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/internal/module/k8s/handler.resource.go b/internal/module/k8s/handler.resource.go index f666602..42a911e 100644 --- a/internal/module/k8s/handler.resource.go +++ b/internal/module/k8s/handler.resource.go @@ -517,6 +517,13 @@ func K8sResourceFetch(ctx context.Context, db *gorm.DB, store store.Store) fiber if err != nil { return resp.R500(c, "", nil, fmt.Errorf("failed to get deployment: %w", err)) } + // Ensure Kind and APIVersion are set + if deployment.Kind == "" { + deployment.Kind = "Deployment" + } + if deployment.APIVersion == "" { + deployment.APIVersion = "apps/v1" + } // Clean up managed fields and other metadata that cause conflicts deployment.ManagedFields = nil deployment.ResourceVersion = "" @@ -535,6 +542,13 @@ func K8sResourceFetch(ctx context.Context, db *gorm.DB, store store.Store) fiber if err != nil { return resp.R500(c, "", nil, fmt.Errorf("failed to get statefulset: %w", err)) } + // Ensure Kind and APIVersion are set + if statefulset.Kind == "" { + statefulset.Kind = "StatefulSet" + } + if statefulset.APIVersion == "" { + statefulset.APIVersion = "apps/v1" + } // Clean up managed fields and other metadata that cause conflicts statefulset.ManagedFields = nil statefulset.ResourceVersion = "" @@ -553,6 +567,13 @@ func K8sResourceFetch(ctx context.Context, db *gorm.DB, store store.Store) fiber if err != nil { return resp.R500(c, "", nil, fmt.Errorf("failed to get service: %w", err)) } + // Ensure Kind and APIVersion are set + if service.Kind == "" { + service.Kind = "Service" + } + if service.APIVersion == "" { + service.APIVersion = "v1" + } // Clean up managed fields and other metadata that cause conflicts service.ManagedFields = nil service.ResourceVersion = "" @@ -571,6 +592,13 @@ func K8sResourceFetch(ctx context.Context, db *gorm.DB, store store.Store) fiber if err != nil { return resp.R500(c, "", nil, fmt.Errorf("failed to get configmap: %w", err)) } + // Ensure Kind and APIVersion are set + if configmap.Kind == "" { + configmap.Kind = "ConfigMap" + } + if configmap.APIVersion == "" { + configmap.APIVersion = "v1" + } // Clean up managed fields and other metadata that cause conflicts configmap.ManagedFields = nil configmap.ResourceVersion = ""