mirror of
https://github.com/pawelmalak/flame.git
synced 2025-07-19 11:39:36 +02:00
Adding support for sigs.k8s.io gateway-api routes, updated rbac.yaml template with new apiGroups and resources.
This commit is contained in:
parent
3c347c854c
commit
2518a88621
2 changed files with 51 additions and 2 deletions
|
@ -4,23 +4,44 @@ const Logger = require('../../../utils/Logger');
|
||||||
const logger = new Logger();
|
const logger = new Logger();
|
||||||
const loadConfig = require('../../../utils/loadConfig');
|
const loadConfig = require('../../../utils/loadConfig');
|
||||||
|
|
||||||
|
|
||||||
|
const gatewayRoutes = [
|
||||||
|
{ type: 'httproutes', version: 'v1' },
|
||||||
|
{ type: 'tcproutes', version: 'v1alpha2' },
|
||||||
|
{ type: 'grpcroutes', version: 'v1alpha2' },
|
||||||
|
{ type: 'tlsroutes', version: 'v1alpha2' },
|
||||||
|
{ type: 'udproutes', version: 'v1alpha2' }
|
||||||
|
];
|
||||||
|
|
||||||
const useKubernetes = async (apps) => {
|
const useKubernetes = async (apps) => {
|
||||||
const { useOrdering: orderType, unpinStoppedApps } = await loadConfig();
|
const { useOrdering: orderType, unpinStoppedApps } = await loadConfig();
|
||||||
|
|
||||||
let ingresses = null;
|
let ingresses = null;
|
||||||
|
let routeData = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const kc = new k8s.KubeConfig();
|
const kc = new k8s.KubeConfig();
|
||||||
kc.loadFromCluster();
|
kc.loadFromCluster();
|
||||||
|
|
||||||
const k8sNetworkingV1Api = kc.makeApiClient(k8s.NetworkingV1Api);
|
const k8sNetworkingV1Api = kc.makeApiClient(k8s.NetworkingV1Api);
|
||||||
await k8sNetworkingV1Api.listIngressForAllNamespaces().then((res) => {
|
await k8sNetworkingV1Api.listIngressForAllNamespaces().then((res) => {
|
||||||
ingresses = res.body.items;
|
ingresses = res.body.items;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const customObjectsApi = kc.makeApiClient(k8s.CustomObjectsApi);
|
||||||
|
for (let route of gatewayRoutes) {
|
||||||
|
await customObjectsApi.listClusterCustomObject('gateway.networking.k8s.io', route.version, route.type).then((res) => {
|
||||||
|
res.body.items.forEach(item => routeData.push({ ...item, routeType: route.type }));
|
||||||
|
}).catch(error => {
|
||||||
|
logger.log(`Error fetching ${route.type}: ${error.message}`, 'ERROR');
|
||||||
|
});
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
logger.log("Can't connect to the Kubernetes API", 'ERROR');
|
logger.log("Can't connect to the Kubernetes API", 'ERROR');
|
||||||
|
logger.log(error.message, 'ERROR');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ingresses) {
|
if (ingresses || routeData.length > 0) {
|
||||||
apps = await App.findAll({
|
apps = await App.findAll({
|
||||||
order: [[orderType, 'ASC']],
|
order: [[orderType, 'ASC']],
|
||||||
});
|
});
|
||||||
|
@ -29,6 +50,12 @@ const useKubernetes = async (apps) => {
|
||||||
(e) => Object.keys(e.metadata.annotations).length !== 0
|
(e) => Object.keys(e.metadata.annotations).length !== 0
|
||||||
);
|
);
|
||||||
|
|
||||||
|
routeData = routeData.filter(
|
||||||
|
item => item.metadata &&
|
||||||
|
item.metadata.annotations &&
|
||||||
|
Object.keys(item.metadata.annotations).length !== 0
|
||||||
|
);
|
||||||
|
|
||||||
const kubernetesApps = [];
|
const kubernetesApps = [];
|
||||||
|
|
||||||
for (const ingress of ingresses) {
|
for (const ingress of ingresses) {
|
||||||
|
@ -47,13 +74,32 @@ const useKubernetes = async (apps) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const item of routeData) {
|
||||||
|
const annotations = item.metadata.annotations || {};
|
||||||
|
|
||||||
|
if (/^app/.test(annotations['flame.pawelmalak/type'])) {
|
||||||
|
if (item.spec && item.spec.hostnames) {
|
||||||
|
item.spec.hostnames.forEach(hostname => {
|
||||||
|
kubernetesApps.push({
|
||||||
|
name: annotations['flame.pawelmalak/name'] || item.metadata.name,
|
||||||
|
url: annotations['flame.pawelmalak/url'] || hostname,
|
||||||
|
icon: annotations['flame.pawelmalak/icon'] || 'kubernetes',
|
||||||
|
type: item.routeType.toUpperCase()
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const uniqueApps = Array.from(new Set(kubernetesApps.map(app => JSON.stringify(app)))).map(item => JSON.parse(item));
|
||||||
|
|
||||||
if (unpinStoppedApps) {
|
if (unpinStoppedApps) {
|
||||||
for (const app of apps) {
|
for (const app of apps) {
|
||||||
await app.update({ isPinned: false });
|
await app.update({ isPinned: false });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const item of kubernetesApps) {
|
for (const item of uniqueApps) {
|
||||||
if (apps.some((app) => app.name === item.name)) {
|
if (apps.some((app) => app.name === item.name)) {
|
||||||
const app = apps.find((a) => a.name === item.name);
|
const app = apps.find((a) => a.name === item.name);
|
||||||
await app.update({ ...item, isPinned: true });
|
await app.update({ ...item, isPinned: true });
|
||||||
|
|
|
@ -12,6 +12,9 @@ rules:
|
||||||
- apiGroups: ["networking.k8s.io"]
|
- apiGroups: ["networking.k8s.io"]
|
||||||
resources: ["ingresses"]
|
resources: ["ingresses"]
|
||||||
verbs: ["get", "list", "watch"]
|
verbs: ["get", "list", "watch"]
|
||||||
|
- apiGroups: ["gateway.networking.k8s.io"]
|
||||||
|
resources: ["tcproutes","httproutes","grpcroutes","tlsroutes","udproutes"]
|
||||||
|
verbs: ["get", "list", "watch"]
|
||||||
---
|
---
|
||||||
apiVersion: rbac.authorization.k8s.io/v1
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
kind: ClusterRoleBinding
|
kind: ClusterRoleBinding
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue