|
1 | 1 | package metadata
|
2 | 2 |
|
3 |
| -import "strings" |
| 3 | +import ( |
| 4 | + "github.com/mark3labs/mcp-go/server" |
| 5 | +) |
| 6 | + |
| 7 | +// ResourceMetadata 封装资源的元数据信息 |
| 8 | +type ResourceMetadata struct { |
| 9 | + Cluster string |
| 10 | + Namespace string |
| 11 | + Name string |
| 12 | + Group string |
| 13 | + Version string |
| 14 | + Kind string |
| 15 | +} |
| 16 | +type ServerConfig struct { |
| 17 | + Name string |
| 18 | + Version string |
| 19 | + Port int |
| 20 | + ServerOptions []server.ServerOption |
| 21 | + SSEOption []server.SSEOption |
| 22 | + Metadata map[string]string // 元数据 |
| 23 | + AuthKey string // 认证key |
| 24 | +} |
4 | 25 |
|
5 | 26 | type ResourceInfo struct {
|
6 | 27 | Group string
|
7 | 28 | Version string
|
8 | 29 | Kind string
|
9 | 30 | Namespaced bool
|
10 | 31 | }
|
11 |
| - |
12 |
| -var resourceMap = map[string]ResourceInfo{ |
13 |
| - // 命名空间级别资源 |
14 |
| - "pod": {Group: "", Version: "v1", Kind: "Pod", Namespaced: true}, |
15 |
| - "deployment": {Group: "apps", Version: "v1", Kind: "Deployment", Namespaced: true}, |
16 |
| - "statefulset": {Group: "apps", Version: "v1", Kind: "StatefulSet", Namespaced: true}, |
17 |
| - "daemonset": {Group: "apps", Version: "v1", Kind: "DaemonSet", Namespaced: true}, |
18 |
| - "replicaset": {Group: "apps", Version: "v1", Kind: "ReplicaSet", Namespaced: true}, |
19 |
| - "service": {Group: "", Version: "v1", Kind: "Service", Namespaced: true}, |
20 |
| - "configmap": {Group: "", Version: "v1", Kind: "ConfigMap", Namespaced: true}, |
21 |
| - "secret": {Group: "", Version: "v1", Kind: "Secret", Namespaced: true}, |
22 |
| - "ingress": {Group: "networking.k8s.io", Version: "v1", Kind: "Ingress", Namespaced: true}, |
23 |
| - "networkpolicy": {Group: "networking.k8s.io", Version: "v1", Kind: "NetworkPolicy", Namespaced: true}, |
24 |
| - "role": {Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "Role", Namespaced: true}, |
25 |
| - "rolebinding": {Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "RoleBinding", Namespaced: true}, |
26 |
| - "serviceaccount": {Group: "", Version: "v1", Kind: "ServiceAccount", Namespaced: true}, |
27 |
| - "persistentvolumeclaim": {Group: "", Version: "v1", Kind: "PersistentVolumeClaim", Namespaced: true}, |
28 |
| - "horizontalpodautoscaler": {Group: "autoscaling", Version: "v2", Kind: "HorizontalPodAutoscaler", Namespaced: true}, |
29 |
| - "cronjob": {Group: "batch", Version: "v1", Kind: "CronJob", Namespaced: true}, |
30 |
| - "job": {Group: "batch", Version: "v1", Kind: "Job", Namespaced: true}, |
31 |
| - "node": {Group: "", Version: "v1", Kind: "Node", Namespaced: false}, |
32 |
| - "namespace": {Group: "", Version: "v1", Kind: "Namespace", Namespaced: false}, |
33 |
| - "persistentvolume": {Group: "", Version: "v1", Kind: "PersistentVolume", Namespaced: false}, |
34 |
| - "clusterrole": {Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "ClusterRole", Namespaced: false}, |
35 |
| - "clusterrolebinding": {Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "ClusterRoleBinding", Namespaced: false}, |
36 |
| - "storageclass": {Group: "storage.k8s.io", Version: "v1", Kind: "StorageClass", Namespaced: false}, |
37 |
| - "customresourcedefinition": {Group: "apiextensions.k8s.io", Version: "v1", Kind: "CustomResourceDefinition", Namespaced: false}, |
38 |
| - "mutatingwebhookconfiguration": {Group: "admissionregistration.k8s.io", Version: "v1", Kind: "MutatingWebhookConfiguration", Namespaced: false}, |
39 |
| - "validatingwebhookconfiguration": {Group: "admissionregistration.k8s.io", Version: "v1", Kind: "ValidatingWebhookConfiguration", Namespaced: false}, |
40 |
| -} |
41 |
| - |
42 |
| -// GetResourceInfo 根据资源类型字符串返回资源信息 |
43 |
| -func GetResourceInfo(resourceType string) (ResourceInfo, bool) { |
44 |
| - resourceType = strings.ToLower(resourceType) |
45 |
| - if info, exists := resourceMap[resourceType]; exists { |
46 |
| - return info, true |
47 |
| - } |
48 |
| - return ResourceInfo{}, false |
49 |
| -} |
50 |
| - |
51 |
| -// IsNamespaced 判断资源是否为命名空间级别 |
52 |
| -func IsNamespaced(resourceType string) bool { |
53 |
| - resourceType = strings.ToLower(resourceType) |
54 |
| - if info, exists := resourceMap[resourceType]; exists { |
55 |
| - return info.Namespaced |
56 |
| - } |
57 |
| - return false |
58 |
| -} |
0 commit comments