@r8s/flux-controller 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +180 -0
- package/package.json +39 -0
package/README.md
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
# r8s FluxCD Controller
|
|
2
|
+
|
|
3
|
+
A FluxCD source controller that renders r8s TSX manifests directly to YAML.
|
|
4
|
+
|
|
5
|
+
## How It Works
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
Git Repository (.tsx files)
|
|
9
|
+
↓
|
|
10
|
+
Flux GitRepository (clones to /data)
|
|
11
|
+
↓
|
|
12
|
+
r8s-controller (renders TSX → YAML)
|
|
13
|
+
↓
|
|
14
|
+
Flux Kustomization (applies rendered YAML)
|
|
15
|
+
↓
|
|
16
|
+
Kubernetes
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
### 1. Install the controller as a Flux Kustomization
|
|
22
|
+
|
|
23
|
+
```yaml
|
|
24
|
+
# flux-system/r8s-controller.yaml
|
|
25
|
+
apiVersion: source.toolkit.fluxcd.io/v1
|
|
26
|
+
kind: GitRepository
|
|
27
|
+
metadata:
|
|
28
|
+
name: r8s-manifests
|
|
29
|
+
namespace: flux-system
|
|
30
|
+
spec:
|
|
31
|
+
interval: 1m
|
|
32
|
+
url: https://github.com/your-org/your-repo
|
|
33
|
+
ref:
|
|
34
|
+
branch: main
|
|
35
|
+
---
|
|
36
|
+
apiVersion: kustomize.toolkit.fluxcd.io/v1
|
|
37
|
+
kind: Kustomization
|
|
38
|
+
metadata:
|
|
39
|
+
name: r8s-rendered
|
|
40
|
+
namespace: flux-system
|
|
41
|
+
spec:
|
|
42
|
+
interval: 10m
|
|
43
|
+
path: ./rendered
|
|
44
|
+
prune: true
|
|
45
|
+
sourceRef:
|
|
46
|
+
kind: GitRepository
|
|
47
|
+
name: r8s-manifests
|
|
48
|
+
postBuild:
|
|
49
|
+
substituteFrom:
|
|
50
|
+
- kind: ConfigMap
|
|
51
|
+
name: cluster-vars
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### 2. Add the r8s-controller as an init container
|
|
55
|
+
|
|
56
|
+
```yaml
|
|
57
|
+
# patch the source-controller deployment
|
|
58
|
+
apiVersion: apps/v1
|
|
59
|
+
kind: Deployment
|
|
60
|
+
metadata:
|
|
61
|
+
name: source-controller
|
|
62
|
+
namespace: flux-system
|
|
63
|
+
spec:
|
|
64
|
+
template:
|
|
65
|
+
spec:
|
|
66
|
+
initContainers:
|
|
67
|
+
- name: r8s-render
|
|
68
|
+
image: ghcr.io/r8s-io/flux-controller:latest
|
|
69
|
+
command:
|
|
70
|
+
- r8s-controller
|
|
71
|
+
- --source=/data
|
|
72
|
+
- --output=/data/rendered
|
|
73
|
+
- --verbose
|
|
74
|
+
volumeMounts:
|
|
75
|
+
- name: data
|
|
76
|
+
mountPath: /data
|
|
77
|
+
containers:
|
|
78
|
+
- name: manager
|
|
79
|
+
volumeMounts:
|
|
80
|
+
- name: data
|
|
81
|
+
mountPath: /data
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Repository Structure
|
|
85
|
+
|
|
86
|
+
Your Git repository should look like this:
|
|
87
|
+
|
|
88
|
+
```
|
|
89
|
+
.
|
|
90
|
+
├── apps/
|
|
91
|
+
│ ├── web/
|
|
92
|
+
│ │ └── r8s.tsx # Entry file
|
|
93
|
+
│ └── api/
|
|
94
|
+
│ └── r8s.tsx # Entry file
|
|
95
|
+
├── infrastructure/
|
|
96
|
+
│ ├── databases/
|
|
97
|
+
│ │ └── r8s.tsx
|
|
98
|
+
│ └── ingress/
|
|
99
|
+
│ └── r8s.tsx
|
|
100
|
+
└── package.json # With @r8s/* dependencies
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Example r8s.tsx
|
|
104
|
+
|
|
105
|
+
```tsx
|
|
106
|
+
import { Database } from '@r8s/recipes';
|
|
107
|
+
import { Ingress } from '@r8s/recipes';
|
|
108
|
+
import { WebService } from '@r8s/recipes';
|
|
109
|
+
|
|
110
|
+
export default function WebApp() {
|
|
111
|
+
return (
|
|
112
|
+
<>
|
|
113
|
+
<Database name="web-db" storage="10Gi" />
|
|
114
|
+
<WebService name="web" image="myapp/web:v1" port={3000} />
|
|
115
|
+
<Ingress
|
|
116
|
+
name="web"
|
|
117
|
+
host="app.example.com"
|
|
118
|
+
serviceName="web"
|
|
119
|
+
tls={{ secretName: "web-tls", clusterIssuer: "letsencrypt" }}
|
|
120
|
+
/>
|
|
121
|
+
</>
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Local Development
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
# Render locally
|
|
130
|
+
npx r8s-controller --source=./k8s --output=./rendered --verbose
|
|
131
|
+
|
|
132
|
+
# The rendered YAML will be in ./rendered/
|
|
133
|
+
ls rendered/
|
|
134
|
+
# apps/web/r8s.yaml
|
|
135
|
+
# apps/api/r8s.yaml
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## How It Works with Flux
|
|
139
|
+
|
|
140
|
+
1. **GitRepository** clones your repo to `/data`
|
|
141
|
+
2. **Init container** runs before the source-controller starts
|
|
142
|
+
3. **r8s-controller** finds all `r8s.tsx` files and renders them
|
|
143
|
+
4. Rendered YAML is written to `/data/rendered/`
|
|
144
|
+
5. **Kustomization** reads from `./rendered/` path
|
|
145
|
+
6. Kubernetes resources are applied
|
|
146
|
+
|
|
147
|
+
## Benefits
|
|
148
|
+
|
|
149
|
+
- **No build step in CI** — rendering happens in-cluster
|
|
150
|
+
- **Git is still source of truth** — your `.tsx` files are versioned
|
|
151
|
+
- **Automatic updates** — Flux watches git and re-renders on changes
|
|
152
|
+
- **Type safety** — catch errors at build time, not deploy time
|
|
153
|
+
- **DRY** — reuse components across environments
|
|
154
|
+
|
|
155
|
+
## Alternative: Pre-render in CI
|
|
156
|
+
|
|
157
|
+
If you prefer, you can render in CI and commit the YAML:
|
|
158
|
+
|
|
159
|
+
```yaml
|
|
160
|
+
# .github/workflows/render.yml
|
|
161
|
+
name: Render r8s manifests
|
|
162
|
+
on:
|
|
163
|
+
push:
|
|
164
|
+
paths:
|
|
165
|
+
- '**.tsx'
|
|
166
|
+
jobs:
|
|
167
|
+
render:
|
|
168
|
+
runs-on: ubuntu-latest
|
|
169
|
+
steps:
|
|
170
|
+
- uses: actions/checkout@v4
|
|
171
|
+
- uses: actions/setup-node@v4
|
|
172
|
+
- run: npm ci
|
|
173
|
+
- run: npx r8s-controller --source=./k8s --output=./rendered
|
|
174
|
+
- run: |
|
|
175
|
+
git config user.name "github-actions"
|
|
176
|
+
git config user.email "actions@github.com"
|
|
177
|
+
git add rendered/
|
|
178
|
+
git diff --quiet && git diff --staged --quiet || git commit -m "chore: render r8s manifests"
|
|
179
|
+
git push
|
|
180
|
+
```
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@r8s/flux-controller",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "FluxCD source controller for r8s TSX manifests",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Berget AI AB",
|
|
7
|
+
"homepage": "https://r8s.berget.ai",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/berget-ai/r8s.git",
|
|
11
|
+
"directory": "packages/flux-controller"
|
|
12
|
+
},
|
|
13
|
+
"bugs": "https://github.com/berget-ai/r8s/issues",
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"main": "./dist/index.js",
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"bin": {
|
|
23
|
+
"r8s-controller": "./dist/controller.js"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsc --build",
|
|
27
|
+
"test": "vitest run",
|
|
28
|
+
"clean": "rm -rf dist tsconfig.tsbuildinfo"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@r8s/core": "^0.1.0",
|
|
32
|
+
"@r8s/k8s-types": "^0.1.0",
|
|
33
|
+
"tsx": "^4.0.0"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"typescript": "^5.3.0",
|
|
37
|
+
"vitest": "^1.0.0"
|
|
38
|
+
}
|
|
39
|
+
}
|