# nestjs-k8s-operator

> NestJS kubernetes operator module

Latest version **1.0.1** (published 2022-12-26) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install nestjs-k8s-operator
pnpm add nestjs-k8s-operator
yarn add nestjs-k8s-operator
bun add nestjs-k8s-operator
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2022-12-26 |
| First published | 2022-12-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 52 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Maintainers | tjaybroodryk |
| Keywords | nestjs, k8s, kubernetes, operator |

## Links

- npm: https://www.npmjs.com/package/nestjs-k8s-operator
- Repository: https://github.com/tjbroodryk/nestjs-k8s-operator
- Homepage: https://github.com/tjbroodryk/nestjs-k8s-operator#readme
- Issues: https://github.com/tjbroodryk/nestjs-k8s-operator
- npm.io page: https://npm.io/package/nestjs-k8s-operator

## Dependencies (5)

- [zod](https://npm.io/package/zod.md) ^3.20.2
- [type-fest](https://npm.io/package/type-fest.md) ^3.4.0
- [@dot-i/k8s-operator](https://npm.io/package/@dot-i/k8s-operator.md) ^1.2.0
- [@golevelup/nestjs-modules](https://npm.io/package/@golevelup/nestjs-modules.md) ^0.6.1
- [@golevelup/nestjs-discovery](https://npm.io/package/@golevelup/nestjs-discovery.md) ^3.0.0

## Recent versions

- 1.0.1 (latest) — 2022-12-26
- 1.0.0 — 2022-12-25

## README

<h1 align="center"></h1>

<div align="center">
  <a href="http://nestjs.com/" target="_blank">
    <img src="https://nestjs.com/img/logo_text.svg" width="150" alt="Nest Logo" />
  </a>
</div>

<h3 align="center">NestJS K8s Operator Module</h3>

<div align="center">
  <a href="https://nestjs.com" target="_blank">
    <img src="https://img.shields.io/badge/built%20with-NestJs-red.svg" alt="Built with NestJS">
  </a>
</div>

Typesafe, contract-driven kubernetes operator module for a NestJS application.

Uses [zod](https://github.com/colinhacks/zod) object defintions to create typesafe resource watchers, with automatic validation of crds.

### Installation

```bash
npm i nestjs-k8s-operator
```

## Example

1. Register in `app.module`

```typescript
@Module({
  imports: [
    KubernetesOperatorModule.forRootAsync(KubernetesOperatorModule, {
      useFactory: () => {
        return {
          enabled: true,
        };
      },
    }),
  ],
})
export class AppModule implements NestModule {
  configure(consumer: MiddlewareConsumer) {}
}
```

2. Create your crd schema contract

```typescript
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();
```

3. Register your resource watcher

```typescript
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>) {}
}
```

4. Profit

---
_Source: https://npm.io/package/nestjs-k8s-operator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
