fix: improve resource field cleaning to prevent YAML parsing errors
This commit is contained in:
@@ -517,11 +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))
|
||||
}
|
||||
// Clean up managed fields and other metadata
|
||||
// Clean up managed fields and other metadata that cause conflicts
|
||||
deployment.ManagedFields = nil
|
||||
deployment.ResourceVersion = ""
|
||||
deployment.UID = ""
|
||||
deployment.CreationTimestamp = metav1.Time{}
|
||||
deployment.SelfLink = ""
|
||||
deployment.Generation = 0
|
||||
yamlData, err = yaml.Marshal(deployment)
|
||||
case "StatefulSet":
|
||||
var statefulset *appsv1.StatefulSet
|
||||
@@ -533,11 +535,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))
|
||||
}
|
||||
// Clean up managed fields and other metadata
|
||||
// Clean up managed fields and other metadata that cause conflicts
|
||||
statefulset.ManagedFields = nil
|
||||
statefulset.ResourceVersion = ""
|
||||
statefulset.UID = ""
|
||||
statefulset.CreationTimestamp = metav1.Time{}
|
||||
statefulset.SelfLink = ""
|
||||
statefulset.Generation = 0
|
||||
yamlData, err = yaml.Marshal(statefulset)
|
||||
case "Service":
|
||||
var service *corev1.Service
|
||||
@@ -549,11 +553,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))
|
||||
}
|
||||
// Clean up managed fields and other metadata
|
||||
// Clean up managed fields and other metadata that cause conflicts
|
||||
service.ManagedFields = nil
|
||||
service.ResourceVersion = ""
|
||||
service.UID = ""
|
||||
service.CreationTimestamp = metav1.Time{}
|
||||
service.SelfLink = ""
|
||||
service.Generation = 0
|
||||
yamlData, err = yaml.Marshal(service)
|
||||
case "ConfigMap":
|
||||
var configmap *corev1.ConfigMap
|
||||
@@ -565,11 +571,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))
|
||||
}
|
||||
// Clean up managed fields and other metadata
|
||||
// Clean up managed fields and other metadata that cause conflicts
|
||||
configmap.ManagedFields = nil
|
||||
configmap.ResourceVersion = ""
|
||||
configmap.UID = ""
|
||||
configmap.CreationTimestamp = metav1.Time{}
|
||||
configmap.SelfLink = ""
|
||||
configmap.Generation = 0
|
||||
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