Skip to content

Commit

Permalink
feat: create nginx-cluster controller with @kubekit/sync examples
Browse files Browse the repository at this point in the history
  • Loading branch information
kahirokunn committed May 17, 2024
1 parent d4dcdcc commit f6f1ad6
Show file tree
Hide file tree
Showing 45 changed files with 128,943 additions and 5,470 deletions.
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
*.log
node_modules
dist*/
packages/kubekit-codegen/lib
packages/kubekit-sync/lib
packages/*/lib
packages/*/dist
examples/*/lib
examples/*/dist
es

.yalc
Expand Down Expand Up @@ -37,4 +39,4 @@ eks-blueprints-add-ons
examples/generate-vercel-client/swagger.json
eks-blueprints-add-ons
openapi
packages/kubekit-prepare/lib
!packages/kubekit-openapi-gen/src/utils/openapi
53 changes: 53 additions & 0 deletions examples/nginx-cluster-controller-with-kubekit-sync/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Node.js + @kubekit/sync + @kubekit/client-gen Example

This example demonstrates how to set up a Node.js application using [@kubekit/sync](../../packages/kubekit-sync) and [@kubekit/client-gen](../../packages/kubekit-client-gen) for managing Kubernetes resources and generating code.

## Prerequisites

- Node.js installed
- Kubernetes cluster (e.g., Minikube, EKS, GKE)
- kubectl configured to interact with your Kubernetes cluster

## Usage

yarn install
kind create cluster -n nodejs-sync
kubectl apply -f config/crds/nginxcluster.yaml

```yaml
cat <<EOF | kubectl apply -f -
apiVersion: kubekit.com/v1
kind: NginxCluster
metadata:
name: my-nginx-cluster1
namespace: default
spec:
replicas: 5
resources:
limits:
cpu: "500m"
memory: "512Mi"
requests:
cpu: "250m"
memory: "256Mi"
---
apiVersion: kubekit.com/v1
kind: NginxCluster
metadata:
name: my-nginx-cluster2
namespace: default
spec:
replicas: 2
resources:
limits:
cpu: "500m"
memory: "512Mi"
requests:
cpu: "250m"
memory: "256Mi"
EOF
```

npm run dev

kind delete cluster -n nodejs-sync
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { ConfigFile } from '@kubekit/client-gen'

const config: ConfigFile = {
schemaFile: '../openapi/apis/coordination.k8s.io/v1/swagger.json',
apiFile: '@kubekit/client',
outputFile: '../src/coordination-v1.ts',
}

export default config
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { ConfigFile } from '@kubekit/client-gen'

const config: ConfigFile = {
schemaFile: '../openapi/api/v1/swagger.json',
apiFile: '@kubekit/client',
outputFile: '../src/core-v1.ts',
}

export default config
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# generated by GPT-4o
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: nginxclusters.kubekit.com
spec:
group: kubekit.com
versions:
- name: v1
served: true
storage: true
subresources:
status: {}
schema:
openAPIV3Schema:
type: object
properties:
spec:
type: object
properties:
replicas:
type: integer
resources:
type: object
properties:
limits:
type: object
properties:
cpu:
type: string
memory:
type: string
requests:
type: object
properties:
cpu:
type: string
memory:
type: string
status:
type: object
properties:
ready:
type: boolean
default: false
default:
ready: false
scope: Namespaced
names:
plural: nginxclusters
singular: nginxcluster
kind: NginxCluster
shortNames:
- nc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { ConfigFile } from '@kubekit/client-gen'

const config: ConfigFile = {
schemaFile: '../openapi/apis/kubekit.com/v1/swagger.json',
apiFile: '@kubekit/client',
outputFile: '../src/kubekit-v1.ts',
}

export default config
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default [
{
plugins: ['autofix'],
rules: {
'autofix/no-unused-vars': 'error',
},
},
]
30 changes: 30 additions & 0 deletions examples/nginx-cluster-controller-with-kubekit-sync/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "nginx-cluster-controller-with-kubekit-sync",
"version": "1.0.0",
"description": "",
"main": "index.js",
"directories": {
"test": "tests"
},
"scripts": {
"sync": "npx @kubekit/sync ./",
"gen": "npm-run-all gen:*",
"gen:core-v1": "npx @kubekit/client-gen config/core-v1.ts",
"gen:kubekit-v1": "npx @kubekit/client-gen config/kubekit-v1.ts",
"gen:coordination-v1": "npx @kubekit/client-gen config/coordination-v1.ts",
"refresh": "kubectl apply -f config/crds/nginxcluster.yaml && npm run sync && npm run gen",
"dev": "npx tsx src/main.ts"
},
"author": "",
"license": "MIT",
"dependencies": {
"@kubekit/client": "0.1.18"
},
"devDependencies": {
"@kubekit/client-gen": "^0.1.0",
"@kubekit/sync": "0.1.3",
"esbuild": "^0.20.2",
"esbuild-runner": "^2.2.2",
"npm-run-all": "^4.1.5"
}
}
Loading

0 comments on commit f6f1ad6

Please sign in to comment.