diagrams-js 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -39
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/providers/yaml.js +1 -1
- package/package.json +2 -2
- package/skills/plugin-kubernetes/SKILL.md +673 -0
- package/dist/chunk-WfQuXRBF.js +0 -1
package/README.md
CHANGED
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
|
|
28
28
|
[](./docs/static/examples/example3-event-processing.svg)
|
|
29
29
|
|
|
30
|
-
Check the [examples page](https://diagrams-js.hatemhosny.dev/getting-started/examples) for a full list of examples.
|
|
30
|
+
Check the [examples page](https://diagrams-js.hatemhosny.dev/docs/getting-started/examples) for a full list of examples.
|
|
31
31
|
|
|
32
32
|
## Interactive Playground
|
|
33
33
|
|
|
@@ -92,33 +92,32 @@ const svg = await diagram.render();
|
|
|
92
92
|
📚 **Full documentation**: [https://diagrams-js.hatemhosny.dev](https://diagrams-js.hatemhosny.dev)
|
|
93
93
|
|
|
94
94
|
- [Getting Started](https://diagrams-js.hatemhosny.dev/docs/getting-started/installation)
|
|
95
|
-
- [
|
|
96
|
-
- [Examples](https://diagrams-js.hatemhosny.dev/getting-started/examples)
|
|
95
|
+
- [Examples](https://diagrams-js.hatemhosny.dev/docs/getting-started/examples)
|
|
97
96
|
- [Guides](https://diagrams-js.hatemhosny.dev/docs/guides/diagram)
|
|
98
97
|
- [Providers](https://diagrams-js.hatemhosny.dev/docs/guides/providers)
|
|
99
98
|
- [Playground](https://diagrams-js.hatemhosny.dev/playground)
|
|
100
99
|
|
|
101
100
|
## Supported Providers
|
|
102
101
|
|
|
103
|
-
| Provider
|
|
104
|
-
|
|
|
105
|
-
| [AWS](https://diagrams-js.hatemhosny.dev/
|
|
106
|
-
| [Azure](https://diagrams-js.hatemhosny.dev/
|
|
107
|
-
| [GCP](https://diagrams-js.hatemhosny.dev/
|
|
108
|
-
| [Kubernetes](https://diagrams-js.hatemhosny.dev/
|
|
109
|
-
| [OnPrem](https://diagrams-js.hatemhosny.dev/
|
|
110
|
-
| [AlibabaCloud](https://diagrams-js.hatemhosny.dev/
|
|
111
|
-
| [DigitalOcean](https://diagrams-js.hatemhosny.dev/
|
|
112
|
-
| [Elastic](https://diagrams-js.hatemhosny.dev/
|
|
113
|
-
| [Firebase](https://diagrams-js.hatemhosny.dev/
|
|
114
|
-
| [Generic](https://diagrams-js.hatemhosny.dev/
|
|
115
|
-
| [GIS](https://diagrams-js.hatemhosny.dev/
|
|
116
|
-
| [IBM](https://diagrams-js.hatemhosny.dev/
|
|
117
|
-
| [OCI](https://diagrams-js.hatemhosny.dev/
|
|
118
|
-
| [OpenStack](https://diagrams-js.hatemhosny.dev/
|
|
119
|
-
| [Outscale](https://diagrams-js.hatemhosny.dev/
|
|
120
|
-
| [Programming](https://diagrams-js.hatemhosny.dev/
|
|
121
|
-
| [SaaS](https://diagrams-js.hatemhosny.dev/
|
|
102
|
+
| Provider | Description |
|
|
103
|
+
| -------------------------------------------------------------------------- | ---------------------------------------- |
|
|
104
|
+
| [AWS](https://diagrams-js.hatemhosny.dev/docs/nodes/aws) | Amazon Web Services nodes |
|
|
105
|
+
| [Azure](https://diagrams-js.hatemhosny.dev/docs/nodes/azure) | Microsoft Azure nodes |
|
|
106
|
+
| [GCP](https://diagrams-js.hatemhosny.dev/docs/nodes/gcp) | Google Cloud Platform nodes |
|
|
107
|
+
| [Kubernetes](https://diagrams-js.hatemhosny.dev/docs/nodes/k8s) | Kubernetes nodes |
|
|
108
|
+
| [OnPrem](https://diagrams-js.hatemhosny.dev/docs/nodes/onprem) | On-premises infrastructure nodes |
|
|
109
|
+
| [AlibabaCloud](https://diagrams-js.hatemhosny.dev/docs/nodes/alibabacloud) | Alibaba Cloud nodes |
|
|
110
|
+
| [DigitalOcean](https://diagrams-js.hatemhosny.dev/docs/nodes/digitalocean) | DigitalOcean nodes |
|
|
111
|
+
| [Elastic](https://diagrams-js.hatemhosny.dev/docs/nodes/elastic) | Elastic Stack nodes |
|
|
112
|
+
| [Firebase](https://diagrams-js.hatemhosny.dev/docs/nodes/firebase) | Firebase nodes |
|
|
113
|
+
| [Generic](https://diagrams-js.hatemhosny.dev/docs/nodes/generic) | Generic computing nodes |
|
|
114
|
+
| [GIS](https://diagrams-js.hatemhosny.dev/docs/nodes/gis) | GIS nodes |
|
|
115
|
+
| [IBM](https://diagrams-js.hatemhosny.dev/docs/nodes/ibm) | IBM Cloud nodes |
|
|
116
|
+
| [OCI](https://diagrams-js.hatemhosny.dev/docs/nodes/oci) | Oracle Cloud Infrastructure nodes |
|
|
117
|
+
| [OpenStack](https://diagrams-js.hatemhosny.dev/docs/nodes/openstack) | OpenStack nodes |
|
|
118
|
+
| [Outscale](https://diagrams-js.hatemhosny.dev/docs/nodes/outscale) | Outscale nodes |
|
|
119
|
+
| [Programming](https://diagrams-js.hatemhosny.dev/docs/nodes/programming) | Programming language and framework nodes |
|
|
120
|
+
| [SaaS](https://diagrams-js.hatemhosny.dev/docs/nodes/saas) | SaaS application nodes |
|
|
122
121
|
|
|
123
122
|
View the [full list](https://diagrams-js.hatemhosny.dev/docs/guides/providers)
|
|
124
123
|
|
|
@@ -150,23 +149,6 @@ vp check
|
|
|
150
149
|
vp run build
|
|
151
150
|
```
|
|
152
151
|
|
|
153
|
-
### Project Structure
|
|
154
|
-
|
|
155
|
-
```
|
|
156
|
-
diagrams-js/
|
|
157
|
-
├── src/ # Source code
|
|
158
|
-
│ ├── index.ts # Main exports
|
|
159
|
-
│ ├── Diagram.ts # Core diagram class
|
|
160
|
-
│ ├── Node.ts # Base node class
|
|
161
|
-
│ ├── Edge.ts # Edge/connection class
|
|
162
|
-
│ ├── Cluster.ts # Cluster/grouping class
|
|
163
|
-
│ └── providers/ # Auto-generated provider classes
|
|
164
|
-
├── resources/ # Icon resources (PNG files)
|
|
165
|
-
├── scripts/ # Build and generation scripts
|
|
166
|
-
├── tests/ # Test files
|
|
167
|
-
└── docs/ # Documentation site
|
|
168
|
-
```
|
|
169
|
-
|
|
170
152
|
## Contributing
|
|
171
153
|
|
|
172
154
|
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { dump, load } from "js-yaml";
|
|
1
|
+
import { dump, load, loadAll } from "js-yaml";
|
|
2
2
|
|
|
3
3
|
//#region src/providers/resources-list.d.ts
|
|
4
4
|
declare namespace resources_list_d_exports {
|
|
@@ -12,7 +12,7 @@ interface ResourceInfo {
|
|
|
12
12
|
declare const allResources: ResourceInfo[];
|
|
13
13
|
declare function findResource(query: string): ResourceInfo[];
|
|
14
14
|
declare namespace yaml_d_exports {
|
|
15
|
-
export { dump, load };
|
|
15
|
+
export { dump, load, loadAll };
|
|
16
16
|
}
|
|
17
17
|
//#endregion
|
|
18
18
|
//#region src/Cluster.d.ts
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{t as e}from"
|
|
1
|
+
import{t as e}from"data:application/javascript;base64,dmFyIGU9T2JqZWN0LmRlZmluZVByb3BlcnR5LHQ9KHQsbik9PntsZXQgcj17fTtmb3IodmFyIGkgaW4gdCllKHIsaSx7Z2V0OnRbaV0sZW51bWVyYWJsZTohMH0pO3JldHVybiBufHxlKHIsU3ltYm9sLnRvU3RyaW5nVGFnLHt2YWx1ZTpgTW9kdWxlYH0pLHJ9O2V4cG9ydHt0fTs=";
|
|
2
2
|
/*!
|
|
3
3
|
Viz.js 3.25.0
|
|
4
4
|
Copyright (c) Michael Daines
|
package/dist/providers/yaml.js
CHANGED
|
@@ -29,7 +29,7 @@ function Ce(e){return typeof e>"u"||e===null}function $e(e){return typeof e=="ob
|
|
|
29
29
|
`+e.slice(r,u),r=u+1),o=f;return c+=`
|
|
30
30
|
`,e.length-r>n&&o>r?c+=e.slice(r,o)+`
|
|
31
31
|
`+e.slice(o+1):c+=e.slice(r),c.slice(1)}function cr(e){for(var n="",i=0,l,r=0;r<e.length;i>=65536?r+=2:r++)i=M(e,r),l=_[i],!l&&H(i)?(n+=e[r],i>=65536&&(n+=e[r+1])):n+=l||Ji(i);return n}function ar(e,n,i){var l="",r=e.tag,u,o,f;for(u=0,o=i.length;u<o;u+=1)f=i[u],e.replacer&&(f=e.replacer.call(i,String(u),f)),(b(e,n,f,!1,!1)||typeof f>"u"&&b(e,n,null,!1,!1))&&(l!==""&&(l+=","+(e.condenseFlow?"":" ")),l+=e.dump);e.tag=r,e.dump="["+l+"]"}function ve(e,n,i,l){var r="",u=e.tag,o,f,c;for(o=0,f=i.length;o<f;o+=1)c=i[o],e.replacer&&(c=e.replacer.call(i,String(o),c)),(b(e,n+1,c,!0,!0,!1,!0)||typeof c>"u"&&b(e,n+1,null,!0,!0,!1,!0))&&((!l||r!=="")&&(r+=z(e,n)),e.dump&&B===e.dump.charCodeAt(0)?r+="-":r+="- ",r+=e.dump);e.tag=u,e.dump=r||"[]"}function pr(e,n,i){var l="",r=e.tag,u=Object.keys(i),o,f,c,a,t;for(o=0,f=u.length;o<f;o+=1)t="",l!==""&&(t+=", "),e.condenseFlow&&(t+='"'),c=u[o],a=i[c],e.replacer&&(a=e.replacer.call(i,c,a)),b(e,n,c,!1,!1)&&(e.dump.length>1024&&(t+="? "),t+=e.dump+(e.condenseFlow?'"':"")+":"+(e.condenseFlow?"":" "),b(e,n,a,!1,!1)&&(t+=e.dump,l+=t));e.tag=r,e.dump="{"+l+"}"}function tr(e,n,i,l){var r="",u=e.tag,o=Object.keys(i),f,c,a,t,p,d;if(e.sortKeys===!0)o.sort();else if(typeof e.sortKeys=="function")o.sort(e.sortKeys);else if(e.sortKeys)throw new w("sortKeys must be a boolean or a function");for(f=0,c=o.length;f<c;f+=1)d="",(!l||r!=="")&&(d+=z(e,n)),a=o[f],t=i[a],e.replacer&&(t=e.replacer.call(i,a,t)),b(e,n+1,a,!0,!0,!0)&&(p=e.tag!==null&&e.tag!=="?"||e.dump&&e.dump.length>1024,p&&(e.dump&&B===e.dump.charCodeAt(0)?d+="?":d+="? "),d+=e.dump,p&&(d+=z(e,n)),b(e,n+1,t,!0,p)&&(e.dump&&B===e.dump.charCodeAt(0)?d+=":":d+=": ",d+=e.dump,r+=d));e.tag=u,e.dump=r||"{}"}function ye(e,n,i){var l,r,u,o,f,c;for(r=i?e.explicitTypes:e.implicitTypes,u=0,o=r.length;u<o;u+=1)if(f=r[u],(f.instanceOf||f.predicate)&&(!f.instanceOf||typeof n=="object"&&n instanceof f.instanceOf)&&(!f.predicate||f.predicate(n))){if(i?f.multi&&f.representName?e.tag=f.representName(n):e.tag=f.tag:e.tag="?",f.represent){if(c=e.styleMap[f.tag]||f.defaultStyle,Me.call(f.represent)==="[object Function]")l=f.represent(n,c);else if(Ye.call(f.represent,c))l=f.represent[c](n,c);else throw new w("!<"+f.tag+'> tag resolver accepts not "'+c+'" style');e.dump=l}return!0}return!1}function b(e,n,i,l,r,u,o){e.tag=null,e.dump=i,ye(e,i,!1)||ye(e,i,!0);var f=Me.call(e.dump),c=l,a;l&&(l=e.flowLevel<0||e.flowLevel>n);var t=f==="[object Object]"||f==="[object Array]",p,d;if(t&&(p=e.duplicates.indexOf(i),d=p!==-1),(e.tag!==null&&e.tag!=="?"||d||e.indent!==2&&n>0)&&(r=!1),d&&e.usedDuplicates[p])e.dump="*ref_"+p;else{if(t&&d&&!e.usedDuplicates[p]&&(e.usedDuplicates[p]=!0),f==="[object Object]")l&&Object.keys(e.dump).length!==0?(tr(e,n,e.dump,r),d&&(e.dump="&ref_"+p+e.dump)):(pr(e,n,e.dump),d&&(e.dump="&ref_"+p+" "+e.dump));else if(f==="[object Array]")l&&e.dump.length!==0?(e.noArrayIndent&&!o&&n>0?ve(e,n-1,e.dump,r):ve(e,n,e.dump,r),d&&(e.dump="&ref_"+p+e.dump)):(ar(e,n,e.dump),d&&(e.dump="&ref_"+p+" "+e.dump));else if(f==="[object String]")e.tag!=="?"&&ur(e,e.dump,n,u,c);else{if(f==="[object Undefined]")return!1;if(e.skipInvalid)return!1;throw new w("unacceptable kind of an object to dump "+f)}e.tag!==null&&e.tag!=="?"&&(a=encodeURI(e.tag[0]==="!"?e.tag.slice(1):e.tag).replace(/!/g,"%21"),e.tag[0]==="!"?a="!"+a:a.slice(0,18)==="tag:yaml.org,2002:"?a="!!"+a.slice(18):a="!<"+a+">",e.dump=a+" "+e.dump)}return!0}function hr(e,n){var i=[],l=[],r,u;for(ee(e,i,l),r=0,u=l.length;r<u;r+=1)n.duplicates.push(i[l[r]]);n.usedDuplicates=new Array(u)}function ee(e,n,i){var l,r,u;if(e!==null&&typeof e=="object")if(r=n.indexOf(e),r!==-1)i.indexOf(r)===-1&&i.push(r);else if(n.push(e),Array.isArray(e))for(r=0,u=e.length;r<u;r+=1)ee(e[r],n,i);else for(l=Object.keys(e),r=0,u=l.length;r<u;r+=1)ee(e[l[r]],n,i)}function dr(e,n){n=n||{};var i=new nr(n);i.noRefs||hr(e,i);var l=e;return i.replacer&&(l=i.replacer.call({"":l},"",l)),b(i,0,l,!0,!0)?i.dump+`
|
|
32
|
-
`:""}var sr=dr,mr={dump:sr};function oe(e,n){return function(){throw new Error("Function yaml."+e+" is removed in js-yaml 4. Use yaml."+n+" instead, which is now safe by default.")}}var xr=De.load,
|
|
32
|
+
`:""}var sr=dr,mr={dump:sr};function oe(e,n){return function(){throw new Error("Function yaml."+e+" is removed in js-yaml 4. Use yaml."+n+" instead, which is now safe by default.")}}var xr=De.load,gr=De.loadAll,Ar=mr.dump;var vr=oe("safeLoad","load"),yr=oe("safeLoadAll","loadAll"),Cr=oe("safeDump","dump");export{Ar as dump,xr as load,gr as loadAll};
|
|
33
33
|
/*! Bundled license information:
|
|
34
34
|
|
|
35
35
|
js-yaml/dist/js-yaml.mjs:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "diagrams-js",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "A TypeScript port of the diagrams Python library for drawing cloud system architecture diagrams as code",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"architecture",
|
|
@@ -976,7 +976,7 @@
|
|
|
976
976
|
},
|
|
977
977
|
"scripts": {
|
|
978
978
|
"build": "vp run build:core && vp run build:providers && vp run build:fix",
|
|
979
|
-
"build:core": "vp pack src/index.ts",
|
|
979
|
+
"build:core": "vp pack src/index.ts && node scripts/inline-chunks.mjs",
|
|
980
980
|
"build:providers": "node scripts/build-providers.mjs",
|
|
981
981
|
"build:fix": "vp check --fix",
|
|
982
982
|
"dev": "vp build --watch",
|
|
@@ -0,0 +1,673 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: plugin-kubernetes
|
|
3
|
+
description: >-
|
|
4
|
+
Import and export Kubernetes YAML manifests with diagrams-js.
|
|
5
|
+
Convert Kubernetes manifests to architecture diagrams and vice versa.
|
|
6
|
+
type: feature
|
|
7
|
+
library: diagrams-js
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# Kubernetes Plugin for diagrams-js
|
|
11
|
+
|
|
12
|
+
The Kubernetes plugin enables bidirectional conversion between Kubernetes YAML manifests and architecture diagrams.
|
|
13
|
+
|
|
14
|
+
## When to Use This Skill
|
|
15
|
+
|
|
16
|
+
Use this skill when you need to:
|
|
17
|
+
|
|
18
|
+
- Visualize Kubernetes configurations as architecture diagrams
|
|
19
|
+
- Generate Kubernetes manifests from existing diagrams
|
|
20
|
+
- Import multi-resource Kubernetes applications into diagrams
|
|
21
|
+
- Export diagrams to Kubernetes deployment configurations
|
|
22
|
+
- Document container orchestration setups
|
|
23
|
+
|
|
24
|
+
## Quick Start
|
|
25
|
+
|
|
26
|
+
### Installation
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install @diagrams-js/plugin-kubernetes
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Import from Kubernetes YAML
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
import { Diagram } from "diagrams-js";
|
|
36
|
+
import { kubernetesPlugin } from "@diagrams-js/plugin-kubernetes";
|
|
37
|
+
|
|
38
|
+
const diagram = Diagram("My K8s Application");
|
|
39
|
+
|
|
40
|
+
// Register the plugin
|
|
41
|
+
await diagram.registerPlugins([kubernetesPlugin]);
|
|
42
|
+
|
|
43
|
+
// Import from Kubernetes YAML
|
|
44
|
+
const k8sYaml = `
|
|
45
|
+
apiVersion: apps/v1
|
|
46
|
+
kind: Deployment
|
|
47
|
+
metadata:
|
|
48
|
+
name: web-deployment
|
|
49
|
+
spec:
|
|
50
|
+
replicas: 3
|
|
51
|
+
selector:
|
|
52
|
+
matchLabels:
|
|
53
|
+
app: web
|
|
54
|
+
template:
|
|
55
|
+
spec:
|
|
56
|
+
containers:
|
|
57
|
+
- name: web
|
|
58
|
+
image: nginx:latest
|
|
59
|
+
ports:
|
|
60
|
+
- containerPort: 80
|
|
61
|
+
`;
|
|
62
|
+
|
|
63
|
+
await diagram.import(k8sYaml, "kubernetes");
|
|
64
|
+
|
|
65
|
+
// Render the diagram
|
|
66
|
+
const svg = await diagram.render();
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Export to Kubernetes YAML
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
import { Diagram, Node } from "diagrams-js";
|
|
73
|
+
import { kubernetesPlugin } from "@diagrams-js/plugin-kubernetes";
|
|
74
|
+
|
|
75
|
+
const diagram = Diagram("My K8s Application");
|
|
76
|
+
|
|
77
|
+
// Create nodes with Kubernetes metadata
|
|
78
|
+
const deployment = diagram.add(Node("web-deployment"));
|
|
79
|
+
deployment.metadata = {
|
|
80
|
+
kubernetes: {
|
|
81
|
+
kind: "Deployment",
|
|
82
|
+
namespace: "default",
|
|
83
|
+
spec: {
|
|
84
|
+
replicas: 3,
|
|
85
|
+
selector: { matchLabels: { app: "web" } },
|
|
86
|
+
template: {
|
|
87
|
+
spec: {
|
|
88
|
+
containers: [{ name: "web", image: "nginx:latest", ports: [{ containerPort: 80 }] }],
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// Register plugin and export
|
|
96
|
+
await diagram.registerPlugins([kubernetesPlugin]);
|
|
97
|
+
const k8sYaml = await diagram.export("kubernetes");
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Features
|
|
101
|
+
|
|
102
|
+
### Import Capabilities
|
|
103
|
+
|
|
104
|
+
- Parse Kubernetes YAML manifests (single or multi-document)
|
|
105
|
+
- Create nodes for each resource with appropriate Kubernetes icons
|
|
106
|
+
- Support for all common Kubernetes resource types
|
|
107
|
+
- Create edges for service-to-deployment relationships
|
|
108
|
+
- Create clusters for namespaces
|
|
109
|
+
- Store Kubernetes-specific metadata on nodes
|
|
110
|
+
|
|
111
|
+
### Supported Resource Types
|
|
112
|
+
|
|
113
|
+
**Workloads:**
|
|
114
|
+
|
|
115
|
+
- Deployment
|
|
116
|
+
- StatefulSet
|
|
117
|
+
- DaemonSet
|
|
118
|
+
- ReplicaSet
|
|
119
|
+
- Pod
|
|
120
|
+
- Job
|
|
121
|
+
- CronJob
|
|
122
|
+
|
|
123
|
+
**Services & Networking:**
|
|
124
|
+
|
|
125
|
+
- Service
|
|
126
|
+
- Ingress
|
|
127
|
+
- NetworkPolicy
|
|
128
|
+
|
|
129
|
+
**Storage:**
|
|
130
|
+
|
|
131
|
+
- ConfigMap
|
|
132
|
+
- Secret
|
|
133
|
+
- PersistentVolume
|
|
134
|
+
- PersistentVolumeClaim
|
|
135
|
+
- StorageClass
|
|
136
|
+
|
|
137
|
+
**RBAC:**
|
|
138
|
+
|
|
139
|
+
- Role
|
|
140
|
+
- RoleBinding
|
|
141
|
+
- ClusterRole
|
|
142
|
+
- ClusterRoleBinding
|
|
143
|
+
- ServiceAccount
|
|
144
|
+
|
|
145
|
+
**Cluster:**
|
|
146
|
+
|
|
147
|
+
- Namespace
|
|
148
|
+
- Node
|
|
149
|
+
- HorizontalPodAutoscaler
|
|
150
|
+
|
|
151
|
+
### Export Capabilities
|
|
152
|
+
|
|
153
|
+
- Export diagrams to Kubernetes YAML format
|
|
154
|
+
- Generate valid Kubernetes manifests
|
|
155
|
+
- Preserve resource configuration (replicas, selectors, ports, etc.)
|
|
156
|
+
- Support for multi-document YAML output
|
|
157
|
+
|
|
158
|
+
## Configuration
|
|
159
|
+
|
|
160
|
+
### Custom Resource Mappings
|
|
161
|
+
|
|
162
|
+
You can customize which icons are used for specific Kubernetes resources:
|
|
163
|
+
|
|
164
|
+
```typescript
|
|
165
|
+
import { Diagram } from "diagrams-js";
|
|
166
|
+
import { createKubernetesPlugin } from "@diagrams-js/plugin-kubernetes";
|
|
167
|
+
|
|
168
|
+
const diagram = Diagram("My K8s Application");
|
|
169
|
+
|
|
170
|
+
// Create plugin with custom resource mappings
|
|
171
|
+
const plugin = createKubernetesPlugin({
|
|
172
|
+
defaultNamespace: "production",
|
|
173
|
+
imageMappings: {
|
|
174
|
+
// 1. Provider icon mapping - use built-in provider icons
|
|
175
|
+
"my-custom-deployment": {
|
|
176
|
+
provider: "onprem",
|
|
177
|
+
type: "compute",
|
|
178
|
+
resource: "Server",
|
|
179
|
+
},
|
|
180
|
+
"my-custom-service": {
|
|
181
|
+
provider: "onprem",
|
|
182
|
+
type: "database",
|
|
183
|
+
resource: "Postgresql",
|
|
184
|
+
},
|
|
185
|
+
|
|
186
|
+
// 2. Direct URL string - use a custom image URL
|
|
187
|
+
"my-frontend": "https://example.com/react-icon.png",
|
|
188
|
+
|
|
189
|
+
// 3. URL object - same as string but as object
|
|
190
|
+
"my-backend": {
|
|
191
|
+
url: "https://example.com/node-icon.svg",
|
|
192
|
+
},
|
|
193
|
+
|
|
194
|
+
// 4. Iconify icon - use icons from Iconify (https://iconify.design/)
|
|
195
|
+
// Format: { iconify: "prefix:name" }
|
|
196
|
+
"custom-app": {
|
|
197
|
+
iconify: "logos:kubernetes",
|
|
198
|
+
},
|
|
199
|
+
"redis-cache": {
|
|
200
|
+
iconify: "logos:redis",
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
await diagram.registerPlugins([plugin]);
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
#### Iconify Icons
|
|
209
|
+
|
|
210
|
+
The plugin supports [Iconify](https://iconify.design/) icons, which provides access to 200,000+ open source icons:
|
|
211
|
+
|
|
212
|
+
```typescript
|
|
213
|
+
{
|
|
214
|
+
iconify: "logos:kubernetes"; // Kubernetes logo
|
|
215
|
+
iconify: "logos:redis"; // Redis logo
|
|
216
|
+
iconify: "mdi:server"; // Material Design server icon
|
|
217
|
+
}
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
#### Mapping Priority
|
|
221
|
+
|
|
222
|
+
The plugin checks mappings by **resource name** first, then falls back to **resource kind**:
|
|
223
|
+
|
|
224
|
+
```yaml
|
|
225
|
+
# deployment.yaml
|
|
226
|
+
apiVersion: apps/v1
|
|
227
|
+
kind: Deployment
|
|
228
|
+
metadata:
|
|
229
|
+
name: my-api # Would normally show Deployment icon
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
```typescript
|
|
233
|
+
// This mapping by RESOURCE NAME takes precedence
|
|
234
|
+
imageMappings: {
|
|
235
|
+
"my-api": { iconify: "logos:aws" } // Shows AWS icon instead of Deployment
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// This mapping by KIND is the fallback
|
|
239
|
+
imageMappings: {
|
|
240
|
+
"Deployment": { iconify: "logos:kubernetes" } // Used if no "my-api" mapping
|
|
241
|
+
}
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
## Examples
|
|
245
|
+
|
|
246
|
+
### Visualize a Microservices Architecture
|
|
247
|
+
|
|
248
|
+
```typescript
|
|
249
|
+
import { Diagram } from "diagrams-js";
|
|
250
|
+
import { kubernetesPlugin } from "@diagrams-js/plugin-kubernetes";
|
|
251
|
+
|
|
252
|
+
const k8sYaml = `
|
|
253
|
+
apiVersion: apps/v1
|
|
254
|
+
kind: Deployment
|
|
255
|
+
metadata:
|
|
256
|
+
name: frontend
|
|
257
|
+
spec:
|
|
258
|
+
replicas: 3
|
|
259
|
+
selector:
|
|
260
|
+
matchLabels:
|
|
261
|
+
app: frontend
|
|
262
|
+
template:
|
|
263
|
+
spec:
|
|
264
|
+
containers:
|
|
265
|
+
- name: frontend
|
|
266
|
+
image: nginx:alpine
|
|
267
|
+
ports:
|
|
268
|
+
- containerPort: 80
|
|
269
|
+
---
|
|
270
|
+
apiVersion: v1
|
|
271
|
+
kind: Service
|
|
272
|
+
metadata:
|
|
273
|
+
name: frontend-service
|
|
274
|
+
spec:
|
|
275
|
+
selector:
|
|
276
|
+
app: frontend
|
|
277
|
+
ports:
|
|
278
|
+
- port: 80
|
|
279
|
+
---
|
|
280
|
+
apiVersion: apps/v1
|
|
281
|
+
kind: Deployment
|
|
282
|
+
metadata:
|
|
283
|
+
name: api
|
|
284
|
+
spec:
|
|
285
|
+
replicas: 2
|
|
286
|
+
selector:
|
|
287
|
+
matchLabels:
|
|
288
|
+
app: api
|
|
289
|
+
template:
|
|
290
|
+
spec:
|
|
291
|
+
containers:
|
|
292
|
+
- name: api
|
|
293
|
+
image: node:18
|
|
294
|
+
ports:
|
|
295
|
+
- containerPort: 3000
|
|
296
|
+
---
|
|
297
|
+
apiVersion: v1
|
|
298
|
+
kind: Service
|
|
299
|
+
metadata:
|
|
300
|
+
name: api-service
|
|
301
|
+
spec:
|
|
302
|
+
selector:
|
|
303
|
+
app: api
|
|
304
|
+
ports:
|
|
305
|
+
- port: 3000
|
|
306
|
+
---
|
|
307
|
+
apiVersion: apps/v1
|
|
308
|
+
kind: StatefulSet
|
|
309
|
+
metadata:
|
|
310
|
+
name: postgres
|
|
311
|
+
spec:
|
|
312
|
+
serviceName: postgres
|
|
313
|
+
replicas: 1
|
|
314
|
+
selector:
|
|
315
|
+
matchLabels:
|
|
316
|
+
app: postgres
|
|
317
|
+
template:
|
|
318
|
+
spec:
|
|
319
|
+
containers:
|
|
320
|
+
- name: postgres
|
|
321
|
+
image: postgres:15
|
|
322
|
+
`;
|
|
323
|
+
|
|
324
|
+
const diagram = Diagram("Production Architecture");
|
|
325
|
+
await diagram.registerPlugins([kubernetesPlugin]);
|
|
326
|
+
await diagram.import(k8sYaml, "kubernetes");
|
|
327
|
+
|
|
328
|
+
const svg = await diagram.render();
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
### Import Multiple Manifest Files
|
|
332
|
+
|
|
333
|
+
```typescript
|
|
334
|
+
const stagingManifest = `
|
|
335
|
+
apiVersion: apps/v1
|
|
336
|
+
kind: Deployment
|
|
337
|
+
metadata:
|
|
338
|
+
name: web
|
|
339
|
+
namespace: staging
|
|
340
|
+
spec:
|
|
341
|
+
replicas: 1
|
|
342
|
+
template:
|
|
343
|
+
spec:
|
|
344
|
+
containers:
|
|
345
|
+
- name: web
|
|
346
|
+
image: myapp:staging
|
|
347
|
+
`;
|
|
348
|
+
|
|
349
|
+
const productionManifest = `
|
|
350
|
+
apiVersion: apps/v1
|
|
351
|
+
kind: Deployment
|
|
352
|
+
metadata:
|
|
353
|
+
name: web
|
|
354
|
+
namespace: production
|
|
355
|
+
spec:
|
|
356
|
+
replicas: 5
|
|
357
|
+
template:
|
|
358
|
+
spec:
|
|
359
|
+
containers:
|
|
360
|
+
- name: web
|
|
361
|
+
image: myapp:latest
|
|
362
|
+
`;
|
|
363
|
+
|
|
364
|
+
const diagram = Diagram("Environment Comparison");
|
|
365
|
+
await diagram.registerPlugins([kubernetesPlugin]);
|
|
366
|
+
|
|
367
|
+
// Each manifest gets its own cluster
|
|
368
|
+
await diagram.import([stagingManifest, productionManifest], "kubernetes");
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
### Export with Custom Metadata
|
|
372
|
+
|
|
373
|
+
```typescript
|
|
374
|
+
import { Diagram, Node } from "diagrams-js";
|
|
375
|
+
import { kubernetesPlugin } from "@diagrams-js/plugin-kubernetes";
|
|
376
|
+
|
|
377
|
+
const diagram = Diagram("Production Stack");
|
|
378
|
+
|
|
379
|
+
const deployment = diagram.add(Node("api"));
|
|
380
|
+
deployment.metadata = {
|
|
381
|
+
kubernetes: {
|
|
382
|
+
kind: "Deployment",
|
|
383
|
+
namespace: "production",
|
|
384
|
+
labels: {
|
|
385
|
+
app: "api",
|
|
386
|
+
tier: "backend",
|
|
387
|
+
env: "production",
|
|
388
|
+
},
|
|
389
|
+
spec: {
|
|
390
|
+
replicas: 5,
|
|
391
|
+
selector: { matchLabels: { app: "api" } },
|
|
392
|
+
template: {
|
|
393
|
+
spec: {
|
|
394
|
+
containers: [
|
|
395
|
+
{
|
|
396
|
+
name: "api",
|
|
397
|
+
image: "myapp:latest",
|
|
398
|
+
resources: {
|
|
399
|
+
limits: { cpu: "1000m", memory: "512Mi" },
|
|
400
|
+
requests: { cpu: "200m", memory: "256Mi" },
|
|
401
|
+
},
|
|
402
|
+
},
|
|
403
|
+
],
|
|
404
|
+
},
|
|
405
|
+
},
|
|
406
|
+
},
|
|
407
|
+
},
|
|
408
|
+
};
|
|
409
|
+
|
|
410
|
+
await diagram.registerPlugins([kubernetesPlugin]);
|
|
411
|
+
const k8sYaml = await diagram.export("kubernetes");
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
### Round-trip Conversion
|
|
415
|
+
|
|
416
|
+
```typescript
|
|
417
|
+
const diagram = Diagram("Modified Stack");
|
|
418
|
+
await diagram.registerPlugins([kubernetesPlugin]);
|
|
419
|
+
|
|
420
|
+
// Import existing manifest
|
|
421
|
+
await diagram.import(existingK8sYaml, "kubernetes");
|
|
422
|
+
|
|
423
|
+
// Add a new resource
|
|
424
|
+
const monitoring = diagram.add(Node("prometheus"));
|
|
425
|
+
monitoring.metadata = {
|
|
426
|
+
kubernetes: {
|
|
427
|
+
kind: "Deployment",
|
|
428
|
+
namespace: "monitoring",
|
|
429
|
+
spec: {
|
|
430
|
+
replicas: 1,
|
|
431
|
+
selector: { matchLabels: { app: "prometheus" } },
|
|
432
|
+
template: {
|
|
433
|
+
spec: {
|
|
434
|
+
containers: [
|
|
435
|
+
{
|
|
436
|
+
name: "prometheus",
|
|
437
|
+
image: "prom/prometheus:latest",
|
|
438
|
+
ports: [{ containerPort: 9090 }],
|
|
439
|
+
},
|
|
440
|
+
],
|
|
441
|
+
},
|
|
442
|
+
},
|
|
443
|
+
},
|
|
444
|
+
},
|
|
445
|
+
};
|
|
446
|
+
|
|
447
|
+
// Export modified configuration
|
|
448
|
+
const updatedYaml = await diagram.export("kubernetes");
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
## API Reference
|
|
452
|
+
|
|
453
|
+
### `kubernetesPlugin`
|
|
454
|
+
|
|
455
|
+
Pre-created Kubernetes plugin instance (no configuration needed).
|
|
456
|
+
|
|
457
|
+
```typescript
|
|
458
|
+
import { kubernetesPlugin } from "@diagrams-js/plugin-kubernetes";
|
|
459
|
+
|
|
460
|
+
// ✅ Use the pre-created instance
|
|
461
|
+
await diagram.registerPlugins([kubernetesPlugin]);
|
|
462
|
+
```
|
|
463
|
+
|
|
464
|
+
The plugin provides:
|
|
465
|
+
|
|
466
|
+
- **Importer**: `name: "kubernetes"`, supports `.yml` and `.yaml` files
|
|
467
|
+
- **Exporter**: `name: "kubernetes"`, exports to `.yaml` format
|
|
468
|
+
|
|
469
|
+
### `createKubernetesPlugin(config?)`
|
|
470
|
+
|
|
471
|
+
Factory function for creating a Kubernetes plugin with custom configuration.
|
|
472
|
+
|
|
473
|
+
```typescript
|
|
474
|
+
import { createKubernetesPlugin } from "@diagrams-js/plugin-kubernetes";
|
|
475
|
+
|
|
476
|
+
// ✅ Create plugin with custom configuration
|
|
477
|
+
const customPlugin = createKubernetesPlugin({
|
|
478
|
+
defaultNamespace: "production",
|
|
479
|
+
imageMappings: {
|
|
480
|
+
"custom-app": { iconify: "logos:kubernetes" },
|
|
481
|
+
},
|
|
482
|
+
});
|
|
483
|
+
|
|
484
|
+
await diagram.registerPlugins([customPlugin]);
|
|
485
|
+
```
|
|
486
|
+
|
|
487
|
+
**Parameters:**
|
|
488
|
+
|
|
489
|
+
- `config` (optional): `KubernetesPluginConfig`
|
|
490
|
+
- `defaultNamespace`: Default namespace for exports (default: "default")
|
|
491
|
+
- `imageMappings`: Custom resource to icon mappings
|
|
492
|
+
|
|
493
|
+
**Returns:** `DiagramsPlugin` - The plugin instance
|
|
494
|
+
|
|
495
|
+
### Exported Types
|
|
496
|
+
|
|
497
|
+
The plugin exports the `ImageMappings` type for TypeScript users:
|
|
498
|
+
|
|
499
|
+
```typescript
|
|
500
|
+
import { createKubernetesPlugin, type ImageMappings } from "@diagrams-js/plugin-kubernetes";
|
|
501
|
+
|
|
502
|
+
// Type your image mappings for better IDE support
|
|
503
|
+
const mappings: ImageMappings = {
|
|
504
|
+
"my-deployment": { provider: "k8s", type: "compute", resource: "Deploy" },
|
|
505
|
+
"my-app": { iconify: "logos:kubernetes" },
|
|
506
|
+
"custom-resource": "https://example.com/icon.svg",
|
|
507
|
+
};
|
|
508
|
+
|
|
509
|
+
const plugin = createKubernetesPlugin({ imageMappings: mappings });
|
|
510
|
+
```
|
|
511
|
+
|
|
512
|
+
## Runtime Support
|
|
513
|
+
|
|
514
|
+
- Node.js ✅
|
|
515
|
+
- Browser ✅
|
|
516
|
+
- Deno ✅
|
|
517
|
+
- Bun ✅
|
|
518
|
+
|
|
519
|
+
## Best Practices
|
|
520
|
+
|
|
521
|
+
### 1. Use Descriptive Resource Names
|
|
522
|
+
|
|
523
|
+
Resource names become node labels:
|
|
524
|
+
|
|
525
|
+
```yaml
|
|
526
|
+
# ✅ Good
|
|
527
|
+
apiVersion: apps/v1
|
|
528
|
+
kind: Deployment
|
|
529
|
+
metadata:
|
|
530
|
+
name: user-service
|
|
531
|
+
|
|
532
|
+
# ❌ Avoid
|
|
533
|
+
apiVersion: apps/v1
|
|
534
|
+
kind: Deployment
|
|
535
|
+
metadata:
|
|
536
|
+
name: svc1
|
|
537
|
+
```
|
|
538
|
+
|
|
539
|
+
### 2. Store Metadata for Round-trip
|
|
540
|
+
|
|
541
|
+
When creating nodes programmatically, store Kubernetes metadata:
|
|
542
|
+
|
|
543
|
+
```typescript
|
|
544
|
+
const node = diagram.add(Node("my-deployment"));
|
|
545
|
+
node.metadata = {
|
|
546
|
+
kubernetes: {
|
|
547
|
+
kind: "Deployment",
|
|
548
|
+
namespace: "default",
|
|
549
|
+
spec: {
|
|
550
|
+
replicas: 3,
|
|
551
|
+
selector: { matchLabels: { app: "my-app" } },
|
|
552
|
+
},
|
|
553
|
+
},
|
|
554
|
+
};
|
|
555
|
+
```
|
|
556
|
+
|
|
557
|
+
### 3. Handle Service Selectors
|
|
558
|
+
|
|
559
|
+
The plugin automatically creates edges when Service selectors match Deployment labels:
|
|
560
|
+
|
|
561
|
+
```yaml
|
|
562
|
+
# Deployment labels
|
|
563
|
+
apiVersion: apps/v1
|
|
564
|
+
kind: Deployment
|
|
565
|
+
metadata:
|
|
566
|
+
name: web
|
|
567
|
+
labels:
|
|
568
|
+
app: web
|
|
569
|
+
|
|
570
|
+
# Service selector matches
|
|
571
|
+
apiVersion: v1
|
|
572
|
+
kind: Service
|
|
573
|
+
metadata:
|
|
574
|
+
name: web-service
|
|
575
|
+
spec:
|
|
576
|
+
selector:
|
|
577
|
+
app: web # Creates edge from service to deployment
|
|
578
|
+
```
|
|
579
|
+
|
|
580
|
+
### 4. Use Namespaces
|
|
581
|
+
|
|
582
|
+
Organize resources with namespaces for better visualization:
|
|
583
|
+
|
|
584
|
+
```yaml
|
|
585
|
+
apiVersion: apps/v1
|
|
586
|
+
kind: Deployment
|
|
587
|
+
metadata:
|
|
588
|
+
name: api
|
|
589
|
+
namespace: production
|
|
590
|
+
|
|
591
|
+
apiVersion: apps/v1
|
|
592
|
+
kind: Deployment
|
|
593
|
+
metadata:
|
|
594
|
+
name: api
|
|
595
|
+
namespace: staging
|
|
596
|
+
```
|
|
597
|
+
|
|
598
|
+
### 5. Multi-document YAML
|
|
599
|
+
|
|
600
|
+
Use `---` separator for multiple resources:
|
|
601
|
+
|
|
602
|
+
```yaml
|
|
603
|
+
apiVersion: apps/v1
|
|
604
|
+
kind: Deployment
|
|
605
|
+
metadata:
|
|
606
|
+
name: web
|
|
607
|
+
---
|
|
608
|
+
apiVersion: v1
|
|
609
|
+
kind: Service
|
|
610
|
+
metadata:
|
|
611
|
+
name: web-service
|
|
612
|
+
```
|
|
613
|
+
|
|
614
|
+
## Troubleshooting
|
|
615
|
+
|
|
616
|
+
### Plugin Not Found
|
|
617
|
+
|
|
618
|
+
```typescript
|
|
619
|
+
// Make sure to register the plugin before using import/export
|
|
620
|
+
import { kubernetesPlugin } from "@diagrams-js/plugin-kubernetes";
|
|
621
|
+
|
|
622
|
+
await diagram.registerPlugins([kubernetesPlugin]);
|
|
623
|
+
```
|
|
624
|
+
|
|
625
|
+
### Type Errors
|
|
626
|
+
|
|
627
|
+
The metadata property is typed as `Record<string, any>`:
|
|
628
|
+
|
|
629
|
+
```typescript
|
|
630
|
+
node.metadata = {
|
|
631
|
+
kubernetes: { ... }
|
|
632
|
+
};
|
|
633
|
+
```
|
|
634
|
+
|
|
635
|
+
### Missing Icons
|
|
636
|
+
|
|
637
|
+
For custom resources or specific icons:
|
|
638
|
+
|
|
639
|
+
```typescript
|
|
640
|
+
const plugin = createKubernetesPlugin({
|
|
641
|
+
imageMappings: {
|
|
642
|
+
// Option 1: Use a provider icon
|
|
643
|
+
"my-deployment": { provider: "k8s", type: "compute", resource: "Deploy" },
|
|
644
|
+
|
|
645
|
+
// Option 2: Use a custom image URL
|
|
646
|
+
"my-app": "https://example.com/icon.svg",
|
|
647
|
+
|
|
648
|
+
// Option 3: Use Iconify
|
|
649
|
+
"custom-app": { iconify: "logos:kubernetes" },
|
|
650
|
+
},
|
|
651
|
+
});
|
|
652
|
+
```
|
|
653
|
+
|
|
654
|
+
### Import Fails
|
|
655
|
+
|
|
656
|
+
Ensure your Kubernetes YAML is valid:
|
|
657
|
+
|
|
658
|
+
```typescript
|
|
659
|
+
try {
|
|
660
|
+
await diagram.import(k8sYaml, "kubernetes");
|
|
661
|
+
} catch (error) {
|
|
662
|
+
console.error("Import failed:", error.message);
|
|
663
|
+
}
|
|
664
|
+
```
|
|
665
|
+
|
|
666
|
+
Required fields: `apiVersion`, `kind`, `metadata.name`
|
|
667
|
+
|
|
668
|
+
## Further Reading
|
|
669
|
+
|
|
670
|
+
- diagrams-js Plugin System: See plugin system documentation
|
|
671
|
+
- diagrams-js Documentation: https://diagrams-js.hatemhosny.dev
|
|
672
|
+
- Kubernetes Documentation: https://kubernetes.io/docs/
|
|
673
|
+
- Iconify Icons: https://iconify.design/
|
package/dist/chunk-WfQuXRBF.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var e=Object.defineProperty,t=(t,n)=>{let r={};for(var i in t)e(r,i,{get:t[i],enumerable:!0});return n||e(r,Symbol.toStringTag,{value:`Module`}),r};export{t};
|