Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#452 - Adding support for Kubernetes Gateway API (such as HTTPRoute) #453

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# 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: "npm" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"

- package-ecosystem: "npm" # See documentation for possible values
directory: "/client" # Location of package manifests
schedule:
interval: "weekly"

51 changes: 49 additions & 2 deletions controllers/apps/docker/useKubernetes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,45 @@ const Logger = require('../../../utils/Logger');
const logger = new Logger();
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' },
{ 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']],
});
Expand All @@ -29,6 +51,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) {
Expand All @@ -47,13 +75,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 });
Expand Down
3 changes: 3 additions & 0 deletions k8s/base/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down