From 23add6447df770ac99f9a552e1e17cf650af8c74 Mon Sep 17 00:00:00 2001 From: loveuer Date: Thu, 13 Nov 2025 11:40:36 +0800 Subject: [PATCH] fix: clean managedFields and metadata from resource YAML to prevent update conflicts --- internal/module/k8s/handler.resource.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/internal/module/k8s/handler.resource.go b/internal/module/k8s/handler.resource.go index c66fb28..c88ab24 100644 --- a/internal/module/k8s/handler.resource.go +++ b/internal/module/k8s/handler.resource.go @@ -517,6 +517,11 @@ 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)) } + // Clean up managed fields and other metadata + deployment.ManagedFields = nil + deployment.ResourceVersion = "" + deployment.UID = "" + deployment.CreationTimestamp = metav1.Time{} yamlData, err = yaml.Marshal(deployment) case "StatefulSet": var statefulset *appsv1.StatefulSet @@ -528,6 +533,11 @@ 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)) } + // Clean up managed fields and other metadata + statefulset.ManagedFields = nil + statefulset.ResourceVersion = "" + statefulset.UID = "" + statefulset.CreationTimestamp = metav1.Time{} yamlData, err = yaml.Marshal(statefulset) case "Service": var service *corev1.Service @@ -539,6 +549,11 @@ 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)) } + // Clean up managed fields and other metadata + service.ManagedFields = nil + service.ResourceVersion = "" + service.UID = "" + service.CreationTimestamp = metav1.Time{} yamlData, err = yaml.Marshal(service) case "ConfigMap": var configmap *corev1.ConfigMap @@ -550,6 +565,11 @@ 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)) } + // Clean up managed fields and other metadata + configmap.ManagedFields = nil + configmap.ResourceVersion = "" + configmap.UID = "" + configmap.CreationTimestamp = metav1.Time{} yamlData, err = yaml.Marshal(configmap) default: return resp.R400(c, "", nil, fmt.Errorf("unsupported resource kind: %s", kind))