nestjs-k8s-operator
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

NestJS K8s Operator Module

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

  1. Register in app.module
@Module({
  imports: [
    KubernetesOperatorModule.forRootAsync(KubernetesOperatorModule, {
      useFactory: () => {
        return {
          enabled: true,
        };
      },
    }),
  ],
})
export class AppModule implements NestModule {
  configure(consumer: MiddlewareConsumer) {}
}
  1. 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();
  1. 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>) {}
}
  1. Profit

Package Sidebar

Install

npm i nestjs-k8s-operator

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

53.2 kB

Total Files

35

Last publish

Collaborators

  • tjaybroodryk