# node-auto-repair

> Automatically detect unhealthy Kubernetes nodes and repair them

Latest version **1.1.1** (published 2022-11-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install node-auto-repair
pnpm add node-auto-repair
yarn add node-auto-repair
bun add node-auto-repair
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2022-11-26 |
| First published | 2022-08-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=16.0.0 |
| Dependencies | 2 |
| Unpacked size | 15.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Nicklas Marc Pedersen |
| Maintainers | nicklason |

## Links

- npm: https://www.npmjs.com/package/node-auto-repair
- Repository: https://github.com/Nicklason/node-auto-repair
- Issues: https://github.com/Nicklason/node-auto-repair/issues
- npm.io page: https://npm.io/package/node-auto-repair

## Dependencies (2)

- [p-queue](https://npm.io/package/p-queue.md) ^7.3.0
- [@kubernetes/client-node](https://npm.io/package/@kubernetes/client-node.md) ^0.17.0

## Recent versions

- 1.1.1 (latest) — 2022-11-26
- 1.1.0 — 2022-11-26
- 1.0.2 — 2022-08-21
- 1.0.1 — 2022-08-21
- 1.0.0 — 2022-08-21

## README

# node-auto-repair

Automatically detect unhealthy Kubernetes nodes and repair them.

## Inspiration

Google Kubernetes Engine can [automatically repair unhealthy nodes](https://cloud.google.com/kubernetes-engine/docs/how-to/node-auto-repair) and then replacing them with a new node. This might not be possible when
running Kubernetes on-premise. Instead of replacing the nodes, an attempt to repair
them can be made by first identifying the problem, and then attempting to repair it.

## Usage

The NodeAutoRepair class listens for unhealthy nodes using the Kubernetes API.
When a node becomes unhealthy, it first waits a given period of time and then
checks if the node is still unhealthy. If it is still unhealthy, then a repair
attempt is made. If the node doesn't become healthy after a given period of
time, then another attempt is made. This continues until either the node becomes
healthy, or max repair attempts has been made.

To use NodeAutoRepair, create a class that implements the AutoRepair interface.
The `repair` function is called when a node needs to be repaired. It should find
the problem, and then attempt to fix it. Multiple attempts can be made to fix
the problem. For example, if one fix didn't work, then a different fix could be
tried.

## Example

```ts
import { NodeAutoRepair, AutoRepair } from 'node-auto-repair';

class CustomAutoRepair implements AutoRepair {
  async repair(apiObj: V1Node, attempts: number): Promise<void> {
    console.log(
      'Attempt #' + attempts + ' to repair node ' + apiObj.metadata.name,
    );

    // Do something to repair node
    await findTheProblem();
    await attemptToFixTheProblem();
  }

  repairAttemptFailed(apiObj: V1Node, attempts: number): void {
    console.log(
      'Attempt #' +
        attempts +
        ' to repair node ' +
        apiObj.metadata.name +
        ' failed',
    );
  }

  repairAttemptsFailed(apiObj: V1Node, attempts: number): void {
    console.log(
      'Failed to repair node ' +
        apiObj.metadata.name +
        ' after ' +
        attempts +
        ' attempts',
    );
  }

  repairSuccess(apiObj: V1Node, attempts: number): void {
    console.log(
      'Repaired node ' +
        apiObj.metadata.name +
        ' after ' +
        attempts +
        ' attempts',
    );
  }
}

const NodeAutoRepair = new NodeAutoRepair(new CustomAutoRepair(), {
  kubeConfigPath: 'path/to/kubeconfig',
});

NodeAutoRepair.start();
```

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