Skip to content

Commit b2ebe11

Browse files
authored
Merge pull request #9 from hyperweb-io/ui/dashboard
UI/dashboard
2 parents 5c56cb8 + 172a092 commit b2ebe11

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+98637
-47
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
**/.DS_Store
33
**/dist
44
**/yarn-error.log
5-
lerna-debug.log
5+
lerna-debug.log
6+
.aiccontent

packages/kubernetesjs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,6 @@
5050
"test:deploy": "ts-node scripts/deploy.ts"
5151
},
5252
"devDependencies": {
53-
"schema-sdk": "^0.7.0"
53+
"schema-sdk": "^0.11.3"
5454
}
5555
}

packages/kubernetesjs/src/client.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { URLSearchParams } from 'url';
2-
31
interface RequestOptions<Params> {
42
hostname?: string;
53
path: string;
@@ -15,6 +13,7 @@ export interface APIClientOptions {
1513
}
1614

1715
export interface APIClientRequestHeaders {
16+
[key: string]: string | number | string[] | undefined;
1817
accept?: string | string[] | undefined;
1918
'accept-charset'?: string | string[] | undefined;
2019
'accept-encoding'?: string | string[] | undefined;
@@ -110,11 +109,28 @@ export class APIClient {
110109
}
111110

112111
private buildFullPath(endpoint: string, query?: { [key: string]: any }): string {
113-
const url = new URL(endpoint, this.baseUrl);
112+
// If baseUrl is a relative proxy path (e.g. '/api/k8s'), build manually
113+
if (this.baseUrl.startsWith('/')) {
114+
// Remove any trailing slash from baseUrl, ensure endpoint starts with '/'
115+
const base = this.baseUrl.replace(/\/$/, '')
116+
let url = `${base}${endpoint}`
117+
if (query) {
118+
// Build query params as a simple record so URLSearchParams can accept it
119+
const record: Record<string, string> = {}
120+
Object.keys(query).forEach(key => {
121+
record[key] = String(query[key])
122+
})
123+
const params = new URLSearchParams(record).toString()
124+
if (params) url += `?${params}`
125+
}
126+
return url
127+
}
128+
// Otherwise, treat baseUrl as an absolute URL
129+
const url = new URL(endpoint, this.baseUrl)
114130
if (query) {
115-
Object.keys(query).forEach(key => url.searchParams.append(key, query[key]));
131+
Object.keys(query).forEach(key => url.searchParams.append(key, query[key]))
116132
}
117-
return url.toString();
133+
return url.toString()
118134
}
119135

120136
private async request<Resp>(options: RequestOptions<any>): Promise<Resp> {

packages/react/README.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# KubernetesJS
2+
3+
<p align="center" width="100%">
4+
<img src="https://github.com/hyperweb-io/interweb-utils/assets/545047/89c743c4-be88-409f-9a77-4b02cd7fe9a4" width="80">
5+
<br/>
6+
TypeScript Client for Kubernetes
7+
<br />
8+
<a href="https://github.com/hyperweb-io/kubernetesjs/actions/workflows/ci.yml">
9+
<img height="20" src="https://github.com/hyperweb-io/kubernetesjs/actions/workflows/ci.yml/badge.svg"/>
10+
</a>
11+
<a href="https://github.com/hyperweb-io/kubernetesjs/blob/main/LICENSE">
12+
<img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"/>
13+
</a>
14+
</p>
15+
16+
17+
KubernetesJS is a **fully-typed**, zero-dependency TypeScript library designed to simplify interactions with Kubernetes APIs. With comprehensive TypeScript support, it provides a strongly-typed interface that makes managing Kubernetes resources clear and predictable, ideal for TypeScript developers looking to integrate Kubernetes management into their applications.
18+
19+
## Features
20+
21+
- **🔒 Fully Typed**: Complete TypeScript definitions for all functions and models for an enhanced development experience.
22+
- **🚀 Zero Dependencies**: Works out of the box without the need for additional installations.
23+
- **📡 Full Kubernetes API Coverage**: Supports all Kubernetes API endpoints with detailed TypeScript types.
24+
- **🌐 Cross-Platform**: Works with both Node.js and browser environments.
25+
26+
## Installation
27+
28+
To install KubernetesJS, you can use npm or yarn:
29+
30+
```bash
31+
npm install kubernetesjs
32+
# or
33+
yarn add kubernetesjs
34+
35+
```
36+
37+
## Example
38+
39+
```js
40+
import { KubernetesClient } from "kubernetesjs";
41+
42+
const client = new KubernetesClient({
43+
restEndpoint: 'http://127.0.0.1:8001'
44+
});
45+
46+
const result = await client.listCoreV1NamespacedPod({
47+
path: { namespace: 'default' }
48+
});
49+
50+
if (result.items && result.items.length) {
51+
result.items.forEach(item => {
52+
console.log('NODE:', item.spec.nodeName);
53+
54+
const initContainers = item.status.initContainerStatuses?.map(ic => ({
55+
image: ic.image,
56+
name: ic.name,
57+
ready: ic.ready,
58+
state: ic.state
59+
}));
60+
61+
const containers = item.status.containerStatuses?.map(c => ({
62+
image: c.image,
63+
name: c.name,
64+
ready: c.ready,
65+
state: c.state
66+
}));
67+
68+
console.log({ containers });
69+
console.log({ initContainers });
70+
});
71+
}
72+
```
73+
74+
## Related
75+
76+
Checkout these related projects:
77+
78+
* [`schema-typescript`](https://github.com/hyperweb-io/schema-typescript/tree/main/packages/schema-typescript)
79+
Provides robust tools for handling JSON schemas and converting them to TypeScript interfaces with ease and efficiency.
80+
* [`@schema-typescript/cli`](https://github.com/hyperweb-io/schema-typescript/tree/main/packages/cli)
81+
CLI is the command line utility for `schema-typescript`.
82+
* [`schema-sdk`](https://github.com/hyperweb-io/schema-typescript/tree/main/packages/schema-sdk)
83+
Provides robust tools for handling OpenAPI schemas and converting them to TypeScript clients with ease and efficiency.
84+
* [`starship`](https://github.com/hyperweb-io/starship) Unified Testing and Development for the Interchain.
85+
86+
## Credits
87+
88+
🛠 Built by Hyperweb — if you like our tools, please checkout and contribute to [our github ⚛️](https://github.com/hyperweb-io)
89+
90+
## Disclaimer
91+
92+
AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED “AS IS”, AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
93+
94+
No developer or entity involved in creating this software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the code, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.

packages/react/jest.config.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/** @type {import('ts-jest').JestConfigWithTsJest} */
2+
module.exports = {
3+
preset: "ts-jest",
4+
testEnvironment: "node",
5+
transform: {
6+
"^.+\\.tsx?$": [
7+
"ts-jest",
8+
{
9+
babelConfig: false,
10+
tsconfig: "tsconfig.json",
11+
},
12+
],
13+
},
14+
transformIgnorePatterns: [`/node_modules/*`],
15+
testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
16+
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
17+
modulePathIgnorePatterns: ["dist/*"]
18+
};

packages/react/package.json

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"name": "@kubernetesjs/react",
3+
"version": "0.6.0",
4+
"author": "Dan Lynch <[email protected]>",
5+
"description": "Fully Typed Kubernetes React Hooks",
6+
"keywords": [
7+
"kubernetes",
8+
"k8s",
9+
"typescript",
10+
"api",
11+
"client",
12+
"sdk",
13+
"container",
14+
"orchestration",
15+
"devops",
16+
"cloud-native",
17+
"openapi",
18+
"swagger"
19+
],
20+
"main": "index.js",
21+
"module": "esm/index.js",
22+
"types": "index.d.ts",
23+
"homepage": "https://github.com/hyperweb-io/kubernetesjs",
24+
"license": "SEE LICENSE IN LICENSE",
25+
"publishConfig": {
26+
"access": "public",
27+
"directory": "dist"
28+
},
29+
"repository": {
30+
"type": "git",
31+
"url": "https://github.com/hyperweb-io/kubernetesjs"
32+
},
33+
"bugs": {
34+
"url": "https://github.com/hyperweb-io/kubernetesjs/issues"
35+
},
36+
"scripts": {
37+
"copy": "copyfiles -f ../../LICENSE README.md package.json dist",
38+
"clean": "rimraf dist/**",
39+
"prepare": "npm run build",
40+
"build": "npm run clean; tsc; tsc -p tsconfig.esm.json; npm run copy",
41+
"build:dev": "npm run clean; tsc --declarationMap; tsc -p tsconfig.esm.json; npm run copy",
42+
"lint": "eslint . --fix",
43+
"dev": "ts-node ./test/test.ts",
44+
"deploy": "ts-node ./test/deployment.ts",
45+
"codegen": "ts-node ./scripts/codegen.ts",
46+
"test": "jest",
47+
"test:watch": "jest --watch",
48+
"test:teardown": "ts-node scripts/teardown.ts",
49+
"test:list": "ts-node scripts/list.ts",
50+
"test:deploy": "ts-node scripts/deploy.ts"
51+
},
52+
"dependencies": {
53+
"react": "^18.2.0",
54+
"@tanstack/react-query": "^5.56.1",
55+
"kubernetesjs": "^0.6.0"
56+
},
57+
"devDependencies": {
58+
"@types/react": "^18.2.77",
59+
"schema-sdk": "^0.11.3",
60+
"react": "^18.2.0"
61+
}
62+
}

packages/react/scripts/codegen.ts

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import { writeFileSync } from 'fs';
2+
import { getDefaultSchemaSDKOptions, generateOpenApiClient, generateReactQueryHooks, generateContext} from 'schema-sdk';
3+
import schema from './swagger.json';
4+
5+
const options = getDefaultSchemaSDKOptions({
6+
includePropertyComments: true,
7+
clientName: 'KubernetesClient',
8+
includeSwaggerUrl: true,
9+
exclude: [
10+
'*.v1beta1.*',
11+
'*.v2beta1.*',
12+
'io.k8s.api.events.v1.EventSeries',
13+
'io.k8s.api.events.v1.Event',
14+
'io.k8s.api.flowcontrol*',
15+
],
16+
});
17+
const openApiOptions = {
18+
...options,
19+
npmApiClient: './client',
20+
operationNamingStrategy: {
21+
aliases: {
22+
listCoreV1PodForAllNamespaces: 'getPods',
23+
},
24+
renameMap: {
25+
listCoreV1PodForAllNamespaces: 'listPods',
26+
},
27+
},
28+
paths: {
29+
exclude: ['*flowschema*', '*v1beta1*', '*v2beta1*'],
30+
excludeRequests: ['head', 'options'],
31+
excludeTags: [
32+
'storage_v1beta1',
33+
'*v1beta1',
34+
'*v2beta1',
35+
'*v1beta1*',
36+
'*v2beta1*',
37+
],
38+
},
39+
includeTypeComments: true,
40+
includeMethodComments: true,
41+
mergedParams: false,
42+
namingStrategy: {
43+
useLastSegment: true,
44+
renameMap: {
45+
'io.k8s.api.discovery.v1.EndpointPort': 'DiscoveryEndpointPort',
46+
'io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.ServiceReference':
47+
'ApiExtServiceReference',
48+
'io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.WebhookClientConfig':
49+
'ApiExtWebhookClientConfig',
50+
'io.k8s.api.admissionregistration.v1.ServiceReference':
51+
'AdmissionServiceReference',
52+
},
53+
},
54+
};
55+
56+
// const code = generateOpenApiClient(
57+
// openApiOptions,
58+
// schema as any
59+
// );
60+
// writeFileSync(
61+
// __dirname + '/../src/index.ts',
62+
// code
63+
// );
64+
65+
const contextCode = generateContext(
66+
'Kubernetes',
67+
'kubernetesjs'
68+
);
69+
writeFileSync(__dirname + '/../src/context.tsx', contextCode);
70+
71+
const reactQueryHooks = generateReactQueryHooks(
72+
{...openApiOptions,
73+
hooks: {
74+
enabled: true,
75+
contextHookName: 'useKubernetes',
76+
contextImportPath: './context',
77+
typesImportPath: 'kubernetesjs',
78+
}
79+
},
80+
schema as any
81+
);
82+
writeFileSync(__dirname + '/../src/index.ts', reactQueryHooks);

0 commit comments

Comments
 (0)