1.0.1 • Published 5 years ago

@kube-ops/controller v1.0.1

Weekly downloads
-
License
MIT
Repository
gitlab
Last release
5 years ago

Controller

Example

import Controller from '@kube-ops/controller'
import {
  ResourceAdded,
  ResourceModified,
  ResourceDeleted,
  ErrorEvent
} from '@kube-ops/controller'

const log = async (message) => console.log(message)

class MyController extends Controller {
    protected async init() {
        this.on(ResourceAdded, (meta, object) => log(`Resource added: ${meta.kind}/${meta.name}`))
        this.on(ResourceModified, (meta, object) => log(`Resource updated: ${meta.kind}/${meta.name}`))
        this.on(ResourceDeleted, (meta, object) => console.log(`Resource removed: ${meta.kind}/${meta.name}`))
        this.on(ErrorEvent, (error) => console.error(error))

        this.watch('nodes') // Watch nodes
        this.watch('pods', 'kube-system') // Watch pobs in namespace `kube-system`
        this.watch('jobs', undefined, 'batch/v1') // Watch jobs in all namespaces
        this.watch('jobs', 'myapp1', 'batch/v1') // Watch jobs in namespace `myapp1`
        this.watch('jobs', 'myapp2', 'batch/v1') // Watch jobs in `myapp2`
    }
}

const app = new MyController()
app.start()
1.0.1

5 years ago

1.0.0

5 years ago