4f702b833a
工作负载: Pod, StatefulSet, DaemonSet, Job, CronJob 服务发现: Ingress 存储管理: PersistentVolume, PersistentVolumeClaim, StorageClass 配置与密钥: ConfigMap, Secret 安全与权限: ServiceAccount, Role, ClusterRole, RoleBinding, ClusterRoleBinding, NetworkPolicy 集群管理: Namespace 总计支持 26 个组件,覆盖 K8s 核心资源全谱
104 lines
2.7 KiB
JavaScript
104 lines
2.7 KiB
JavaScript
// K8s Namespace Schema - 由 ConfTemplate 生成
|
|
// 生成时间: 自动生成
|
|
|
|
export const k8sNamespaceSchema = {
|
|
id: 'k8s-namespace',
|
|
name: 'K8s Namespace',
|
|
icon: 'Layers',
|
|
category: '云原生',
|
|
description: 'Kubernetes 命名空间,用于资源隔离和组织',
|
|
format: 'yaml',
|
|
fileName: 'namespace.yaml',
|
|
groups: [
|
|
{
|
|
title: '基础信息',
|
|
fields: [
|
|
{
|
|
key: 'name',
|
|
label: 'Namespace 名称',
|
|
type: 'text',
|
|
placeholder: 'my-namespace',
|
|
default: '',
|
|
required: true,
|
|
tip: '命名空间名称,必须符合 DNS 命名规范',
|
|
},
|
|
],
|
|
},
|
|
{
|
|
title: '标签配置',
|
|
fields: [
|
|
{
|
|
key: 'labelKey',
|
|
label: '标签键',
|
|
type: 'text',
|
|
placeholder: 'app',
|
|
default: 'app',
|
|
tip: '为命名空间添加标签键',
|
|
},
|
|
{
|
|
key: 'labelValue',
|
|
label: '标签值',
|
|
type: 'text',
|
|
placeholder: 'my-project',
|
|
default: 'my-project',
|
|
tip: '标签值',
|
|
},
|
|
],
|
|
},
|
|
],
|
|
}
|
|
|
|
function toYaml(obj, indent = 0) {
|
|
const lines = []
|
|
const prefix = ' '.repeat(indent)
|
|
|
|
for (const [key, value] of Object.entries(obj)) {
|
|
if (value === null || value === undefined || value === '') continue
|
|
|
|
if (Array.isArray(value)) {
|
|
lines.push(`${prefix}${key}:`)
|
|
for (const item of value) {
|
|
if (typeof item === 'object' && item !== null) {
|
|
const entries = Object.entries(item).filter(([, v]) => v !== null && v !== undefined && v !== '')
|
|
if (entries.length === 0) continue
|
|
const first = entries[0]
|
|
lines.push(`${prefix} - ${first[0]}: ${first[1]}`)
|
|
for (let i = 1; i < entries.length; i++) {
|
|
lines.push(`${prefix} ${entries[i][0]}: ${entries[i][1]}`)
|
|
}
|
|
} else {
|
|
lines.push(`${prefix} - ${item}`)
|
|
}
|
|
}
|
|
} else if (typeof value === 'object') {
|
|
lines.push(`${prefix}${key}:`)
|
|
lines.push(toYaml(value, indent + 1))
|
|
} else {
|
|
lines.push(`${prefix}${key}: ${value}`)
|
|
}
|
|
}
|
|
|
|
return lines.join('\n')
|
|
}
|
|
|
|
export function generateK8sNamespaceYaml(config) {
|
|
const ns = {
|
|
apiVersion: 'v1',
|
|
kind: 'Namespace',
|
|
metadata: {
|
|
name: config.name,
|
|
},
|
|
}
|
|
|
|
if (config.labelKey && config.labelValue) {
|
|
ns.metadata.labels = { [config.labelKey]: config.labelValue }
|
|
}
|
|
|
|
const header = `# K8s Namespace - 由 ConfTemplate 生成
|
|
# 生成时间: ${new Date().toLocaleString('zh-CN')}
|
|
# 部署命令: kubectl apply -f ${config.fileName || 'namespace.yaml'}
|
|
`
|
|
|
|
return header + '\n' + toYaml(ns)
|
|
}
|