mirror of
https://github.com/pawelmalak/flame.git
synced 2025-07-19 11:39:36 +02:00
chore(): kubernetes integration
This commit is contained in:
parent
b3d6a8e30d
commit
95c41b62ac
9 changed files with 5256 additions and 88 deletions
|
@ -56,4 +56,4 @@
|
||||||
- Added 'warnings' to apps and bookmarks forms about supported url formats ([#5](https://github.com/pawelmalak/flame/issues/5))
|
- Added 'warnings' to apps and bookmarks forms about supported url formats ([#5](https://github.com/pawelmalak/flame/issues/5))
|
||||||
|
|
||||||
### v1.0 (2021-06-08)
|
### 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.
|
||||||
|
|
23
README.md
23
README.md
|
@ -22,6 +22,7 @@ Flame is self-hosted startpage for your server. Its design is inspired (heavily)
|
||||||
- TypeScript
|
- TypeScript
|
||||||
- Deployment
|
- Deployment
|
||||||
- Docker
|
- Docker
|
||||||
|
- Kubernetes
|
||||||
|
|
||||||
## Development
|
## Development
|
||||||
|
|
||||||
|
@ -80,6 +81,13 @@ services:
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Skaffold
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# use skaffold
|
||||||
|
skaffold dev
|
||||||
|
```
|
||||||
|
|
||||||
### Without Docker
|
### Without Docker
|
||||||
|
|
||||||
Follow instructions from wiki: [Installation without Docker](https://github.com/pawelmalak/flame/wiki/Installation-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.
|
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
|
### Custom CSS
|
||||||
|
|
||||||
> This is an experimental feature. Its behaviour might change in the future.
|
> This is an experimental feature. Its behaviour might change in the future.
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
REACT_APP_VERSION=1.6.3
|
REACT_APP_VERSION=1.6.3
|
||||||
|
|
|
@ -52,6 +52,7 @@ const OtherSettings = (props: ComponentProps): JSX.Element => {
|
||||||
bookmarksSameTab: 0,
|
bookmarksSameTab: 0,
|
||||||
searchSameTab: 0,
|
searchSameTab: 0,
|
||||||
dockerApps: 1,
|
dockerApps: 1,
|
||||||
|
kubernetesApps: 1,
|
||||||
unpinStoppedApps: 1
|
unpinStoppedApps: 1
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -71,6 +72,7 @@ const OtherSettings = (props: ComponentProps): JSX.Element => {
|
||||||
bookmarksSameTab: searchConfig('bookmarksSameTab', 0),
|
bookmarksSameTab: searchConfig('bookmarksSameTab', 0),
|
||||||
searchSameTab: searchConfig('searchSameTab', 0),
|
searchSameTab: searchConfig('searchSameTab', 0),
|
||||||
dockerApps: searchConfig('dockerApps', 0),
|
dockerApps: searchConfig('dockerApps', 0),
|
||||||
|
kubernetesApps: searchConfig('kubernetesApps', 0),
|
||||||
unpinStoppedApps: searchConfig('unpinStoppedApps', 0)
|
unpinStoppedApps: searchConfig('unpinStoppedApps', 0)
|
||||||
});
|
});
|
||||||
}, [props.loading]);
|
}, [props.loading]);
|
||||||
|
@ -297,6 +299,21 @@ const OtherSettings = (props: ComponentProps): JSX.Element => {
|
||||||
<option value={0}>False</option>
|
<option value={0}>False</option>
|
||||||
</select>
|
</select>
|
||||||
</InputGroup>
|
</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>
|
<Button>Save changes</Button>
|
||||||
</form>
|
</form>
|
||||||
);
|
);
|
||||||
|
|
|
@ -19,5 +19,6 @@ export interface SettingsForm {
|
||||||
bookmarksSameTab: number;
|
bookmarksSameTab: number;
|
||||||
searchSameTab: number;
|
searchSameTab: number;
|
||||||
dockerApps: number;
|
dockerApps: number;
|
||||||
|
kubernetesApps: number;
|
||||||
unpinStoppedApps: number;
|
unpinStoppedApps: number;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ const { Sequelize } = require('sequelize');
|
||||||
const axios = require('axios');
|
const axios = require('axios');
|
||||||
const Logger = require('../utils/Logger');
|
const Logger = require('../utils/Logger');
|
||||||
const logger = new Logger();
|
const logger = new Logger();
|
||||||
|
const k8s = require('@kubernetes/client-node');
|
||||||
|
|
||||||
// @desc Create new app
|
// @desc Create new app
|
||||||
// @route POST /api/apps
|
// @route POST /api/apps
|
||||||
|
@ -51,6 +52,9 @@ exports.getApps = asyncWrapper(async (req, res, next) => {
|
||||||
const useDockerApi = await Config.findOne({
|
const useDockerApi = await Config.findOne({
|
||||||
where: { key: 'dockerApps' }
|
where: { key: 'dockerApps' }
|
||||||
});
|
});
|
||||||
|
const useKubernetesApi = await Config.findOne({
|
||||||
|
where: { key: 'kubernetesApps' }
|
||||||
|
});
|
||||||
const unpinStoppedApps = await Config.findOne({
|
const unpinStoppedApps = await Config.findOne({
|
||||||
where: { key: 'unpinStoppedApps' }
|
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') {
|
if (orderType == 'name') {
|
||||||
apps = await App.findAll({
|
apps = await App.findAll({
|
||||||
order: [[Sequelize.fn('lower', Sequelize.col('name')), 'ASC']]
|
order: [[Sequelize.fn('lower', Sequelize.col('name')), 'ASC']]
|
||||||
|
|
5229
package-lock.json
generated
5229
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -10,11 +10,13 @@
|
||||||
"dev-init": "npm run init-server && npm run init-client",
|
"dev-init": "npm run init-server && npm run init-client",
|
||||||
"dev-server": "nodemon server.js",
|
"dev-server": "nodemon server.js",
|
||||||
"dev-client": "npm start --prefix client",
|
"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": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@kubernetes/client-node": "^0.15.0",
|
||||||
"@types/express": "^4.17.11",
|
"@types/express": "^4.17.11",
|
||||||
"axios": "^0.21.1",
|
"axios": "^0.21.1",
|
||||||
"colors": "^1.4.0",
|
"colors": "^1.4.0",
|
||||||
|
|
|
@ -68,6 +68,10 @@
|
||||||
"key": "dockerApps",
|
"key": "dockerApps",
|
||||||
"value": false
|
"value": false
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"key": "kubernetesApps",
|
||||||
|
"value": false
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"key": "unpinStoppedApps",
|
"key": "unpinStoppedApps",
|
||||||
"value": false
|
"value": false
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue