Skip to content

Latest commit

 

History

History
471 lines (287 loc) · 13.9 KB

API.md

File metadata and controls

471 lines (287 loc) · 13.9 KB

API Reference

Constructs

Operator

A CDK8s app which allows implementing Kubernetes operators using CDK8s constructs.

Initializers

import { Operator } from 'cdk8s-operator'

new Operator(props?: OperatorProps)
Name Type Description
props OperatorProps No description.

propsOptional

Methods

Name Description
toString Returns a string representation of this construct.
synth Reads a Kubernetes manifest in JSON format from STDIN or the file specified as the first positional command-line argument.
synthYaml Synthesizes the app into a YAML string.
addProvider Adds a custom resource provider to this operator.

toString
public toString(): string

Returns a string representation of this construct.

synth
public synth(): void

Reads a Kubernetes manifest in JSON format from STDIN or the file specified as the first positional command-line argument.

This manifest is expected to include a single Kubernetes resource. Then, we match apiVersion and kind to one of the registered providers and if we do, we invoke apply(), passing it the spec of the input manifest and a chart as a scope. The chart is then synthesized and the output manifest is written to STDOUT.

synthYaml
public synthYaml(): string

Synthesizes the app into a YAML string.

addProvider
public addProvider(provider: CustomResourceProvider): void

Adds a custom resource provider to this operator.

providerRequired

The provider to add.


Static Functions

Name Description
isConstruct Checks if x is a construct.
of No description.

isConstruct
import { Operator } from 'cdk8s-operator'

Operator.isConstruct(x: any)

Checks if x is a construct.

Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.

xRequired
  • Type: any

Any object.


of
import { Operator } from 'cdk8s-operator'

Operator.of(c: IConstruct)
cRequired
  • Type: constructs.IConstruct

Properties

Name Type Description
node constructs.Node The tree node.
charts cdk8s.Chart[] Returns all the charts in this app, sorted topologically.
outdir string The output directory into which manifests will be synthesized.
outputFileExtension string The file extension to use for rendered YAML files.
resolvers cdk8s.IResolver[] Resolvers used by this app.
yamlOutputType cdk8s.YamlOutputType How to divide the YAML output into files.

nodeRequired
public readonly node: Node;
  • Type: constructs.Node

The tree node.


chartsRequired
public readonly charts: Chart[];
  • Type: cdk8s.Chart[]

Returns all the charts in this app, sorted topologically.


outdirRequired
public readonly outdir: string;
  • Type: string

The output directory into which manifests will be synthesized.


outputFileExtensionRequired
public readonly outputFileExtension: string;
  • Type: string
  • Default: .k8s.yaml

The file extension to use for rendered YAML files.


resolversRequired
public readonly resolvers: IResolver[];
  • Type: cdk8s.IResolver[]

Resolvers used by this app.

This includes both custom resolvers passed by the resolvers property, as well as built-in resolvers.


yamlOutputTypeRequired
public readonly yamlOutputType: YamlOutputType;
  • Type: cdk8s.YamlOutputType
  • Default: YamlOutputType.FILE_PER_CHART

How to divide the YAML output into files.


Structs

CustomResourceProvider

Initializer

import { CustomResourceProvider } from 'cdk8s-operator'

const customResourceProvider: CustomResourceProvider = { ... }

Properties

Name Type Description
apiVersion string API version of the custom resource.
handler ICustomResourceProviderHandler The construct handler.
kind string Kind of this custom resource.

apiVersionRequired
public readonly apiVersion: string;
  • Type: string
  • Default: "v1"

API version of the custom resource.


handlerRequired
public readonly handler: ICustomResourceProviderHandler;

The construct handler.


kindRequired
public readonly kind: string;
  • Type: string

Kind of this custom resource.


OperatorProps

Initializer

import { OperatorProps } from 'cdk8s-operator'

const operatorProps: OperatorProps = { ... }

Properties

Name Type Description
inputFile string A Kubernetes JSON manifest with a single resource that is matched against one of the providers within this operator.
outputFile string Where to write the synthesized output.

inputFileOptional
public readonly inputFile: string;
  • Type: string
  • Default: first position command-line argument or "/dev/stdin"

A Kubernetes JSON manifest with a single resource that is matched against one of the providers within this operator.


outputFileOptional
public readonly outputFile: string;
  • Type: string
  • Default: "/dev/stdout"

Where to write the synthesized output.


ServerProps

Initializer

import { ServerProps } from 'cdk8s-operator'

const serverProps: ServerProps = { ... }

Properties

Name Type Description
appCommand string The command to execute in order to synthesize the CDK app.

appCommandRequired
public readonly appCommand: string;
  • Type: string

The command to execute in order to synthesize the CDK app.


Classes

Server

Initializers

import { Server } from 'cdk8s-operator'

new Server(props: ServerProps)
Name Type Description
props ServerProps No description.

propsRequired

Methods

Name Description
close Stop server.
listen Starts HTTP server.

close
public close(): void

Stop server.

listen
public listen(port?: number): number

Starts HTTP server.

portOptional
  • Type: number

The port to listen to.

If not specified, the PORT environment variable will be used. If that's not specified an available port will be auto-selected.


Protocols

ICustomResourceProviderHandler

The handler for this custom resource provider.

Methods

Name Description
apply No description.

apply
public apply(scope: Construct, id: string, spec: any): Construct
scopeRequired
  • Type: constructs.Construct

idRequired
  • Type: string

specRequired
  • Type: any