fix: clean managedFields and metadata from resource YAML to prevent update conflicts
This commit is contained in:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user