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

Kubernetes Mock API #17

Merged
merged 10 commits into from
Dec 8, 2020
Merged
Show file tree
Hide file tree
Changes from 9 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
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"**/.DS_Store": true
},
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": false
},
"cSpell.words": [
"Deduplication",
Expand Down
7 changes: 7 additions & 0 deletions Environment/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ http {
proxy_set_header Tenant-ID 508c1745-5f2a-4b4c-b7a5-2fbb1484346d;
}

location /api/v1 {
proxy_pass http://host.docker.internal:3001;
proxy_set_header Host localhost:9000;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Tenant-ID 508c1745-5f2a-4b4c-b7a5-2fbb1484346d;
}

location /api/k8s {
proxy_pass http://host.docker.internal:3001;
proxy_set_header Host localhost:9000;
Expand Down
19 changes: 18 additions & 1 deletion Source/Applications/Backend/applications/ApplicationQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import { ILogger } from '@shared/backend/logging';
import { injectable } from 'tsyringe';
import { Application, ApplicationModel } from './Application';

import { NamespaceList } from '@shared/backend/k8s/NamespaceList';
pavsaund marked this conversation as resolved.
Show resolved Hide resolved

import { Guid } from '@dolittle/rudiments';
import fetch from 'node-fetch';

@injectable()
@Resolver(Application)
export class ApplicationQueries {
Expand All @@ -14,6 +19,18 @@ export class ApplicationQueries {

@Query(returns => [Application])
async allApplications() {
return ApplicationModel.find();

const response = await fetch('http://localhost:3001/api/v1/namespaces');
const namespaces = await response.json() as NamespaceList;

const applications = namespaces.items.map(_ => {
const guid = _.metadata.name.replace('application-', '');
const application = new Application();
application._id = Guid.parse(guid);
application.name = _.metadata.labels.application || 'unknown';
return application;
});

return applications;
}
}
3 changes: 2 additions & 1 deletion Source/K8sMock/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ import { PartitionedFilterResult } from '@dolittle/sdk.events.filtering';
dolittleRuntimePort: 50055,
graphQLSchema: schema,
defaultDatabaseName: 'k8s',
defaultEventStoreDatabaseName: 'event_store_k8smock',
expressCallback: _ => {
_.use(
'/api/k8s/swagger',
'/api/swagger',
swaggerUi.serve,
swaggerUi.setup(swagger)
);
Expand Down
1 change: 1 addition & 0 deletions Source/K8sMock/k8s-swagger.json

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions Source/K8sMock/namespaces/NamespacesController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) Dolittle. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

import { Controller, Get, Route, Tags } from 'tsoa';
import { PodList } from '@shared/backend/k8s/PodList';

const namespaces = require('./namespaces.json') as PodList;

@Route('api/v1/namespaces')
@Tags('core_v1')
export class NamespacesController extends Controller {

@Get()
async getNamespaces(): Promise<PodList> {
return namespaces;
}
}
pavsaund marked this conversation as resolved.
Show resolved Hide resolved
43 changes: 43 additions & 0 deletions Source/K8sMock/namespaces/namespaces-full-sample.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"apiVersion": "v1",
"items": [
{
"metadata": {
"name": "Portal",
"creationTimestamp": "2020-12-07T17:00:28Z",
"labels": {
"app": "Something"
}
},
"spec": {
"containers": [
{
"name": "Portal",
"image": "dolittle/studio/portal:1.0.0",
"args": []
}
]
}
}
],
"status": {
"phase": "Running",
"startTime": "2020-12-07T17:00:28Z",
"containerStatuses": [
{
"containerID": "docker://9656265f3d8207d2ec8ce5962f3d25b34f784a9466c268492f06766f03665881",
"name": "Portal",
"image": "dolittle/studio/portal:1.0.0",
"imageID": "docker-pullable://docker/desktop-vpnkit-controller@sha256:6800d69751e483710a0949fbd01c459934a18ede9d227166def0af44f3a46970",
"ready": true,
"started": true,
"state": {
"running": {
"startedAt": "2020-12-07T17:06:07Z"
}
},
"lastState": {}
}
]
}
}
15 changes: 15 additions & 0 deletions Source/K8sMock/namespaces/namespaces.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"apiVersion": "v1",
"kind": "NamespaceList",
"items": [
{
"metadata": {
"name": "application-fe7736bb-57fc-4166-bb91-6954f4dd4eb7",
"labels": {
"tenant": "Dolittle",
"application": "Studio"
}
}
}
]
}
1 change: 1 addition & 0 deletions Source/K8sMock/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"scripts": {
"dev": "concurrently \"nodemon -x tsoa spec-and-routes\" \"nodemon index.ts\"",
"debug": "nodemon --inspect -e ts --exec node -r ts-node/register index.ts",
"k8s-api": "docker run --rm -p 80:8080 -e SWAGGER_JSON=/k8s-swagger.json -v $(pwd)/k8s-swagger.json:/k8s-swagger.json swaggerapi/swagger-ui",
"start": "ts-node index.ts",
"build": "tsc -b --clean && tsc -b"
},
Expand Down
17 changes: 17 additions & 0 deletions Source/K8sMock/pods/PodsController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) Dolittle. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

import { Controller, Get, Route, Tags } from 'tsoa';
import { PodList } from '@shared/backend/k8s/PodList';

const pods = require('./pods.json') as PodList;

@Route('api/v1/namespaces')
@Tags('core_v1')
export class PodsController extends Controller {

@Get('{namespace}/pods')
async getPods(): Promise<PodList> {
return pods;
}
}
Loading