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
@@ -0,0 +1 @@
|
||||
import{r as v,j as e,R as H,y as J,o as X}from"./vendor-codemirror-C7mXSpXt.js";import{B as R}from"./index-BBDEBVET.js";import{I as k}from"./input-e2KnvZus.js";import{L as w}from"./label-J75lkt_x.js";import{T as K}from"./textarea-Bhm4J_66.js";import{S as D,a as B,b as G,c as W,d as T}from"./select-B_wPmYeS.js";import{u as Q}from"./use-toast-CkA38LVP.js";import{k as I}from"./index-CoT9mL1C.js";import{p as Z,c as $,b as ee,d as se,e as te}from"./PodFileBrowser-D_SJAX96.js";import{D as re,f as oe,N as ae,j as ce,F as ne,X as de,L as z,$ as O,P as L,T as Y}from"./vendor-icons-Aso0-eeY.js";function ie(d,h,c){switch(d){case"services":return{apiVersion:"v1",kind:"Service",metadata:{name:c,namespace:h},spec:{type:"ClusterIP",selector:{},ports:[{name:"http",port:80,targetPort:80,protocol:"TCP"}]}};case"ingresses":return{apiVersion:"networking.k8s.io/v1",kind:"Ingress",metadata:{name:c,namespace:h},spec:{ingressClassName:"nginx",rules:[{host:"",http:{paths:[{path:"/",pathType:"Prefix",backend:{service:{name:"",port:{number:80}}}}]}}]}};case"configmaps":return{apiVersion:"v1",kind:"ConfigMap",metadata:{name:c,namespace:h},data:{}};case"secrets":return{apiVersion:"v1",kind:"Secret",metadata:{name:c,namespace:h},type:"Opaque",data:{}};case"pvcs":return{apiVersion:"v1",kind:"PersistentVolumeClaim",metadata:{name:c,namespace:h},spec:{accessModes:["ReadWriteOnce"],resources:{requests:{storage:"1Gi"}}}};default:return{apiVersion:"v1",kind:"Unknown",metadata:{name:c,namespace:h}}}}function Ne({clusterCode:d,namespace:h,resource:c,name:V,onClose:g,onSaved:N,isCreate:b=!1}){const{toast:i}=Q(),[f,x]=v.useState(!0),[m,y]=v.useState(!1),[S,r]=v.useState(""),[t,u]=v.useState(null),[j,P]=v.useState("visual"),[l,o]=v.useState(""),p=v.useCallback(async()=>{x(!0);try{if(b){const F=ie(c,h,V||"");u(F),o(JSON.stringify(F,null,2)),r("");return}const E=await I.getResourceYaml(d,h,c,V);r(E);const{manifest:M,yaml:A}=await Z(E);o(A),u(M),M||(P("yaml"),i({title:"可视化编辑不可用",description:"无法解析资源结构,已切换到 YAML 编辑模式"}))}catch(E){i({title:"加载失败",description:E.message,variant:"destructive"})}finally{x(!1)}},[d,h,c,V,b]);v.useEffect(()=>{p()},[p]);const s=async E=>{y(!0);try{const M=await te(E),A=E?.metadata?.name||V;if(b){if(!A?.trim()){i({title:"请填写名称",variant:"destructive"});return}await I.applyYAML(d,M),i({title:"创建成功",description:`${c}/${A}`})}else await I.updateResourceYaml(d,h,c,V,M),i({title:"保存成功",description:`${c}/${V} 已更新`});N?.(),g()}catch(M){i({title:b?"创建失败":"保存失败",description:M.message,variant:"destructive"})}finally{y(!1)}},a=async()=>{y(!0);try{const E=$(l);b?(await I.applyYAML(d,E),i({title:"创建成功",description:"YAML 已应用"})):(await I.updateResourceYaml(d,h,c,V,E),i({title:"YAML 已应用",description:`${c}/${V} 更新成功`})),N?.(),g()}catch(E){i({title:"保存失败",description:E.message,variant:"destructive"})}finally{y(!1)}},n=async()=>{const E=await ee(l);if(!E){i({title:"无法解析 YAML",description:"请检查语法后继续用 YAML 模式",variant:"destructive"});return}u(E),P("visual")},C=async()=>{if(t){const E=await se(t);o($(E))}P("yaml")},q={configmaps:{title:"ConfigMap",icon:ne,color:"text-blue-400"},secrets:{title:"Secret",icon:ce,color:"text-amber-400"},services:{title:"Service",icon:ae,color:"text-cyan-400"},ingresses:{title:"Ingress",icon:oe,color:"text-purple-400"},pvcs:{title:"PersistentVolumeClaim",icon:re,color:"text-emerald-400"}},_=q[c]||q.configmaps,U=_.icon;return e.jsx("div",{"code-path":"src/components/kubernetes/ResourceVisualEditor.tsx:135:5",className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",onClick:g,children:e.jsxs("div",{"code-path":"src/components/kubernetes/ResourceVisualEditor.tsx:136:7",className:"bg-[var(--dg-bg-primary)] border border-[var(--dg-border)] rounded-xl w-[90vw] max-w-3xl max-h-[85vh] flex flex-col shadow-2xl",onClick:E=>E.stopPropagation(),children:[e.jsxs("div",{"code-path":"src/components/kubernetes/ResourceVisualEditor.tsx:138:9",className:"flex items-center justify-between p-4 border-b border-[var(--dg-border)]",children:[e.jsxs("div",{"code-path":"src/components/kubernetes/ResourceVisualEditor.tsx:139:11",className:"flex items-center gap-2",children:[e.jsx(U,{"code-path":"src/components/kubernetes/ResourceVisualEditor.tsx:140:13",className:`h-5 w-5 ${_.color}`}),e.jsxs("div",{"code-path":"src/components/kubernetes/ResourceVisualEditor.tsx:141:13",children:[e.jsx("h2",{"code-path":"src/components/kubernetes/ResourceVisualEditor.tsx:142:15",className:"text-lg font-bold text-[var(--dg-text-primary)]",children:b?`新建 ${_.title}`:`${_.title} 编辑`}),e.jsxs("p",{"code-path":"src/components/kubernetes/ResourceVisualEditor.tsx:143:15",className:"text-xs text-[var(--dg-text-muted)]",children:[b?h:V," · ",h," · ",d]})]})]}),e.jsxs("div",{"code-path":"src/components/kubernetes/ResourceVisualEditor.tsx:146:11",className:"flex items-center gaLine truncated
|
||||
Reference in new issue
Block a user