nestjs-k8s-operator
v1.0.1
Published
NestJS kubernetes operator module
Downloads
7
Maintainers
Readme
Typesafe, contract-driven kubernetes operator module for a NestJS application.
Uses zod object defintions to create typesafe resource watchers, with automatic validation of crds.
Installation
npm i nestjs-k8s-operator
Example
- Register in
app.module
@Module({
imports: [
KubernetesOperatorModule.forRootAsync(KubernetesOperatorModule, {
useFactory: () => {
return {
enabled: true,
};
},
}),
],
})
export class AppModule implements NestModule {
configure(consumer: MiddlewareConsumer) {}
}
- Create your crd schema contract
const contract = CustomResourceContract.createForOrg('exampleOrg')
.kind('yourResource')
.version('v1', {
spec: z.object({
test: z.string(),
bla: z.string(),
}),
metadata: z.object({
name: z.string(),
}),
})
.build();
- Register your resource watcher
import * as z from 'zod';
import { Injectable } from '@nestjs/common';
import {
CustomResourceContract,
KubernetesOperator,
CustomResource,
KubernetesResourceWatcher,
} from 'nestjs-k8s-operator';
@Injectable()
@KubernetesResourceWatcher(contract, 'foo')
export class ExampleWatcher {
async added(crd: CustomResource<typeof contract.foo>) {}
async modified(crd: CustomResource<typeof contract.foo>) {}
async deleted(crd: CustomResource<typeof contract.foo>) {}
}
- Profit