mirror of
https://github.com/komodorio/helm-dashboard.git
synced 2026-03-24 11:48:04 +00:00
feat: add Relations tab with force-directed resource dependency graph (#96)
Add a new "Relations" tab after "Images" that visualizes resource dependencies within a Helm release as an interactive force-directed graph. Detects relationships via ownerReferences, *Ref fields, volumes, env refs, service selectors, ingress backends, and RBAC bindings. External resources appear as dashed oval ghost nodes. Color-coded by resource category. Closes #96 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
268
frontend/package-lock.json
generated
268
frontend/package-lock.json
generated
@@ -9,8 +9,12 @@
|
|||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@dagrejs/dagre": "^2.0.4",
|
||||||
"@tanstack/react-query": "^5.90.21",
|
"@tanstack/react-query": "^5.90.21",
|
||||||
|
"@types/d3-force": "^3.0.10",
|
||||||
|
"@xyflow/react": "^12.10.1",
|
||||||
"compare-versions": "^6.1.1",
|
"compare-versions": "^6.1.1",
|
||||||
|
"d3-force": "^3.0.0",
|
||||||
"diff2html": "^3.4.52",
|
"diff2html": "^3.4.52",
|
||||||
"flowbite-react": "^0.12.17",
|
"flowbite-react": "^0.12.17",
|
||||||
"highlight.js": "^11.11.1",
|
"highlight.js": "^11.11.1",
|
||||||
@@ -463,6 +467,21 @@
|
|||||||
"ms": "^2.1.1"
|
"ms": "^2.1.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@dagrejs/dagre": {
|
||||||
|
"version": "2.0.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/@dagrejs/dagre/-/dagre-2.0.4.tgz",
|
||||||
|
"integrity": "sha512-J6vCWTNpicHF4zFlZG1cS5DkGzMr9941gddYkakjrg3ZNev4bbqEgLHFTWiFrcJm7UCRu7olO3K6IRDd9gSGhA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@dagrejs/graphlib": "3.0.4"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@dagrejs/graphlib": {
|
||||||
|
"version": "3.0.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/@dagrejs/graphlib/-/graphlib-3.0.4.tgz",
|
||||||
|
"integrity": "sha512-HxZ7fCvAwTLCWCO0WjDkzAFQze8LdC6iOpKbetDKHIuDfIgMlIzYzqZ4nxwLlclQX+3ZVeZ1K2OuaOE2WWcyOg==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
"node_modules/@emnapi/core": {
|
"node_modules/@emnapi/core": {
|
||||||
"version": "1.8.1",
|
"version": "1.8.1",
|
||||||
"resolved": "https://registry.npmjs.org/@emnapi/core/-/core-1.8.1.tgz",
|
"resolved": "https://registry.npmjs.org/@emnapi/core/-/core-1.8.1.tgz",
|
||||||
@@ -3401,6 +3420,61 @@
|
|||||||
"assertion-error": "^2.0.1"
|
"assertion-error": "^2.0.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@types/d3-color": {
|
||||||
|
"version": "3.1.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/d3-color/-/d3-color-3.1.3.tgz",
|
||||||
|
"integrity": "sha512-iO90scth9WAbmgv7ogoq57O9YpKmFBbmoEoCHDB2xMBY0+/KVrqAaCDyCE16dUspeOvIxFFRI+0sEtqDqy2b4A==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/@types/d3-drag": {
|
||||||
|
"version": "3.0.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/d3-drag/-/d3-drag-3.0.7.tgz",
|
||||||
|
"integrity": "sha512-HE3jVKlzU9AaMazNufooRJ5ZpWmLIoc90A37WU2JMmeq28w1FQqCZswHZ3xR+SuxYftzHq6WU6KJHvqxKzTxxQ==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@types/d3-selection": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@types/d3-force": {
|
||||||
|
"version": "3.0.10",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/d3-force/-/d3-force-3.0.10.tgz",
|
||||||
|
"integrity": "sha512-ZYeSaCF3p73RdOKcjj+swRlZfnYpK1EbaDiYICEEp5Q6sUiqFaFQ9qgoshp5CzIyyb/yD09kD9o2zEltCexlgw==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/@types/d3-interpolate": {
|
||||||
|
"version": "3.0.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/d3-interpolate/-/d3-interpolate-3.0.4.tgz",
|
||||||
|
"integrity": "sha512-mgLPETlrpVV1YRJIglr4Ez47g7Yxjl1lj7YKsiMCb27VJH9W8NVM6Bb9d8kkpG/uAQS5AmbA48q2IAolKKo1MA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@types/d3-color": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@types/d3-selection": {
|
||||||
|
"version": "3.0.11",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/d3-selection/-/d3-selection-3.0.11.tgz",
|
||||||
|
"integrity": "sha512-bhAXu23DJWsrI45xafYpkQ4NtcKMwWnAC/vKrd2l+nxMFuvOT3XMYTIj2opv8vq8AO5Yh7Qac/nSeP/3zjTK0w==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/@types/d3-transition": {
|
||||||
|
"version": "3.0.9",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/d3-transition/-/d3-transition-3.0.9.tgz",
|
||||||
|
"integrity": "sha512-uZS5shfxzO3rGlu0cC3bjmMFKsXv+SmZZcgp0KD22ts4uGXp5EVYGzu/0YdwZeKmddhcAccYtREJKkPfXkZuCg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@types/d3-selection": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@types/d3-zoom": {
|
||||||
|
"version": "3.0.8",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/d3-zoom/-/d3-zoom-3.0.8.tgz",
|
||||||
|
"integrity": "sha512-iqMC4/YlFCSlO8+2Ii1GGGliCAY4XdeG748w5vQUbevlbDu0zSjH/+jojorQVBK/se0j6DUFNPBGSqD3YWYnDw==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@types/d3-interpolate": "*",
|
||||||
|
"@types/d3-selection": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@types/deep-eql": {
|
"node_modules/@types/deep-eql": {
|
||||||
"version": "4.0.2",
|
"version": "4.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/@types/deep-eql/-/deep-eql-4.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/@types/deep-eql/-/deep-eql-4.0.2.tgz",
|
||||||
@@ -4185,6 +4259,38 @@
|
|||||||
"url": "https://opencollective.com/vitest"
|
"url": "https://opencollective.com/vitest"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@xyflow/react": {
|
||||||
|
"version": "12.10.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@xyflow/react/-/react-12.10.1.tgz",
|
||||||
|
"integrity": "sha512-5eSWtIK/+rkldOuFbOOz44CRgQRjtS9v5nufk77DV+XBnfCGL9HAQ8PG00o2ZYKqkEU/Ak6wrKC95Tu+2zuK3Q==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@xyflow/system": "0.0.75",
|
||||||
|
"classcat": "^5.0.3",
|
||||||
|
"zustand": "^4.4.0"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"react": ">=17",
|
||||||
|
"react-dom": ">=17"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@xyflow/system": {
|
||||||
|
"version": "0.0.75",
|
||||||
|
"resolved": "https://registry.npmjs.org/@xyflow/system/-/system-0.0.75.tgz",
|
||||||
|
"integrity": "sha512-iXs+AGFLi8w/VlAoc/iSxk+CxfT6o64Uw/k0CKASOPqjqz6E0rb5jFZgJtXGZCpfQI6OQpu5EnumP5fGxQheaQ==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@types/d3-drag": "^3.0.7",
|
||||||
|
"@types/d3-interpolate": "^3.0.4",
|
||||||
|
"@types/d3-selection": "^3.0.10",
|
||||||
|
"@types/d3-transition": "^3.0.8",
|
||||||
|
"@types/d3-zoom": "^3.0.8",
|
||||||
|
"d3-drag": "^3.0.0",
|
||||||
|
"d3-interpolate": "^3.0.1",
|
||||||
|
"d3-selection": "^3.0.0",
|
||||||
|
"d3-zoom": "^3.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/abbrev": {
|
"node_modules/abbrev": {
|
||||||
"version": "1.1.1",
|
"version": "1.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
|
||||||
@@ -5124,6 +5230,12 @@
|
|||||||
"node": ">=8"
|
"node": ">=8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/classcat": {
|
||||||
|
"version": "5.0.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/classcat/-/classcat-5.0.5.tgz",
|
||||||
|
"integrity": "sha512-JhZUT7JFcQy/EzW605k/ktHtncoo9vnyW/2GspNYwFlN1C/WmjuV/xtS04e9SOkL2sTdw0VAZ2UGCcQ9lR6p6w==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
"node_modules/classnames": {
|
"node_modules/classnames": {
|
||||||
"version": "2.5.1",
|
"version": "2.5.1",
|
||||||
"resolved": "https://registry.npmjs.org/classnames/-/classnames-2.5.1.tgz",
|
"resolved": "https://registry.npmjs.org/classnames/-/classnames-2.5.1.tgz",
|
||||||
@@ -5552,6 +5664,134 @@
|
|||||||
"node": "^20.1.0 || ^22.0.0 || >=24.0.0"
|
"node": "^20.1.0 || ^22.0.0 || >=24.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/d3-color": {
|
||||||
|
"version": "3.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/d3-color/-/d3-color-3.1.0.tgz",
|
||||||
|
"integrity": "sha512-zg/chbXyeBtMQ1LbD/WSoW2DpC3I0mpmPdW+ynRTj/x2DAWYrIY7qeZIHidozwV24m4iavr15lNwIwLxRmOxhA==",
|
||||||
|
"license": "ISC",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/d3-dispatch": {
|
||||||
|
"version": "3.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/d3-dispatch/-/d3-dispatch-3.0.1.tgz",
|
||||||
|
"integrity": "sha512-rzUyPU/S7rwUflMyLc1ETDeBj0NRuHKKAcvukozwhshr6g6c5d8zh4c2gQjY2bZ0dXeGLWc1PF174P2tVvKhfg==",
|
||||||
|
"license": "ISC",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/d3-drag": {
|
||||||
|
"version": "3.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/d3-drag/-/d3-drag-3.0.0.tgz",
|
||||||
|
"integrity": "sha512-pWbUJLdETVA8lQNJecMxoXfH6x+mO2UQo8rSmZ+QqxcbyA3hfeprFgIT//HW2nlHChWeIIMwS2Fq+gEARkhTkg==",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"d3-dispatch": "1 - 3",
|
||||||
|
"d3-selection": "3"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/d3-ease": {
|
||||||
|
"version": "3.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/d3-ease/-/d3-ease-3.0.1.tgz",
|
||||||
|
"integrity": "sha512-wR/XK3D3XcLIZwpbvQwQ5fK+8Ykds1ip7A2Txe0yxncXSdq1L9skcG7blcedkOX+ZcgxGAmLX1FrRGbADwzi0w==",
|
||||||
|
"license": "BSD-3-Clause",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/d3-force": {
|
||||||
|
"version": "3.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/d3-force/-/d3-force-3.0.0.tgz",
|
||||||
|
"integrity": "sha512-zxV/SsA+U4yte8051P4ECydjD/S+qeYtnaIyAs9tgHCqfguma/aAQDjo85A9Z6EKhBirHRJHXIgJUlffT4wdLg==",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"d3-dispatch": "1 - 3",
|
||||||
|
"d3-quadtree": "1 - 3",
|
||||||
|
"d3-timer": "1 - 3"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/d3-interpolate": {
|
||||||
|
"version": "3.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/d3-interpolate/-/d3-interpolate-3.0.1.tgz",
|
||||||
|
"integrity": "sha512-3bYs1rOD33uo8aqJfKP3JWPAibgw8Zm2+L9vBKEHJ2Rg+viTR7o5Mmv5mZcieN+FRYaAOWX5SJATX6k1PWz72g==",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"d3-color": "1 - 3"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/d3-quadtree": {
|
||||||
|
"version": "3.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/d3-quadtree/-/d3-quadtree-3.0.1.tgz",
|
||||||
|
"integrity": "sha512-04xDrxQTDTCFwP5H6hRhsRcb9xxv2RzkcsygFzmkSIOJy3PeRJP7sNk3VRIbKXcog561P9oU0/rVH6vDROAgUw==",
|
||||||
|
"license": "ISC",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/d3-selection": {
|
||||||
|
"version": "3.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/d3-selection/-/d3-selection-3.0.0.tgz",
|
||||||
|
"integrity": "sha512-fmTRWbNMmsmWq6xJV8D19U/gw/bwrHfNXxrIN+HfZgnzqTHp9jOmKMhsTUjXOJnZOdZY9Q28y4yebKzqDKlxlQ==",
|
||||||
|
"license": "ISC",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/d3-timer": {
|
||||||
|
"version": "3.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/d3-timer/-/d3-timer-3.0.1.tgz",
|
||||||
|
"integrity": "sha512-ndfJ/JxxMd3nw31uyKoY2naivF+r29V+Lc0svZxe1JvvIRmi8hUsrMvdOwgS1o6uBHmiz91geQ0ylPP0aj1VUA==",
|
||||||
|
"license": "ISC",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/d3-transition": {
|
||||||
|
"version": "3.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/d3-transition/-/d3-transition-3.0.1.tgz",
|
||||||
|
"integrity": "sha512-ApKvfjsSR6tg06xrL434C0WydLr7JewBB3V+/39RMHsaXTOG0zmt/OAXeng5M5LBm0ojmxJrpomQVZ1aPvBL4w==",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"d3-color": "1 - 3",
|
||||||
|
"d3-dispatch": "1 - 3",
|
||||||
|
"d3-ease": "1 - 3",
|
||||||
|
"d3-interpolate": "1 - 3",
|
||||||
|
"d3-timer": "1 - 3"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"d3-selection": "2 - 3"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/d3-zoom": {
|
||||||
|
"version": "3.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/d3-zoom/-/d3-zoom-3.0.0.tgz",
|
||||||
|
"integrity": "sha512-b8AmV3kfQaqWAuacbPuNbL6vahnOJflOhexLzMMNLga62+/nh0JzvJ0aO/5a5MVgUFGS7Hu1P9P03o3fJkDCyw==",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"d3-dispatch": "1 - 3",
|
||||||
|
"d3-drag": "2 - 3",
|
||||||
|
"d3-interpolate": "1 - 3",
|
||||||
|
"d3-selection": "2 - 3",
|
||||||
|
"d3-transition": "2 - 3"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/dashdash": {
|
"node_modules/dashdash": {
|
||||||
"version": "1.14.1",
|
"version": "1.14.1",
|
||||||
"resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz",
|
"resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz",
|
||||||
@@ -13449,6 +13689,34 @@
|
|||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"zod": "^3.25.0 || ^4.0.0"
|
"zod": "^3.25.0 || ^4.0.0"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"node_modules/zustand": {
|
||||||
|
"version": "4.5.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/zustand/-/zustand-4.5.7.tgz",
|
||||||
|
"integrity": "sha512-CHOUy7mu3lbD6o6LJLfllpjkzhHXSBlX8B9+qPddUsIfeF5S/UZ5q0kmCsnRqT1UHFQZchNFDDzMbQsuesHWlw==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"use-sync-external-store": "^1.2.2"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12.7.0"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"@types/react": ">=16.8",
|
||||||
|
"immer": ">=9.0.6",
|
||||||
|
"react": ">=16.8"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"@types/react": {
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"immer": {
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"react": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,8 +24,12 @@
|
|||||||
"cypress:component:open": "cypress open --component"
|
"cypress:component:open": "cypress open --component"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@dagrejs/dagre": "^2.0.4",
|
||||||
"@tanstack/react-query": "^5.90.21",
|
"@tanstack/react-query": "^5.90.21",
|
||||||
|
"@types/d3-force": "^3.0.10",
|
||||||
|
"@xyflow/react": "^12.10.1",
|
||||||
"compare-versions": "^6.1.1",
|
"compare-versions": "^6.1.1",
|
||||||
|
"d3-force": "^3.0.0",
|
||||||
"diff2html": "^3.4.52",
|
"diff2html": "^3.4.52",
|
||||||
"flowbite-react": "^0.12.17",
|
"flowbite-react": "^0.12.17",
|
||||||
"highlight.js": "^11.11.1",
|
"highlight.js": "^11.11.1",
|
||||||
|
|||||||
@@ -96,6 +96,35 @@ export function useGetImages(ns: string, name: string) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface RelationNode {
|
||||||
|
id: string;
|
||||||
|
kind: string;
|
||||||
|
name: string;
|
||||||
|
inRelease: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface RelationEdge {
|
||||||
|
source: string;
|
||||||
|
target: string;
|
||||||
|
type: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface RelationGraph {
|
||||||
|
nodes: RelationNode[];
|
||||||
|
edges: RelationEdge[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useGetRelations(ns: string, name: string) {
|
||||||
|
return useQuery<RelationGraph>({
|
||||||
|
queryKey: ["relations", ns, name],
|
||||||
|
queryFn: () =>
|
||||||
|
apiService.fetchWithSafeDefaults<RelationGraph>({
|
||||||
|
url: `/api/helm/releases/${ns}/${name}/relations`,
|
||||||
|
fallback: { nodes: [], edges: [] },
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// List of installed k8s resources for this release
|
// List of installed k8s resources for this release
|
||||||
export function useGetResources(ns: string, name: string, enabled?: boolean) {
|
export function useGetResources(ns: string, name: string, enabled?: boolean) {
|
||||||
return useQuery<StructuredResources[]>({
|
return useQuery<StructuredResources[]>({
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import Spinner from "../Spinner";
|
|||||||
import Tabs from "../Tabs";
|
import Tabs from "../Tabs";
|
||||||
import RevisionDiff from "./RevisionDiff";
|
import RevisionDiff from "./RevisionDiff";
|
||||||
import RevisionImages from "./RevisionImages";
|
import RevisionImages from "./RevisionImages";
|
||||||
|
import RevisionRelations from "./RevisionRelations";
|
||||||
import RevisionResource from "./RevisionResource";
|
import RevisionResource from "./RevisionResource";
|
||||||
|
|
||||||
type RevisionTagProps = {
|
type RevisionTagProps = {
|
||||||
@@ -84,6 +85,11 @@ const RevisionDetails = ({
|
|||||||
label: "Images",
|
label: "Images",
|
||||||
content: <RevisionImages />,
|
content: <RevisionImages />,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
value: "relations",
|
||||||
|
label: "Relations",
|
||||||
|
content: <RevisionRelations />,
|
||||||
|
},
|
||||||
];
|
];
|
||||||
const { context, namespace, chart } = useParams();
|
const { context, namespace, chart } = useParams();
|
||||||
const tab = searchParams.get("tab");
|
const tab = searchParams.get("tab");
|
||||||
|
|||||||
270
frontend/src/components/revision/RevisionRelations.tsx
Normal file
270
frontend/src/components/revision/RevisionRelations.tsx
Normal file
@@ -0,0 +1,270 @@
|
|||||||
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||||
|
import { useParams } from "react-router";
|
||||||
|
import {
|
||||||
|
ReactFlow,
|
||||||
|
type Node,
|
||||||
|
type Edge,
|
||||||
|
type OnNodesChange,
|
||||||
|
Background,
|
||||||
|
Controls,
|
||||||
|
MiniMap,
|
||||||
|
MarkerType,
|
||||||
|
applyNodeChanges,
|
||||||
|
} from "@xyflow/react";
|
||||||
|
import {
|
||||||
|
forceSimulation,
|
||||||
|
forceLink,
|
||||||
|
forceManyBody,
|
||||||
|
forceCenter,
|
||||||
|
forceCollide,
|
||||||
|
type SimulationNodeDatum,
|
||||||
|
type SimulationLinkDatum,
|
||||||
|
} from "d3-force";
|
||||||
|
import "@xyflow/react/dist/style.css";
|
||||||
|
|
||||||
|
import { useGetRelations } from "../../API/releases";
|
||||||
|
import Spinner from "../Spinner";
|
||||||
|
|
||||||
|
const NODE_WIDTH = 180;
|
||||||
|
const NODE_HEIGHT = 50;
|
||||||
|
|
||||||
|
const KIND_COLORS: Record<string, { bg: string; border: string }> = {
|
||||||
|
Deployment: { bg: "#dbeafe", border: "#2563eb" },
|
||||||
|
StatefulSet: { bg: "#dbeafe", border: "#2563eb" },
|
||||||
|
DaemonSet: { bg: "#dbeafe", border: "#2563eb" },
|
||||||
|
ReplicaSet: { bg: "#dbeafe", border: "#2563eb" },
|
||||||
|
Job: { bg: "#dbeafe", border: "#2563eb" },
|
||||||
|
CronJob: { bg: "#dbeafe", border: "#2563eb" },
|
||||||
|
Pod: { bg: "#dbeafe", border: "#2563eb" },
|
||||||
|
Service: { bg: "#ede9fe", border: "#7c3aed" },
|
||||||
|
Ingress: { bg: "#ede9fe", border: "#7c3aed" },
|
||||||
|
NetworkPolicy: { bg: "#ede9fe", border: "#7c3aed" },
|
||||||
|
ConfigMap: { bg: "#fef3c7", border: "#d97706" },
|
||||||
|
Secret: { bg: "#fef3c7", border: "#d97706" },
|
||||||
|
ServiceAccount: { bg: "#d1fae5", border: "#059669" },
|
||||||
|
Role: { bg: "#d1fae5", border: "#059669" },
|
||||||
|
ClusterRole: { bg: "#d1fae5", border: "#059669" },
|
||||||
|
RoleBinding: { bg: "#d1fae5", border: "#059669" },
|
||||||
|
ClusterRoleBinding: { bg: "#d1fae5", border: "#059669" },
|
||||||
|
PersistentVolumeClaim: { bg: "#fce7f3", border: "#db2777" },
|
||||||
|
PersistentVolume: { bg: "#fce7f3", border: "#db2777" },
|
||||||
|
StorageClass: { bg: "#fce7f3", border: "#db2777" },
|
||||||
|
};
|
||||||
|
|
||||||
|
const DEFAULT_COLOR = { bg: "#eff6ff", border: "#1347ff" };
|
||||||
|
const GHOST_COLOR = { bg: "#f3f4f6", border: "#9ca3af" };
|
||||||
|
|
||||||
|
interface SimNode extends SimulationNodeDatum {
|
||||||
|
id: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ForceLayoutResult {
|
||||||
|
nodes: Node[];
|
||||||
|
pinNode: (id: string, x: number, y: number) => void;
|
||||||
|
unpinNode: (id: string) => void;
|
||||||
|
setNodes: React.Dispatch<React.SetStateAction<Node[]>>;
|
||||||
|
}
|
||||||
|
|
||||||
|
function useForceLayout(
|
||||||
|
sourceNodes: Node[],
|
||||||
|
sourceEdges: Edge[]
|
||||||
|
): ForceLayoutResult {
|
||||||
|
const [nodes, setNodes] = useState<Node[]>([]);
|
||||||
|
const simRef = useRef<ReturnType<typeof forceSimulation<SimNode>> | null>(
|
||||||
|
null
|
||||||
|
);
|
||||||
|
const sourceNodesRef = useRef(sourceNodes);
|
||||||
|
useEffect(() => {
|
||||||
|
sourceNodesRef.current = sourceNodes;
|
||||||
|
}, [sourceNodes]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!sourceNodes.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const radius = Math.max(300, sourceNodes.length * 30);
|
||||||
|
const simNodes: SimNode[] = sourceNodes.map((n, i) => {
|
||||||
|
const angle = (2 * Math.PI * i) / sourceNodes.length - Math.PI / 2;
|
||||||
|
return {
|
||||||
|
id: n.id,
|
||||||
|
x: radius * Math.cos(angle),
|
||||||
|
y: radius * Math.sin(angle),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const nodeById = new Map(simNodes.map((n) => [n.id, n]));
|
||||||
|
|
||||||
|
const simLinks: SimulationLinkDatum<SimNode>[] = sourceEdges
|
||||||
|
.filter((e) => nodeById.has(e.source) && nodeById.has(e.target))
|
||||||
|
.map((e) => ({
|
||||||
|
source: nodeById.get(e.source) as SimNode,
|
||||||
|
target: nodeById.get(e.target) as SimNode,
|
||||||
|
}));
|
||||||
|
|
||||||
|
simRef.current?.stop();
|
||||||
|
|
||||||
|
const sim = forceSimulation<SimNode>(simNodes)
|
||||||
|
.force(
|
||||||
|
"link",
|
||||||
|
forceLink<SimNode, SimulationLinkDatum<SimNode>>(simLinks)
|
||||||
|
.id((d: SimNode) => d.id)
|
||||||
|
.distance(200)
|
||||||
|
)
|
||||||
|
.force("charge", forceManyBody().strength(-800))
|
||||||
|
.force("center", forceCenter(0, 0))
|
||||||
|
.force("collide", forceCollide(NODE_WIDTH * 0.7))
|
||||||
|
.alphaDecay(0.02)
|
||||||
|
.on("tick", () => {
|
||||||
|
const current = sourceNodesRef.current;
|
||||||
|
setNodes(
|
||||||
|
current.map((n, i) => ({
|
||||||
|
...n,
|
||||||
|
position: {
|
||||||
|
x: (simNodes[i].x ?? 0) - NODE_WIDTH / 2,
|
||||||
|
y: (simNodes[i].y ?? 0) - NODE_HEIGHT / 2,
|
||||||
|
},
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
simRef.current = sim;
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
sim.stop();
|
||||||
|
};
|
||||||
|
}, [sourceNodes, sourceEdges]);
|
||||||
|
|
||||||
|
const pinNode = useCallback((nodeId: string, x: number, y: number) => {
|
||||||
|
const sim = simRef.current;
|
||||||
|
if (!sim) return;
|
||||||
|
const simNode = sim.nodes().find((n: SimNode) => n.id === nodeId);
|
||||||
|
if (simNode) {
|
||||||
|
simNode.fx = x + NODE_WIDTH / 2;
|
||||||
|
simNode.fy = y + NODE_HEIGHT / 2;
|
||||||
|
sim.alpha(0.3).restart();
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const unpinNode = useCallback((nodeId: string) => {
|
||||||
|
const sim = simRef.current;
|
||||||
|
if (!sim) return;
|
||||||
|
const simNode = sim.nodes().find((n: SimNode) => n.id === nodeId);
|
||||||
|
if (simNode) {
|
||||||
|
simNode.fx = null;
|
||||||
|
simNode.fy = null;
|
||||||
|
sim.alpha(0.3).restart();
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return { nodes, setNodes, pinNode, unpinNode };
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function RevisionRelations() {
|
||||||
|
const { namespace = "", chart = "" } = useParams();
|
||||||
|
const { data, isLoading } = useGetRelations(namespace, chart);
|
||||||
|
|
||||||
|
const { rfNodes, rfEdges } = useMemo(() => {
|
||||||
|
if (!data?.nodes?.length) {
|
||||||
|
return { rfNodes: [] as Node[], rfEdges: [] as Edge[] };
|
||||||
|
}
|
||||||
|
|
||||||
|
const builtNodes: Node[] = data.nodes.map((n) => {
|
||||||
|
const color = n.inRelease
|
||||||
|
? (KIND_COLORS[n.kind] ?? DEFAULT_COLOR)
|
||||||
|
: GHOST_COLOR;
|
||||||
|
return {
|
||||||
|
id: n.id,
|
||||||
|
data: { label: `${n.kind}\n${n.name}` },
|
||||||
|
position: { x: 0, y: 0 },
|
||||||
|
draggable: true,
|
||||||
|
style: {
|
||||||
|
background: color.bg,
|
||||||
|
border: `2px ${n.inRelease ? "solid" : "dashed"} ${color.border}`,
|
||||||
|
borderRadius: n.inRelease ? "6px" : "50%",
|
||||||
|
padding: n.inRelease ? "8px 12px" : "12px 20px",
|
||||||
|
fontSize: "12px",
|
||||||
|
fontWeight: 500,
|
||||||
|
whiteSpace: "pre-line" as const,
|
||||||
|
width: NODE_WIDTH,
|
||||||
|
textAlign: "center" as const,
|
||||||
|
...(n.inRelease ? {} : { color: "#6b7280" }),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const builtEdges: Edge[] = data.edges.map((e, i) => ({
|
||||||
|
id: `e-${i}`,
|
||||||
|
source: e.source,
|
||||||
|
target: e.target,
|
||||||
|
label: e.type,
|
||||||
|
type: "default",
|
||||||
|
style: { stroke: "#9ca3af" },
|
||||||
|
labelStyle: { fontSize: 10, fill: "#6b7280" },
|
||||||
|
markerEnd: { type: MarkerType.ArrowClosed, width: 12, height: 12 },
|
||||||
|
}));
|
||||||
|
|
||||||
|
return { rfNodes: builtNodes, rfEdges: builtEdges };
|
||||||
|
}, [data]);
|
||||||
|
|
||||||
|
const { nodes, setNodes, pinNode, unpinNode } = useForceLayout(
|
||||||
|
rfNodes,
|
||||||
|
rfEdges
|
||||||
|
);
|
||||||
|
|
||||||
|
const onNodesChange: OnNodesChange = useCallback(
|
||||||
|
(changes) => setNodes((nds) => applyNodeChanges(changes, nds)),
|
||||||
|
[setNodes]
|
||||||
|
);
|
||||||
|
|
||||||
|
const onNodeDrag = useCallback(
|
||||||
|
(_event: React.MouseEvent, node: Node) => {
|
||||||
|
pinNode(node.id, node.position.x, node.position.y);
|
||||||
|
},
|
||||||
|
[pinNode]
|
||||||
|
);
|
||||||
|
|
||||||
|
const onNodeDragStop = useCallback(
|
||||||
|
(_event: React.MouseEvent, node: Node) => {
|
||||||
|
unpinNode(node.id);
|
||||||
|
},
|
||||||
|
[unpinNode]
|
||||||
|
);
|
||||||
|
|
||||||
|
if (isLoading) return <Spinner />;
|
||||||
|
|
||||||
|
if (!nodes.length) {
|
||||||
|
return (
|
||||||
|
<div className="mt-3 rounded-sm bg-white p-4 text-sm shadow-sm">
|
||||||
|
No resource relations found in this release.
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="mt-3 h-[600px] rounded-sm bg-white shadow-sm">
|
||||||
|
<ReactFlow
|
||||||
|
nodes={nodes}
|
||||||
|
edges={rfEdges}
|
||||||
|
onNodesChange={onNodesChange}
|
||||||
|
onNodeDrag={onNodeDrag}
|
||||||
|
onNodeDragStop={onNodeDragStop}
|
||||||
|
fitView
|
||||||
|
minZoom={0.2}
|
||||||
|
maxZoom={2}
|
||||||
|
proOptions={{ hideAttribution: true }}
|
||||||
|
>
|
||||||
|
<Background />
|
||||||
|
<Controls />
|
||||||
|
<MiniMap
|
||||||
|
nodeStrokeWidth={2}
|
||||||
|
nodeColor={(n: Node) => {
|
||||||
|
const found = nodes.find((nd) => nd.id === n.id);
|
||||||
|
const borderStr = String(found?.style?.border ?? "");
|
||||||
|
return borderStr.includes("dashed") ? "#e5e7eb" : "#dbeafe";
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</ReactFlow>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
6507
frontend/yarn.lock
Normal file
6507
frontend/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
@@ -163,6 +163,7 @@ func configureHelms(api *gin.RouterGroup, data *objects.DataLayer) {
|
|||||||
rels.GET(":ns/:name/:section", h.GetInfoSection)
|
rels.GET(":ns/:name/:section", h.GetInfoSection)
|
||||||
rels.GET(":ns/:name/resources", h.Resources)
|
rels.GET(":ns/:name/resources", h.Resources)
|
||||||
rels.GET(":ns/:name/images", h.Images)
|
rels.GET(":ns/:name/images", h.Images)
|
||||||
|
rels.GET(":ns/:name/relations", h.Relations)
|
||||||
rels.POST(":ns/:name/rollback", h.Rollback)
|
rels.POST(":ns/:name/rollback", h.Rollback)
|
||||||
rels.POST(":ns/:name/test", h.RunTests)
|
rels.POST(":ns/:name/test", h.RunTests)
|
||||||
|
|
||||||
|
|||||||
@@ -182,6 +182,16 @@ func (h *HelmHandler) Images(c *gin.Context) {
|
|||||||
c.IndentedJSON(http.StatusOK, images)
|
c.IndentedJSON(http.StatusOK, images)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *HelmHandler) Relations(c *gin.Context) {
|
||||||
|
rel := h.getRelease(c)
|
||||||
|
if rel == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
graph := objects.ExtractRelations(rel.Orig.Manifest)
|
||||||
|
c.IndentedJSON(http.StatusOK, graph)
|
||||||
|
}
|
||||||
|
|
||||||
func (h *HelmHandler) RepoVersions(c *gin.Context) {
|
func (h *HelmHandler) RepoVersions(c *gin.Context) {
|
||||||
qp, err := utils.GetQueryProps(c)
|
qp, err := utils.GetQueryProps(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
438
pkg/dashboard/objects/relations.go
Normal file
438
pkg/dashboard/objects/relations.go
Normal file
@@ -0,0 +1,438 @@
|
|||||||
|
package objects
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"k8s.io/apimachinery/pkg/util/yaml"
|
||||||
|
)
|
||||||
|
|
||||||
|
// RelationGraph represents the dependency graph of resources in a release.
|
||||||
|
type RelationGraph struct {
|
||||||
|
Nodes []RelationNode `json:"nodes"`
|
||||||
|
Edges []RelationEdge `json:"edges"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// RelationNode represents a single resource in the graph.
|
||||||
|
type RelationNode struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
Kind string `json:"kind"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
InRelease bool `json:"inRelease"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// RelationEdge represents a dependency between two resources.
|
||||||
|
type RelationEdge struct {
|
||||||
|
Source string `json:"source"`
|
||||||
|
Target string `json:"target"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func nodeID(kind, name string) string {
|
||||||
|
return kind + "/" + name
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExtractRelations parses a manifest and returns the resource relation graph.
|
||||||
|
func ExtractRelations(manifest string) RelationGraph {
|
||||||
|
dec := yaml.NewYAMLOrJSONDecoder(strings.NewReader(manifest), 4096)
|
||||||
|
|
||||||
|
var docs []map[string]interface{}
|
||||||
|
for {
|
||||||
|
var tmp map[string]interface{}
|
||||||
|
if err := dec.Decode(&tmp); err != nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if tmp == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
kind, _ := tmp["kind"].(string)
|
||||||
|
if kind == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
docs = append(docs, tmp)
|
||||||
|
}
|
||||||
|
|
||||||
|
nodes := map[string]RelationNode{}
|
||||||
|
for _, doc := range docs {
|
||||||
|
kind, _ := doc["kind"].(string)
|
||||||
|
metadata, _ := doc["metadata"].(map[string]interface{})
|
||||||
|
name, _ := metadata["name"].(string)
|
||||||
|
id := nodeID(kind, name)
|
||||||
|
nodes[id] = RelationNode{ID: id, Kind: kind, Name: name, InRelease: true}
|
||||||
|
}
|
||||||
|
|
||||||
|
var edges []RelationEdge
|
||||||
|
addEdge := func(sourceID, targetKind, targetName, edgeType string) {
|
||||||
|
tid := nodeID(targetKind, targetName)
|
||||||
|
if tid == sourceID {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if _, exists := nodes[tid]; !exists {
|
||||||
|
nodes[tid] = RelationNode{ID: tid, Kind: targetKind, Name: targetName, InRelease: false}
|
||||||
|
}
|
||||||
|
edges = append(edges, RelationEdge{Source: sourceID, Target: tid, Type: edgeType})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build label index for selector matching: workload ID -> template labels
|
||||||
|
type workloadLabels struct {
|
||||||
|
id string
|
||||||
|
labels map[string]interface{}
|
||||||
|
}
|
||||||
|
var workloads []workloadLabels
|
||||||
|
for _, doc := range docs {
|
||||||
|
kind, _ := doc["kind"].(string)
|
||||||
|
metadata, _ := doc["metadata"].(map[string]interface{})
|
||||||
|
name, _ := metadata["name"].(string)
|
||||||
|
spec, _ := doc["spec"].(map[string]interface{})
|
||||||
|
if spec == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
tpl, _ := spec["template"].(map[string]interface{})
|
||||||
|
if tpl == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
tplMeta, _ := tpl["metadata"].(map[string]interface{})
|
||||||
|
if tplMeta == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
lbls, _ := tplMeta["labels"].(map[string]interface{})
|
||||||
|
if lbls != nil {
|
||||||
|
workloads = append(workloads, workloadLabels{id: nodeID(kind, name), labels: lbls})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, doc := range docs {
|
||||||
|
kind, _ := doc["kind"].(string)
|
||||||
|
metadata, _ := doc["metadata"].(map[string]interface{})
|
||||||
|
name, _ := metadata["name"].(string)
|
||||||
|
srcID := nodeID(kind, name)
|
||||||
|
|
||||||
|
// ownerReferences
|
||||||
|
extractOwnerRefs(doc, srcID, addEdge)
|
||||||
|
|
||||||
|
// recursive *Ref fields (skip metadata to avoid self-refs from ownerReferences)
|
||||||
|
collectRefFields(doc, srcID, addEdge)
|
||||||
|
|
||||||
|
// volumes, envFrom, serviceAccount from pod specs
|
||||||
|
for _, podSpec := range findPodSpecs(kind, doc) {
|
||||||
|
extractVolumes(podSpec, srcID, addEdge)
|
||||||
|
extractEnvRefs(podSpec, srcID, addEdge)
|
||||||
|
extractServiceAccount(podSpec, srcID, addEdge)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Service selector -> workloads
|
||||||
|
if kind == "Service" {
|
||||||
|
spec, _ := doc["spec"].(map[string]interface{})
|
||||||
|
if spec != nil {
|
||||||
|
selector, _ := spec["selector"].(map[string]interface{})
|
||||||
|
if len(selector) > 0 {
|
||||||
|
for _, wl := range workloads {
|
||||||
|
if labelsMatch(selector, wl.labels) {
|
||||||
|
parts := strings.SplitN(wl.id, "/", 2)
|
||||||
|
if len(parts) == 2 {
|
||||||
|
addEdge(srcID, parts[0], parts[1], "selector")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ingress -> Service
|
||||||
|
if kind == "Ingress" {
|
||||||
|
extractIngressBackends(doc, srcID, addEdge)
|
||||||
|
}
|
||||||
|
|
||||||
|
// RoleBinding / ClusterRoleBinding
|
||||||
|
if kind == "RoleBinding" || kind == "ClusterRoleBinding" {
|
||||||
|
extractRoleBindingRefs(doc, srcID, addEdge)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deduplicate edges
|
||||||
|
edges = deduplicateEdges(edges)
|
||||||
|
|
||||||
|
nodeSlice := make([]RelationNode, 0, len(nodes))
|
||||||
|
for _, n := range nodes {
|
||||||
|
nodeSlice = append(nodeSlice, n)
|
||||||
|
}
|
||||||
|
|
||||||
|
return RelationGraph{Nodes: nodeSlice, Edges: edges}
|
||||||
|
}
|
||||||
|
|
||||||
|
func extractOwnerRefs(doc map[string]interface{}, srcID string, addEdge func(string, string, string, string)) {
|
||||||
|
metadata, _ := doc["metadata"].(map[string]interface{})
|
||||||
|
if metadata == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
owners, _ := metadata["ownerReferences"].([]interface{})
|
||||||
|
for _, o := range owners {
|
||||||
|
ref, ok := o.(map[string]interface{})
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
kind, _ := ref["kind"].(string)
|
||||||
|
name, _ := ref["name"].(string)
|
||||||
|
if kind != "" && name != "" {
|
||||||
|
addEdge(srcID, kind, name, "ownerRef")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func collectRefFields(doc map[string]interface{}, srcID string, addEdge func(string, string, string, string)) {
|
||||||
|
// Walk the doc but skip metadata (ownerReferences handled separately)
|
||||||
|
for key, value := range doc {
|
||||||
|
if key == "metadata" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
collectRefFieldsRecursive(value, srcID, addEdge)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func collectRefFieldsRecursive(obj interface{}, srcID string, addEdge func(string, string, string, string)) {
|
||||||
|
switch v := obj.(type) {
|
||||||
|
case map[string]interface{}:
|
||||||
|
for key, value := range v {
|
||||||
|
if strings.HasSuffix(key, "Ref") || strings.HasSuffix(key, "Reference") {
|
||||||
|
tryAddRef(value, srcID, addEdge)
|
||||||
|
} else {
|
||||||
|
collectRefFieldsRecursive(value, srcID, addEdge)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case []interface{}:
|
||||||
|
for _, item := range v {
|
||||||
|
collectRefFieldsRecursive(item, srcID, addEdge)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func tryAddRef(value interface{}, srcID string, addEdge func(string, string, string, string)) {
|
||||||
|
switch v := value.(type) {
|
||||||
|
case map[string]interface{}:
|
||||||
|
kind, _ := v["kind"].(string)
|
||||||
|
name, _ := v["name"].(string)
|
||||||
|
if kind != "" && name != "" {
|
||||||
|
addEdge(srcID, kind, name, "fieldRef")
|
||||||
|
}
|
||||||
|
case []interface{}:
|
||||||
|
for _, item := range v {
|
||||||
|
if ref, ok := item.(map[string]interface{}); ok {
|
||||||
|
kind, _ := ref["kind"].(string)
|
||||||
|
name, _ := ref["name"].(string)
|
||||||
|
if kind != "" && name != "" {
|
||||||
|
addEdge(srcID, kind, name, "fieldRef")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func extractVolumes(podSpec map[string]interface{}, srcID string, addEdge func(string, string, string, string)) {
|
||||||
|
volumes, _ := podSpec["volumes"].([]interface{})
|
||||||
|
for _, vol := range volumes {
|
||||||
|
v, ok := vol.(map[string]interface{})
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if cm, ok := v["configMap"].(map[string]interface{}); ok {
|
||||||
|
if name, _ := cm["name"].(string); name != "" {
|
||||||
|
addEdge(srcID, "ConfigMap", name, "volume")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if sec, ok := v["secret"].(map[string]interface{}); ok {
|
||||||
|
if name, _ := sec["secretName"].(string); name != "" {
|
||||||
|
addEdge(srcID, "Secret", name, "volume")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if pvc, ok := v["persistentVolumeClaim"].(map[string]interface{}); ok {
|
||||||
|
if name, _ := pvc["claimName"].(string); name != "" {
|
||||||
|
addEdge(srcID, "PersistentVolumeClaim", name, "volume")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if proj, ok := v["projected"].(map[string]interface{}); ok {
|
||||||
|
sources, _ := proj["sources"].([]interface{})
|
||||||
|
for _, s := range sources {
|
||||||
|
src, ok := s.(map[string]interface{})
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if cm, ok := src["configMap"].(map[string]interface{}); ok {
|
||||||
|
if name, _ := cm["name"].(string); name != "" {
|
||||||
|
addEdge(srcID, "ConfigMap", name, "volume")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if sec, ok := src["secret"].(map[string]interface{}); ok {
|
||||||
|
if name, _ := sec["name"].(string); name != "" {
|
||||||
|
addEdge(srcID, "Secret", name, "volume")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func extractEnvRefs(podSpec map[string]interface{}, srcID string, addEdge func(string, string, string, string)) {
|
||||||
|
containers, _ := podSpec["containers"].([]interface{})
|
||||||
|
initContainers, _ := podSpec["initContainers"].([]interface{})
|
||||||
|
allContainers := append(containers, initContainers...)
|
||||||
|
|
||||||
|
for _, c := range allContainers {
|
||||||
|
cMap, ok := c.(map[string]interface{})
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// envFrom
|
||||||
|
envFrom, _ := cMap["envFrom"].([]interface{})
|
||||||
|
for _, ef := range envFrom {
|
||||||
|
e, ok := ef.(map[string]interface{})
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if cmRef, ok := e["configMapRef"].(map[string]interface{}); ok {
|
||||||
|
if name, _ := cmRef["name"].(string); name != "" {
|
||||||
|
addEdge(srcID, "ConfigMap", name, "envRef")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if secRef, ok := e["secretRef"].(map[string]interface{}); ok {
|
||||||
|
if name, _ := secRef["name"].(string); name != "" {
|
||||||
|
addEdge(srcID, "Secret", name, "envRef")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// env[].valueFrom
|
||||||
|
envVars, _ := cMap["env"].([]interface{})
|
||||||
|
for _, ev := range envVars {
|
||||||
|
envVar, ok := ev.(map[string]interface{})
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
valueFrom, _ := envVar["valueFrom"].(map[string]interface{})
|
||||||
|
if valueFrom == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if cmKeyRef, ok := valueFrom["configMapKeyRef"].(map[string]interface{}); ok {
|
||||||
|
if name, _ := cmKeyRef["name"].(string); name != "" {
|
||||||
|
addEdge(srcID, "ConfigMap", name, "envRef")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if secKeyRef, ok := valueFrom["secretKeyRef"].(map[string]interface{}); ok {
|
||||||
|
if name, _ := secKeyRef["name"].(string); name != "" {
|
||||||
|
addEdge(srcID, "Secret", name, "envRef")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func extractServiceAccount(podSpec map[string]interface{}, srcID string, addEdge func(string, string, string, string)) {
|
||||||
|
if sa, _ := podSpec["serviceAccountName"].(string); sa != "" && sa != "default" {
|
||||||
|
addEdge(srcID, "ServiceAccount", sa, "serviceAccount")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func extractIngressBackends(doc map[string]interface{}, srcID string, addEdge func(string, string, string, string)) {
|
||||||
|
spec, _ := doc["spec"].(map[string]interface{})
|
||||||
|
if spec == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// default backend
|
||||||
|
if backend, ok := spec["defaultBackend"].(map[string]interface{}); ok {
|
||||||
|
addIngressServiceRef(backend, srcID, addEdge)
|
||||||
|
}
|
||||||
|
|
||||||
|
rules, _ := spec["rules"].([]interface{})
|
||||||
|
for _, r := range rules {
|
||||||
|
rule, ok := r.(map[string]interface{})
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
http, _ := rule["http"].(map[string]interface{})
|
||||||
|
if http == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
paths, _ := http["paths"].([]interface{})
|
||||||
|
for _, p := range paths {
|
||||||
|
path, ok := p.(map[string]interface{})
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
backend, _ := path["backend"].(map[string]interface{})
|
||||||
|
if backend == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
addIngressServiceRef(backend, srcID, addEdge)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TLS secrets
|
||||||
|
tls, _ := spec["tls"].([]interface{})
|
||||||
|
for _, t := range tls {
|
||||||
|
tlsEntry, ok := t.(map[string]interface{})
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if secretName, _ := tlsEntry["secretName"].(string); secretName != "" {
|
||||||
|
addEdge(srcID, "Secret", secretName, "tlsSecret")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func addIngressServiceRef(backend map[string]interface{}, srcID string, addEdge func(string, string, string, string)) {
|
||||||
|
// v1 Ingress: backend.service.name
|
||||||
|
if svc, ok := backend["service"].(map[string]interface{}); ok {
|
||||||
|
if name, _ := svc["name"].(string); name != "" {
|
||||||
|
addEdge(srcID, "Service", name, "ingressBackend")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// v1beta1 Ingress: backend.serviceName
|
||||||
|
if name, _ := backend["serviceName"].(string); name != "" {
|
||||||
|
addEdge(srcID, "Service", name, "ingressBackend")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func extractRoleBindingRefs(doc map[string]interface{}, srcID string, addEdge func(string, string, string, string)) {
|
||||||
|
// roleRef
|
||||||
|
if roleRef, ok := doc["roleRef"].(map[string]interface{}); ok {
|
||||||
|
kind, _ := roleRef["kind"].(string)
|
||||||
|
name, _ := roleRef["name"].(string)
|
||||||
|
if kind != "" && name != "" {
|
||||||
|
addEdge(srcID, kind, name, "roleBinding")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// subjects
|
||||||
|
subjects, _ := doc["subjects"].([]interface{})
|
||||||
|
for _, s := range subjects {
|
||||||
|
subj, ok := s.(map[string]interface{})
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
kind, _ := subj["kind"].(string)
|
||||||
|
name, _ := subj["name"].(string)
|
||||||
|
if kind != "" && name != "" {
|
||||||
|
addEdge(srcID, kind, name, "roleBinding")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func labelsMatch(selector, labels map[string]interface{}) bool {
|
||||||
|
for k, v := range selector {
|
||||||
|
if labels[k] != v {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func deduplicateEdges(edges []RelationEdge) []RelationEdge {
|
||||||
|
seen := map[string]bool{}
|
||||||
|
var result []RelationEdge
|
||||||
|
for _, e := range edges {
|
||||||
|
key := fmt.Sprintf("%s->%s:%s", e.Source, e.Target, e.Type)
|
||||||
|
if !seen[key] {
|
||||||
|
seen[key] = true
|
||||||
|
result = append(result, e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
184
pkg/dashboard/objects/relations_test.go
Normal file
184
pkg/dashboard/objects/relations_test.go
Normal file
@@ -0,0 +1,184 @@
|
|||||||
|
package objects
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
const testManifest = `
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: my-config
|
||||||
|
data:
|
||||||
|
key: value
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: my-secret
|
||||||
|
type: Opaque
|
||||||
|
data:
|
||||||
|
password: cGFzcw==
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ServiceAccount
|
||||||
|
metadata:
|
||||||
|
name: my-sa
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: my-app
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: my-app
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: my-app
|
||||||
|
spec:
|
||||||
|
serviceAccountName: my-sa
|
||||||
|
containers:
|
||||||
|
- name: main
|
||||||
|
image: nginx:latest
|
||||||
|
envFrom:
|
||||||
|
- configMapRef:
|
||||||
|
name: my-config
|
||||||
|
env:
|
||||||
|
- name: DB_PASS
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: my-secret
|
||||||
|
key: password
|
||||||
|
volumes:
|
||||||
|
- name: config-vol
|
||||||
|
configMap:
|
||||||
|
name: my-config
|
||||||
|
- name: secret-vol
|
||||||
|
secret:
|
||||||
|
secretName: external-secret
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: my-service
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
app: my-app
|
||||||
|
ports:
|
||||||
|
- port: 80
|
||||||
|
---
|
||||||
|
apiVersion: networking.k8s.io/v1
|
||||||
|
kind: Ingress
|
||||||
|
metadata:
|
||||||
|
name: my-ingress
|
||||||
|
spec:
|
||||||
|
rules:
|
||||||
|
- host: example.com
|
||||||
|
http:
|
||||||
|
paths:
|
||||||
|
- path: /
|
||||||
|
pathType: Prefix
|
||||||
|
backend:
|
||||||
|
service:
|
||||||
|
name: my-service
|
||||||
|
port:
|
||||||
|
number: 80
|
||||||
|
tls:
|
||||||
|
- secretName: tls-cert
|
||||||
|
hosts:
|
||||||
|
- example.com
|
||||||
|
---
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
|
kind: ClusterRoleBinding
|
||||||
|
metadata:
|
||||||
|
name: my-binding
|
||||||
|
roleRef:
|
||||||
|
apiGroup: rbac.authorization.k8s.io
|
||||||
|
kind: ClusterRole
|
||||||
|
name: my-role
|
||||||
|
subjects:
|
||||||
|
- kind: ServiceAccount
|
||||||
|
name: my-sa
|
||||||
|
namespace: default
|
||||||
|
`
|
||||||
|
|
||||||
|
func TestExtractRelations(t *testing.T) {
|
||||||
|
graph := ExtractRelations(testManifest)
|
||||||
|
|
||||||
|
// Check nodes
|
||||||
|
nodeMap := map[string]RelationNode{}
|
||||||
|
for _, n := range graph.Nodes {
|
||||||
|
nodeMap[n.ID] = n
|
||||||
|
}
|
||||||
|
|
||||||
|
// In-release nodes
|
||||||
|
inReleaseExpected := []string{
|
||||||
|
"ConfigMap/my-config",
|
||||||
|
"Secret/my-secret",
|
||||||
|
"ServiceAccount/my-sa",
|
||||||
|
"Deployment/my-app",
|
||||||
|
"Service/my-service",
|
||||||
|
"Ingress/my-ingress",
|
||||||
|
"ClusterRoleBinding/my-binding",
|
||||||
|
}
|
||||||
|
for _, id := range inReleaseExpected {
|
||||||
|
n, ok := nodeMap[id]
|
||||||
|
if !ok {
|
||||||
|
t.Errorf("missing in-release node %s", id)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if !n.InRelease {
|
||||||
|
t.Errorf("node %s should be inRelease=true", id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ghost nodes (external references)
|
||||||
|
ghostExpected := []string{
|
||||||
|
"Secret/external-secret",
|
||||||
|
"Secret/tls-cert",
|
||||||
|
"ClusterRole/my-role",
|
||||||
|
}
|
||||||
|
for _, id := range ghostExpected {
|
||||||
|
n, ok := nodeMap[id]
|
||||||
|
if !ok {
|
||||||
|
t.Errorf("missing ghost node %s", id)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if n.InRelease {
|
||||||
|
t.Errorf("node %s should be inRelease=false", id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check edges
|
||||||
|
edgeSet := map[string]bool{}
|
||||||
|
for _, e := range graph.Edges {
|
||||||
|
key := e.Source + " -" + e.Type + "-> " + e.Target
|
||||||
|
edgeSet[key] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
expectedEdges := []string{
|
||||||
|
"Deployment/my-app -volume-> ConfigMap/my-config",
|
||||||
|
"Deployment/my-app -volume-> Secret/external-secret",
|
||||||
|
"Deployment/my-app -envRef-> ConfigMap/my-config",
|
||||||
|
"Deployment/my-app -envRef-> Secret/my-secret",
|
||||||
|
"Deployment/my-app -serviceAccount-> ServiceAccount/my-sa",
|
||||||
|
"Service/my-service -selector-> Deployment/my-app",
|
||||||
|
"Ingress/my-ingress -ingressBackend-> Service/my-service",
|
||||||
|
"Ingress/my-ingress -tlsSecret-> Secret/tls-cert",
|
||||||
|
"ClusterRoleBinding/my-binding -roleBinding-> ClusterRole/my-role",
|
||||||
|
"ClusterRoleBinding/my-binding -roleBinding-> ServiceAccount/my-sa",
|
||||||
|
}
|
||||||
|
for _, e := range expectedEdges {
|
||||||
|
if !edgeSet[e] {
|
||||||
|
t.Errorf("missing edge: %s", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Logf("Nodes: %d, Edges: %d", len(graph.Nodes), len(graph.Edges))
|
||||||
|
for _, e := range graph.Edges {
|
||||||
|
t.Logf(" %s --%s--> %s", e.Source, e.Type, e.Target)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user