-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
da877f9
commit 832a703
Showing
106 changed files
with
11,343 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import type { ConfigFile } from '@kubekit/codegen' | ||
|
||
const config: ConfigFile = { | ||
schemaFile: '../openapi/api/v1/swagger.json', | ||
apiFile: '@kubekit/client', | ||
outputFile: '../src/generated/k8s-client/api-v1.ts', | ||
} | ||
|
||
export default config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import type { ConfigFile } from '@kubekit/codegen' | ||
|
||
const config: ConfigFile = { | ||
schemaFile: | ||
'../openapi/apis/storage.k8s.io/v1/swagger.json', | ||
apiFile: '@kubekit/client', | ||
outputFile: '../src/generated/k8s-client/apis-storage-k8s-io-v1.ts', | ||
} | ||
|
||
export default config |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"name": "next.js", | ||
"version": "0.1.0", | ||
"private": true, | ||
"scripts": { | ||
"dev": "next dev", | ||
"build": "next build", | ||
"start": "next start", | ||
"lint": "next lint", | ||
"import": "npx @kubekit/import ./", | ||
"gen": "npx @kubekit/codegen gen-config/storage-config.ts && npx @kubekit/codegen gen-config/core-v1-config.ts" | ||
}, | ||
"dependencies": { | ||
"@kubekit/client": "^0.0.3", | ||
"next": "^14.2.0-canary.23", | ||
"react": "^18", | ||
"react-dom": "^18" | ||
}, | ||
"devDependencies": { | ||
"@kubekit/codegen": "^0.0.2", | ||
"@kubekit/import": "^0.0.2", | ||
"@types/node": "^20", | ||
"@types/react": "^18", | ||
"@types/react-dom": "^18", | ||
"autoprefixer": "^10.0.1", | ||
"esbuild-runner": "^2.2.2", | ||
"eslint": "^8", | ||
"eslint-config-next": "14.1.3", | ||
"postcss": "^8", | ||
"tailwindcss": "^3.3.0", | ||
"typescript": "^5" | ||
} | ||
} |
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { listCoreV1PodForAllNamespaces } from "@/generated/k8s-client/api-v1"; | ||
|
||
export default async function Home() { | ||
const pods = await listCoreV1PodForAllNamespaces({}) | ||
return ( | ||
<main> | ||
<ul> | ||
{pods.items.map((pod, i) => <li key={i}>{pod.metadata!.name}</li>)} | ||
</ul> | ||
</main> | ||
); | ||
} |
File renamed without changes.
File renamed without changes.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import type { ConfigFile } from '@kubekit/codegen' | ||
|
||
const config: ConfigFile = { | ||
schemaFile: '../openapi/api/v1/swagger.json', | ||
apiFile: '@kubekit/client', | ||
outputFile: '../generated/k8s-client/api-v1.ts', | ||
} | ||
|
||
export default config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import type { ConfigFile } from '@kubekit/codegen' | ||
|
||
const config: ConfigFile = { | ||
schemaFile: | ||
'../openapi/apis/storage.k8s.io/v1/swagger.json', | ||
apiFile: '@kubekit/client', | ||
outputFile: '../generated/k8s-client/apis-storage-k8s-io-v1.ts', | ||
} | ||
|
||
export default config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "basic-usage", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"directories": { | ||
"test": "tests" | ||
}, | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"import": "npx @kubekit/import ./", | ||
"gen": "npx @kubekit/codegen gen-config/storage-config.ts && npx @kubekit/codegen gen-config/core-v1-config.ts", | ||
"dev": "npx tsx src/main.ts" | ||
}, | ||
"author": "", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@kubekit/client": "0.0.3" | ||
}, | ||
"devDependencies": { | ||
"@kubekit/codegen": "^0.0.2", | ||
"@kubekit/import": "^0.0.2", | ||
"esbuild-runner": "^2.2.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { parse, stringify } from 'https://deno.land/std/yaml/mod.ts' | ||
import { existsSync } from 'https://deno.land/std/fs/mod.ts' | ||
|
||
type Env = { | ||
name: string | ||
value: string | ||
} | ||
|
||
type User = { | ||
exec?: { | ||
apiVersion: string | ||
args: string[] | ||
command: string | ||
env?: Env[] | ||
} | ||
} | ||
|
||
type KubeConfig = { | ||
users: { name: string; user: User }[] | ||
} | ||
|
||
const defaultKubeConfigPath = Deno.env.get('HOME') + '/.kube/config' | ||
|
||
const kubeConfigPath = Deno.env.get('KUBECONFIG') || defaultKubeConfigPath | ||
if (existsSync(kubeConfigPath)) { | ||
const kubeConfig = parse( | ||
await Deno.readTextFile(kubeConfigPath) | ||
) as KubeConfig | ||
kubeConfig.users.forEach(({ user }) => { | ||
const AWS_PROFILE_ENV = user.exec?.env?.find( | ||
(e) => e.name === 'AWS_PROFILE' | ||
) | ||
const HAS_PROFILE_ARG = user.exec?.args?.find((arg) => arg === '--profile') | ||
if (AWS_PROFILE_ENV && !HAS_PROFILE_ARG) { | ||
user.exec?.args.push('--profile') | ||
user.exec?.args.push(AWS_PROFILE_ENV.value) | ||
} | ||
}) | ||
await Deno.writeTextFile(kubeConfigPath, stringify(kubeConfig)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,200 @@ | ||
import { | ||
createCoreV1NamespacedPod, | ||
deleteCoreV1NamespacedPod, | ||
listCoreV1PodForAllNamespaces, | ||
patchCoreV1NamespacedPod, | ||
patchCoreV1NamespacedPodStatus, | ||
readCoreV1NamespacedPod, | ||
} from '../generated/k8s-client/api-v1' | ||
|
||
// $ kubectl run nginx --image=nginx --restart=Never --dry-run=client -o yaml | ||
// apiVersion: v1 | ||
// kind: Pod | ||
// metadata: | ||
// creationTimestamp: null | ||
// labels: | ||
// run: nginx | ||
// name: nginx | ||
// spec: | ||
// containers: | ||
// - image: nginx | ||
// name: nginx | ||
// dnsPolicy: ClusterFirst | ||
// restartPolicy: Never | ||
|
||
async function main() { | ||
const controller = new AbortController() | ||
|
||
setTimeout(() => controller.abort(), 2000) | ||
|
||
try { | ||
await listCoreV1PodForAllNamespaces( | ||
{ | ||
watch: true, | ||
}, | ||
{ | ||
watchEventHandler: console.log, | ||
signal: controller.signal | ||
} | ||
) | ||
} catch (e) { | ||
if (e.name !== "AbortError") { | ||
throw e | ||
} | ||
} | ||
await listCoreV1PodForAllNamespaces({ | ||
watch: false, | ||
}) | ||
|
||
await createCoreV1NamespacedPod({ | ||
namespace: 'default', | ||
body: { | ||
metadata: { | ||
name: 'test', | ||
namespace: 'default', | ||
}, | ||
spec: { | ||
containers: [{ name: 'nginx', image: 'nginx' }], | ||
dnsPolicy: 'ClusterFirst', | ||
restartPolicy: 'Never', | ||
}, | ||
status: { | ||
phase: 'Unknown', | ||
}, | ||
}, | ||
}) | ||
|
||
await patchCoreV1NamespacedPod({ | ||
namespace: 'default', | ||
name: 'test', | ||
contentType: 'application/strategic-merge-patch+json', | ||
body: { | ||
metadata: { | ||
annotations: { | ||
patch: 'true', | ||
}, | ||
}, | ||
}, | ||
fieldManager: 'client-side-apply', | ||
fieldValidation: 'Strict', | ||
}) | ||
|
||
await patchCoreV1NamespacedPod({ | ||
namespace: 'default', | ||
name: 'test', | ||
contentType: 'application/json-patch+json', | ||
body: [ | ||
{ op: 'add', path: '/metadata/annotations/testpatch', value: 'success' }, | ||
], | ||
fieldManager: 'json-patch', | ||
}) | ||
|
||
await deleteCoreV1NamespacedPod({ | ||
name: 'test', | ||
namespace: 'default', | ||
body: {}, | ||
}) | ||
|
||
await patchCoreV1NamespacedPod({ | ||
namespace: 'default', | ||
name: 'nginx', | ||
fieldManager: 'server-side-apply', | ||
fieldValidation: 'Strict', | ||
contentType: 'application/apply-patch+yaml', | ||
body: { | ||
apiVersion: 'v1', | ||
kind: 'Pod', | ||
metadata: { | ||
labels: { | ||
run: 'nginx', | ||
}, | ||
name: 'nginx', | ||
namespace: 'default', | ||
}, | ||
spec: { | ||
containers: [ | ||
{ | ||
image: 'nginx', | ||
name: 'nginx', | ||
resources: {}, | ||
}, | ||
], | ||
dnsPolicy: 'ClusterFirst', | ||
restartPolicy: 'Never', | ||
}, | ||
status: {}, | ||
}, | ||
}) | ||
|
||
await readCoreV1NamespacedPod({ | ||
name: 'nginx', | ||
namespace: 'default', | ||
}) | ||
|
||
await patchCoreV1NamespacedPodStatus({ | ||
name: 'nginx', | ||
namespace: 'default', | ||
fieldManager: 'kahiro', | ||
contentType: 'application/apply-patch+yaml', | ||
body: { | ||
apiVersion: 'v1', | ||
kind: 'Pod', | ||
status: { | ||
phase: 'Failed', | ||
}, | ||
}, | ||
}) | ||
|
||
// await wait(async () => { | ||
// const res = await readCoreV1NamespacedPod({ | ||
// name: 'nginx', | ||
// namespace: 'default', | ||
// }) | ||
// if ( | ||
// !res.status?.conditions?.find( | ||
// (c) => c.type === 'Ready' && c.status === 'True' | ||
// ) | ||
// ) { | ||
// return retry | ||
// } | ||
|
||
// return res | ||
// }) | ||
|
||
await deleteCoreV1NamespacedPod({ | ||
name: 'nginx', | ||
namespace: 'default', | ||
body: {}, | ||
}) | ||
|
||
console.info('Successfully') | ||
} | ||
main() | ||
|
||
type Executor<T> = (params: ExecutorParams) => Promise<Retry | T> | ||
type ExecutorParams = { retry: Retry } | ||
const retry = Symbol() | ||
type Retry = typeof retry | ||
|
||
async function wait<T>( | ||
executor: Executor<T>, | ||
{ interval = 500, timeout = 5000 } = {} | ||
): Promise<T> { | ||
const startTime = Date.now() | ||
|
||
while (true) { | ||
const elapsed = Date.now() - startTime | ||
|
||
if (elapsed > timeout) { | ||
throw new Error('Timeout reached') | ||
} | ||
|
||
const result = await executor({ retry }) | ||
|
||
if (result !== retry) { | ||
return result | ||
} | ||
|
||
await new Promise((r) => setTimeout(r, interval)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "next/core-web-vitals" | ||
} |
Oops, something went wrong.