Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,19 @@ kind: Configuration
metadata:
name: crossplane-configuration-template-typescript
spec:
package: ghcr.io/crossplane/configuration-template-typescript:v0.2.1
package: ghcr.io/crossplane/configuration-template-typescript:v0.3.0
```

Once installed, confirm that the package and dependencies are installed:

```shell
$ kubectl get pkg
NAME INSTALLED HEALTHY PACKAGE AGE
configuration.pkg.crossplane.io/crossplane-configuration-template-typescript True True ghcr.io/crossplane/configuration-template-typescript:v0.2.1 49m
configuration.pkg.crossplane.io/crossplane-configuration-template-typescript True True ghcr.io/crossplane/configuration-template-typescript:v0.3.0 49m

NAME INSTALLED HEALTHY PACKAGE AGE
function.pkg.crossplane.io/crossplane-contrib-function-auto-ready True True xpkg.upbound.io/crossplane-contrib/function-auto-ready:v0.6.0 48m
function.pkg.crossplane.io/crossplane-function-template-typescript True True ghcr.io/crossplane/function-template-typescript:v0.2.1 49m
function.pkg.crossplane.io/crossplane-function-template-typescript True True ghcr.io/crossplane/function-template-typescript:v0.3.0 49m
```

### Deploy the Example Manifest
Expand Down Expand Up @@ -335,8 +335,8 @@ packed into a Function Package:
```shell
$ tree _build/docker_images
_build/docker_images
├── function-template-typescript-runtime-amd64-v0.2.1.tar
└── function-template-typescript-runtime-arm64-v0.2.1.tar
├── function-template-typescript-runtime-amd64-v0.3.0.tar
└── function-template-typescript-runtime-arm64-v0.3.0.tar
```

The Dockerfile uses a multi-stage build:
Expand Down Expand Up @@ -372,8 +372,8 @@ the `_build/xpkg` directory:
```shell
$ tree _build/xpkg
_build/xpkg
├── function-template-typescript-amd64-v0.2.1.xpkg
└── function-template-typescript-arm64-v0.2.1.xpkg
├── function-template-typescript-amd64-v0.3.0.xpkg
└── function-template-typescript-arm64-v0.3.0.xpkg
```

These packages can be pushed to any Docker Registry using `crossplane xpkg push`. Update the `XPKG_REPO` in the [env](env)
Expand Down Expand Up @@ -412,7 +412,7 @@ spec:
- apiVersion: pkg.crossplane.io/v1
kind: Function
package: ghcr.io/crossplane/function-template-typescript
version: '>=v0.2.1'
version: '>=v0.3.0'
```

A Crossplane Composition requires a `CompositeResourceDefinition` (XRD) and `Composite`. These
Expand Down Expand Up @@ -451,9 +451,9 @@ images and the Configuration package image:
```shell
$ tree _build/xpkg
_build/xpkg
├── configuration-template-typescript-v0.2.1.xpkg
├── function-template-typescript-amd64-v0.2.1.xpkg
└── function-template-typescript-arm64-v0.2.1.xpkg
├── configuration-template-typescript-v0.3.0.xpkg
├── function-template-typescript-amd64-v0.3.0.xpkg
└── function-template-typescript-arm64-v0.3.0.xpkg
```

Push this package to a Docker registry:
Expand Down Expand Up @@ -489,7 +489,8 @@ The SDK provides helper functions for working with Crossplane resources:
- `getObservedComposedResources(req)` - Get observed composed resources
- `getDesiredComposedResources(req)` - Get desired composed resources
- `setDesiredComposedResources(rsp, resources)` - Set desired composed resources
- `Resource.fromJSON()` - Create resources from JSON
- `fromModel(model)` - Convert a Kubernetes model to a Crossplane Resource (added in SDK v0.4.0)
- `Resource.fromJSON()` - Create resources from JSON (legacy method, use `fromModel` for kubernetes-models)
- `normal(rsp, message)` - Add a normal condition to the response
- `fatal(rsp, message)` - Add a fatal condition to the response
- `to(req)` - Create a minimal response from a request
Expand Down Expand Up @@ -525,6 +526,7 @@ desiredComposed['my-config'] = resource;
The template includes [kubernetes-models](https://github.com/tommy351/kubernetes-models-ts) for type-safe K8s resource creation:

```typescript
import { fromModel } from '@crossplane-org/function-sdk-typescript';
import { Pod } from 'kubernetes-models/v1';

const pod = new Pod({
Expand All @@ -544,9 +546,12 @@ const pod = new Pod({

pod.validate(); // Validate the resource

desiredComposed['my-pod'] = Resource.fromJSON({ resource: pod.toJSON() });
// Use fromModel to convert kubernetes-models to Crossplane Resources
desiredComposed['my-pod'] = fromModel(pod);
```

**Note**: As of SDK v0.4.0, the `fromModel` helper function provides a cleaner way to convert kubernetes-models objects to Crossplane Resources. The legacy approach using `Resource.fromJSON({ resource: pod.toJSON() })` is still supported but `fromModel` is now the recommended method.

### Testing Your Function

Create YAML test cases in the [test-cases/](test-cases/) directory. Each test case defines:
Expand Down Expand Up @@ -643,7 +648,7 @@ Manual workflow for creating Git tags:

### Production Dependencies

- `@crossplane-org/function-sdk-typescript` - Crossplane function SDK
- `@crossplane-org/function-sdk-typescript` - Crossplane function SDK (v0.4.0+ includes `fromModel` helper)
- `commander` - CLI argument parsing
- `pino` - Structured logging
- `kubernetes-models` - Type-safe Kubernetes resource models
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "function-template-typescript",
"version": "0.2.1",
"version": "0.3.0",
"description": "Template for Crossplane function in Typescript",
"keywords": [
"crossplane",
Expand Down