chore(): kubernetes integration

This commit is contained in:
shokohsc 2021-08-11 13:55:28 +02:00
parent b3d6a8e30d
commit 95c41b62ac
9 changed files with 5256 additions and 88 deletions

View file

@ -56,4 +56,4 @@
- Added 'warnings' to apps and bookmarks forms about supported url formats ([#5](https://github.com/pawelmalak/flame/issues/5))
### v1.0 (2021-06-08)
Initial release of Flame - self-hosted startpage using Node.js on backend and React on frontend.
Initial release of Flame - self-hosted startpage using Node.js on backend and React on frontend.

View file

@ -22,6 +22,7 @@ Flame is self-hosted startpage for your server. Its design is inspired (heavily)
- TypeScript
- Deployment
- Docker
- Kubernetes
## Development
@ -80,6 +81,13 @@ services:
restart: unless-stopped
```
#### Skaffold
```sh
# use skaffold
skaffold dev
```
### Without Docker
Follow instructions from wiki: [Installation without Docker](https://github.com/pawelmalak/flame/wiki/Installation-without-docker)
@ -170,6 +178,21 @@ labels:
And you must have activated the Docker sync option in the settings panel.
### Kubernetes integration
In order to use the Kubernetes integration, each ingress must have the following annotations:
```yml
metadata:
annotations:
- flame.pawelmalak/type=application # "app" works too
- flame.pawelmalak/name=My container
- flame.pawelmalak/url=https://example.com
- flame.pawelmalak/icon=icon-name # Optional, default is "kubernetes"
```
And you must have activated the Kubernetes sync option in the settings panel.
### Custom CSS
> This is an experimental feature. Its behaviour might change in the future.

View file

@ -1 +1 @@
REACT_APP_VERSION=1.6.3
REACT_APP_VERSION=1.6.3

View file

@ -52,6 +52,7 @@ const OtherSettings = (props: ComponentProps): JSX.Element => {
bookmarksSameTab: 0,
searchSameTab: 0,
dockerApps: 1,
kubernetesApps: 1,
unpinStoppedApps: 1
});
@ -71,6 +72,7 @@ const OtherSettings = (props: ComponentProps): JSX.Element => {
bookmarksSameTab: searchConfig('bookmarksSameTab', 0),
searchSameTab: searchConfig('searchSameTab', 0),
dockerApps: searchConfig('dockerApps', 0),
kubernetesApps: searchConfig('kubernetesApps', 0),
unpinStoppedApps: searchConfig('unpinStoppedApps', 0)
});
}, [props.loading]);
@ -297,6 +299,21 @@ const OtherSettings = (props: ComponentProps): JSX.Element => {
<option value={0}>False</option>
</select>
</InputGroup>
{/* KUBERNETES SETTINGS */}
<h2 className={classes.SettingsSection}>Kubernetes</h2>
<InputGroup>
<label htmlFor='kubernetesApps'>Use Kubernetes Ingress API</label>
<select
id='kubernetesApps'
name='kubernetesApps'
value={formData.kubernetesApps}
onChange={e => inputChangeHandler(e, true)}
>
<option value={1}>True</option>
<option value={0}>False</option>
</select>
</InputGroup>
<Button>Save changes</Button>
</form>
);

View file

@ -19,5 +19,6 @@ export interface SettingsForm {
bookmarksSameTab: number;
searchSameTab: number;
dockerApps: number;
kubernetesApps: number;
unpinStoppedApps: number;
}

View file

@ -6,6 +6,7 @@ const { Sequelize } = require('sequelize');
const axios = require('axios');
const Logger = require('../utils/Logger');
const logger = new Logger();
const k8s = require('@kubernetes/client-node');
// @desc Create new app
// @route POST /api/apps
@ -51,6 +52,9 @@ exports.getApps = asyncWrapper(async (req, res, next) => {
const useDockerApi = await Config.findOne({
where: { key: 'dockerApps' }
});
const useKubernetesApi = await Config.findOne({
where: { key: 'kubernetesApps' }
});
const unpinStoppedApps = await Config.findOne({
where: { key: 'unpinStoppedApps' }
});
@ -116,6 +120,64 @@ exports.getApps = asyncWrapper(async (req, res, next) => {
}
}
if (useKubernetesApi && useKubernetesApi.value == 1) {
let ingresses = null;
try {
const kc = new k8s.KubeConfig();
kc.loadFromCluster();
const k8sNetworkingV1Api = kc.makeApiClient(k8s.NetworkingV1Api);
await k8sNetworkingV1Api.listIngressForAllNamespaces()
.then((res) => {
ingresses = res.body.items;
});
} catch {
logger.log("Can't connect to the kubernetes api", 'ERROR');
}
if (ingresses) {
apps = await App.findAll({
order: [[orderType, 'ASC']]
});
ingresses = ingresses.filter(e => Object.keys(e.metadata.annotations).length !== 0);
const kubernetesApps = [];
for (const ingress of ingresses) {
const annotations = ingress.metadata.annotations;
if (
'flame.pawelmalak/name' in annotations &&
'flame.pawelmalak/url' in annotations &&
/^app/.test(annotations['flame.pawelmalak/type'])
) {
kubernetesApps.push({
name: annotations['flame.pawelmalak/name'],
url: annotations['flame.pawelmalak/url'],
icon: annotations['flame.pawelmalak/icon'] || 'kubernetes'
});
}
}
if (unpinStoppedApps && unpinStoppedApps.value == 1) {
for (const app of apps) {
await app.update({ isPinned: false });
}
}
for (const item of kubernetesApps) {
if (apps.some(app => app.name === item.name)) {
const app = apps.filter(e => e.name === item.name)[0];
await app.update({ ...item, isPinned: true });
} else {
await App.create({
...item,
isPinned: true
});
}
}
}
}
if (orderType == 'name') {
apps = await App.findAll({
order: [[Sequelize.fn('lower', Sequelize.col('name')), 'ASC']]

5229
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -10,11 +10,13 @@
"dev-init": "npm run init-server && npm run init-client",
"dev-server": "nodemon server.js",
"dev-client": "npm start --prefix client",
"dev": "concurrently \"npm run dev-server\" \"npm run dev-client\""
"dev": "concurrently \"npm run dev-server\" \"npm run dev-client\"",
"skaffold": "concurrently \"npm run init-client\" \"npm run dev-server\""
},
"author": "",
"license": "ISC",
"dependencies": {
"@kubernetes/client-node": "^0.15.0",
"@types/express": "^4.17.11",
"axios": "^0.21.1",
"colors": "^1.4.0",

View file

@ -68,6 +68,10 @@
"key": "dockerApps",
"value": false
},
{
"key": "kubernetesApps",
"value": false
},
{
"key": "unpinStoppedApps",
"value": false