From 2518a886210e970be44c25075a1a89229257e23c Mon Sep 17 00:00:00 2001 From: Richard Sanders Date: Fri, 12 Apr 2024 08:46:43 -0400 Subject: [PATCH 1/5] Adding support for sigs.k8s.io gateway-api routes, updated rbac.yaml template with new apiGroups and resources. --- controllers/apps/docker/useKubernetes.js | 50 +++++++++++++++++++++++- k8s/base/rbac.yaml | 3 ++ 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/controllers/apps/docker/useKubernetes.js b/controllers/apps/docker/useKubernetes.js index d9961cd..89a58b8 100644 --- a/controllers/apps/docker/useKubernetes.js +++ b/controllers/apps/docker/useKubernetes.js @@ -4,23 +4,44 @@ const Logger = require('../../../utils/Logger'); const logger = new Logger(); 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 { useOrdering: orderType, unpinStoppedApps } = await loadConfig(); let ingresses = null; + let routeData = []; try { const kc = new k8s.KubeConfig(); kc.loadFromCluster(); + const k8sNetworkingV1Api = kc.makeApiClient(k8s.NetworkingV1Api); await k8sNetworkingV1Api.listIngressForAllNamespaces().then((res) => { 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 { 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({ order: [[orderType, 'ASC']], }); @@ -29,6 +50,12 @@ const useKubernetes = async (apps) => { (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 = []; 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) { for (const app of apps) { await app.update({ isPinned: false }); } } - for (const item of kubernetesApps) { + for (const item of uniqueApps) { if (apps.some((app) => app.name === item.name)) { const app = apps.find((a) => a.name === item.name); await app.update({ ...item, isPinned: true }); diff --git a/k8s/base/rbac.yaml b/k8s/base/rbac.yaml index eedb941..9d6f2c9 100644 --- a/k8s/base/rbac.yaml +++ b/k8s/base/rbac.yaml @@ -12,6 +12,9 @@ rules: - apiGroups: ["networking.k8s.io"] resources: ["ingresses"] 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 kind: ClusterRoleBinding From 5f6d2e2146b1ae7ee480f059ca58cbfb78463d1f Mon Sep 17 00:00:00 2001 From: Richard Sanders Date: Fri, 12 Apr 2024 10:57:02 -0400 Subject: [PATCH 2/5] Update useKubernetes.js --- controllers/apps/docker/useKubernetes.js | 1 + 1 file changed, 1 insertion(+) diff --git a/controllers/apps/docker/useKubernetes.js b/controllers/apps/docker/useKubernetes.js index 89a58b8..cf1d809 100644 --- a/controllers/apps/docker/useKubernetes.js +++ b/controllers/apps/docker/useKubernetes.js @@ -7,6 +7,7 @@ const loadConfig = require('../../../utils/loadConfig'); const gatewayRoutes = [ { type: 'httproutes', version: 'v1' }, + { type: 'httproutes', version: 'v1beta1' }, { type: 'tcproutes', version: 'v1alpha2' }, { type: 'grpcroutes', version: 'v1alpha2' }, { type: 'tlsroutes', version: 'v1alpha2' }, From 2588e7acaf27cef436c85895ba23ff87c93f3c26 Mon Sep 17 00:00:00 2001 From: Richard Sanders Date: Mon, 15 Apr 2024 08:52:53 -0400 Subject: [PATCH 3/5] Create dependabot.yml --- .github/dependabot.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..c77d007 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,12 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file + +version: 2 +updates: + - package-ecosystem: "" # See documentation for possible values + directory: "/" # Location of package manifests + schedule: + interval: "weekly" + From 22e1424b448b7c9721af730e76bcd4b8bb369e5c Mon Sep 17 00:00:00 2001 From: Richard Sanders Date: Mon, 15 Apr 2024 08:55:23 -0400 Subject: [PATCH 4/5] Update dependabot.yml --- .github/dependabot.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index c77d007..cd09173 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -5,7 +5,7 @@ version: 2 updates: - - package-ecosystem: "" # See documentation for possible values + - package-ecosystem: "npm" # See documentation for possible values directory: "/" # Location of package manifests schedule: interval: "weekly" From 6dcbf7346a3d852ea4989b7273c4cea3dbf58af8 Mon Sep 17 00:00:00 2001 From: Richard Sanders Date: Mon, 15 Apr 2024 08:58:15 -0400 Subject: [PATCH 5/5] Update dependabot.yml --- .github/dependabot.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index cd09173..7841196 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -10,3 +10,8 @@ updates: schedule: interval: "weekly" + - package-ecosystem: "npm" # See documentation for possible values + directory: "/client" # Location of package manifests + schedule: + interval: "weekly" +