fix(k8s): 可视化编辑器 YAML 解析失败(managedFields 清理)
- 先解析原始 YAML 再对象级剥离,避免 cleanYAML 破坏结构 - managedFields 从 METADATA_LINE_KEYS 移除,改整块删除含数组项 - YamlViewer 同步使用 parseEditableManifest
This commit is contained in:
1 parent
21d40b186a
commit
5fad2db0c6
101 files changed
+195
-146
No files matched your search
@@ -7,6 +7,7 @@ import { Button } from '@/components/ui/button';
|
||||
import { useToast } from '@/hooks/use-toast';
|
||||
import { kubernetesApi } from '@/api';
|
||||
import { cleanYAML } from './k8s-yaml-utils';
|
||||
import { parseEditableManifest } from './k8s-manifest-utils';
|
||||
import CodeMirror from '@uiw/react-codemirror';
|
||||
import { yaml } from '@codemirror/lang-yaml';
|
||||
import { oneDark } from '@codemirror/theme-one-dark';
|
||||
@@ -40,10 +41,16 @@ export function YamlViewer({ clusterCode, namespace, resource, name, onClose, on
|
||||
// autoEdit 时隐式启用清理(编辑入口必须有清理,否则 status/managedFields 会被 K8s 拒绝)
|
||||
const effectiveClean = cleanBeforeEdit || autoEdit;
|
||||
|
||||
const toEditableYaml = async (text: string) => {
|
||||
if (!effectiveClean) return text;
|
||||
const { yaml } = await parseEditableManifest(text);
|
||||
return yaml;
|
||||
};
|
||||
|
||||
const loadYaml = async () => {
|
||||
if (initialYaml) {
|
||||
setRawYaml(initialYaml);
|
||||
setEditYaml(effectiveClean ? cleanYAML(initialYaml) : initialYaml);
|
||||
setEditYaml(await toEditableYaml(initialYaml));
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
@@ -51,7 +58,7 @@ export function YamlViewer({ clusterCode, namespace, resource, name, onClose, on
|
||||
try {
|
||||
const text = await kubernetesApi.getResourceYaml(clusterCode, namespace, resource, name);
|
||||
setRawYaml(text);
|
||||
setEditYaml(effectiveClean ? cleanYAML(text) : text);
|
||||
setEditYaml(await toEditableYaml(text));
|
||||
} catch (e) {
|
||||
toast({ title: '获取YAML失败', description: (e as Record<string, any>).message, variant: 'destructive' });
|
||||
const err = `# Error: ${e.message}`;
|
||||
@@ -60,9 +67,8 @@ export function YamlViewer({ clusterCode, namespace, resource, name, onClose, on
|
||||
} finally { setLoading(false); }
|
||||
};
|
||||
|
||||
const enterEdit = () => {
|
||||
const cleaned = effectiveClean ? cleanYAML(rawYaml) : rawYaml;
|
||||
setEditYaml(cleaned);
|
||||
const enterEdit = async () => {
|
||||
setEditYaml(await toEditableYaml(rawYaml));
|
||||
setEditing(true);
|
||||
if (effectiveClean) {
|
||||
toast({ title: '已清理只读字段', description: '已剥离 status / managedFields / uid 等' });
|
||||
|
||||
Reference in new issue
Block a user