22
33This guide will walk you through developing a KPT function using the Typescript SDK.
44
5- ## Prerequisites
5+ <!-- toc -->
6+
7+ - [ Setup] ( #setup )
8+ - [ Create the NPM package] ( #create-the-npm-package )
9+ - [ Implement the function] ( #implement-the-function )
10+ - [ Build and push Docker image] ( #build-and-push-docker-image )
11+ - [ Use the SDK CLI] ( #use-the-sdk-cli )
12+ - [ Next Steps] ( #next-steps )
13+
14+ <!-- tocstop -->
15+
16+ ## Setup
617
718### System Requirements
819
@@ -92,9 +103,9 @@ gcloud container clusters get-credentials $USER-1-14-alpha --zone us-central1-a
92103
93104### Working with CRDs
94105
106+ The SDK uses the k8s server to generate the typescript classes.
95107If your function uses a Custom Resource Definition, make sure you apply it to the cluster before
96- generating the SDK. Typescript uses the k8s server to generate the types represented there,
97- including your CRD.
108+ generating the SDK.
98109
99110```sh
100111kubectl apply -f /path/to/my/crd.yaml
@@ -105,8 +116,8 @@ kubectl apply -f /path/to/my/crd.yaml
105116To initialize a new NPM package, first create a package directory:
106117
107118```sh
108- mkdir < my-package>
109- cd < my-package>
119+ mkdir my-package
120+ cd my-package
110121```
111122
112123> **Note:** All subsequent commands are run from the `my-package/` directory.
@@ -133,13 +144,13 @@ This process will create the following:
133144 including the `create-kpt-functions` CLI discussed later in the `README`.
1341451. `src/`: Directory containing the source files for all your functions, e.g.:
135146
136- - `< my_func.ts> `: Implement your function' s interface here.
137- - ` < my_func_test.ts> ` : Unit tests for your function.
138- - ` < my_func_run.ts> ` : The entry point from which your function is run.
147+ - `my_func.ts`: Implement your function' s interface here.
148+ - ` my_func_test.ts` : Unit tests for your function.
149+ - ` my_func_run.ts` : The entry point from which your function is run.
139150
1401511. ` src/gen/` : Contains Kubernetes core and CRD types generated from the OpenAPI spec published by the cluster you selected.
1411521. ` build/` : Contains Dockerfile for each function, e.g.:
142- - ` < my_func> .Dockerfile`
153+ - ` my_func.Dockerfile`
143154
144155Next, install all package dependencies:
145156
@@ -152,20 +163,20 @@ In addition to installation, `install` compiles your function into the `dist/` d
152163You can run your function directly:
153164
154165` ` ` sh
155- node dist/< my_func_run> .js --help
166+ node dist/my_func_run.js --help
156167` ` `
157168
158169Currently, it simply passes through the input configuration data. Let' s remedy this.
159170
160- ## Implementing the function
171+ ## Implement the function
161172
162173You can now start implementing the function using your favorite IDE, e.g. [VSCode][vscode]:
163174
164175```sh
165176code .
166177```
167178
168- In `src/< my_func> .ts`, implement the `KptFunc` interface [documented here][api-kptfunc].
179+ In `src/my_func.ts`, implement the `KptFunc` interface [documented here][api-kptfunc].
169180
170181Take a look at [these example functions][demo-funcs] to better understand how to use
171182`kpt-functions` library. These functions are available as docker images documented in the [catalog][catalog].
@@ -189,7 +200,7 @@ To run the tests, use:
189200npm test
190201` ` `
191202
192- # # Container images
203+ # # Build and push Docker image
193204
194205With your working function in-hand, it' s time to package your function into an executable docker
195206image.
@@ -230,7 +241,7 @@ npm run kpt:docker-build -- --tag=latest
230241npm run kpt:docker-push -- --tag=latest
231242` ` `
232243
233- # # SDK CLI
244+ # # Use the SDK CLI
234245
235246The ` create-kpt-functions` package (installed as ` devDependencies` ), provides a CLI for managing
236247the NPM package you created above. The CLI sub-commands can be invoked via ` npm run` . For example,
@@ -240,6 +251,8 @@ to add a new function to the package:
240251npm run kpt:function-create -- --help
241252` ` `
242253
254+ > ** Note:** Flags are passed to the CLI after the ` --` separator.
255+
243256These sub-commands are available:
244257
245258` ` ` console
@@ -253,8 +266,6 @@ kpt:type-create Generate classes for core and CRD types. Overwrite
253266 files if they exist.
254267` ` `
255268
256- > ** Note:** Flags are passed to the CLI after the ` --` separator.
257-
258269# # Next Steps
259270
260271- [Running KPT Functions](run.md)
0 commit comments