-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from Avarei/refactor/packages
Restructure packages
- Loading branch information
Showing
36 changed files
with
1,362 additions
and
315 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,61 +35,14 @@ spec: | |
spec: | ||
type: uri | ||
# This pkl file is at `pkl/crossplane-example/full.pkl` in this repo | ||
uri: "package://pkg.pkl-lang.org/github.com/crossplane-contrib/function-pkl/crossplane-example@0.1.19#/full.pkl" | ||
uri: "package://pkg.pkl-lang.org/github.com/crossplane-contrib/function-pkl/crossplane-example@1.0.0#/full.pkl" | ||
``` | ||
### Example | ||
see [examples](./example/) | ||
## Building a Pkl Package | ||
A Pkl Package can be built in the following steps: | ||
1. Create Pkl files in a directory | ||
> Note: you can [convert CRDs and Manifests](#generating-pkl-files-and-modules-from-manifests) to Pkl | ||
1. Create a PklProject file (take a look at pkl/crossplane-example/PklProject for reference) | ||
* Make sure that `\(baseUri)@\(version)` is the url where the package metadata can be downloaded from | ||
* Likewise `\(baseUri)@\(version).zip` is the path where the content will be expected. | ||
> Note: The PklProjects in this repository use pkg.pkl-lang.org, as they redirect to the download | ||
* the path https://pkg.pkl-lang.org/github.com/crossplane-contrib/function-pkl/[email protected] | ||
* redirects to https://github.com/crossplane-contrib/function-pkl/releases/download/[email protected]/[email protected] | ||
1. Run `pkl project resolve` to resolve the dependencies of the PklProject | ||
1. Run `pkl project package` to package the Project into the files and make them ready for the upload. | ||
1. Publish the Package | ||
* This can be done by uploading the files created by the previous command to the place defined in step 2. | ||
* in github this can be done by creating a release and uploading the files to it. | ||
|
||
## Basic Pkl File | ||
Pkl Files used in this Function **must** amend CompositionRequest.pkl. | ||
see [here](example/inline/composition.yaml) and [here](pkl/crossplane-example/full.pkl) | ||
|
||
### Generating Pkl Files and Modules from Manifests | ||
There are some package to make it easier to convert existing CRDs or Manifests into the Pkl format. | ||
> [!NOTE] | ||
> There is currently no module to convert from CompositeResourceDefinitions (XRDs) to Pkl. | ||
> Crossplane Creates CRDs from the XRDs. These CRDs can be converted instead. | ||
> If direct conversion would be useful to you - please create an issue. | ||
|
||
In this example we'll implement the [Object][provider-kubernetes-object] resource from [provider-kubernetes][provider-kubernetes]. | ||
|
||
1. First we will generate a Pkl Module from the Object CRD. | ||
```bash | ||
pkl eval "package://pkg.pkl-lang.org/pkl-pantry/[email protected]#/generate.pkl" -m . -p source="https://raw.githubusercontent.com/crossplane-contrib/provider-kubernetes/main/package/crds/kubernetes.crossplane.io_objects.yaml" | ||
``` | ||
This should create a `Object.pkl` file. | ||
|
||
1. Create a small Pkl file which adds context for the converter about the CRDs. | ||
```pkl | ||
amends "package://pkg.pkl-lang.org/pkl-pantry/[email protected]#/convert.pkl" | ||
customResourceTemplates { | ||
["Object"] { | ||
["kubernetes.crossplane.io/v1alpha2"] = import("Object.pkl") | ||
} | ||
} | ||
``` | ||
|
||
1. Convert a object manifest to pkl | ||
```bash | ||
pkl eval -p "input=https://raw.githubusercontent.com/crossplane-contrib/provider-kubernetes/main/examples/object/object.yaml" -o example-object.pkl <CONVERT-FILE-FROM-PREVIOUS-STEP>.pkl | ||
``` | ||
## Creating a new Composition Function | ||
see [pkl/crossplane.contrib.example/README.md](pkl/crossplane.contrib.example/README.md) | ||
## Development | ||
This function uses [Go][go], [Docker][docker], the [Crossplane CLI][cli], and the [Pkl CLI][pkl cli] to build functions | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,12 +18,12 @@ spec: | |
type: inline | ||
# This pkl file is at `pkl/crossplane-example/full.pkl` in this repo | ||
inline: | | ||
amends "package://pkg.pkl-lang.org/github.com/crossplane-contrib/function-pkl/crossplane@0.0.29#/CompositionResponse.pkl" | ||
import "package://pkg.pkl-lang.org/github.com/crossplane-contrib/function-pkl/crossplane@0.0.29#/Resource.pkl" | ||
import "package://pkg.pkl-lang.org/github.com/crossplane-contrib/function-pkl/crossplane@0.0.29#/Crossplane.pkl" | ||
amends "package://pkg.pkl-lang.org/github.com/crossplane-contrib/function-pkl/crossplane@1.0.0#/CompositionResponse.pkl" | ||
import "package://pkg.pkl-lang.org/github.com/crossplane-contrib/function-pkl/crossplane@1.0.0#/Resource.pkl" | ||
import "package://pkg.pkl-lang.org/github.com/crossplane-contrib/function-pkl/crossplane@1.0.0#/Crossplane.pkl" | ||
import "package://pkg.pkl-lang.org/github.com/crossplane-contrib/function-pkl/crossplane-example@0.1.19#/crds/XR.pkl" | ||
import "package://pkg.pkl-lang.org/github.com/crossplane-contrib/function-pkl/crossplane-example@0.1.19#/crds/Object.pkl" | ||
import "package://pkg.pkl-lang.org/github.com/crossplane-contrib/function-pkl/crossplane-example@1.0.0#/crds/XR.pkl" | ||
import "package://pkg.pkl-lang.org/github.com/crossplane-contrib/function-pkl/crossplane-example@1.0.0#/crds/Object.pkl" | ||
import "package://pkg.pkl-lang.org/pkl-k8s/[email protected]#/api/core/v1/ConfigMap.pkl" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,8 @@ package function | |
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"testing" | ||
|
||
"github.com/apple/pkl-go/pkl" | ||
|
@@ -28,11 +30,11 @@ import ( | |
"github.com/crossplane/crossplane-runtime/pkg/logging" | ||
fnv1beta1 "github.com/crossplane/function-sdk-go/proto/v1beta1" | ||
"github.com/crossplane/function-sdk-go/resource" | ||
//objectv1alpha2 "github.com/crossplane-contrib/provider-kubernetes/apis/object/v1alpha2" | ||
) | ||
|
||
var ( | ||
pklPackage = "package://pkg.pkl-lang.org/github.com/crossplane-contrib/function-pkl/[email protected]" | ||
workdir, _ = os.Getwd() | ||
pklPackage = fmt.Sprintf("%s/../../pkl/crossplane.contrib.example", workdir) | ||
) | ||
|
||
func TestRunFunction(t *testing.T) { | ||
|
@@ -59,8 +61,11 @@ func TestRunFunction(t *testing.T) { | |
Meta: &fnv1beta1.RequestMeta{Tag: "extra"}, | ||
Input: resource.MustStructObject(&v1beta1.Pkl{ | ||
Spec: v1beta1.PklSpec{ | ||
Type: "uri", | ||
Uri: pklPackage + "#/full.pkl", | ||
Type: "local", | ||
Local: &v1beta1.Local{ | ||
ProjectDir: pklPackage, | ||
File: pklPackage + "/full.pkl", | ||
}, | ||
}, | ||
}), | ||
Context: resource.MustStructJSON(`{ | ||
|
@@ -175,7 +180,12 @@ func TestRunFunction(t *testing.T) { | |
for name, tc := range cases { | ||
t.Run(name, func(t *testing.T) { | ||
evaluatorManager := pkl.NewEvaluatorManager() | ||
defer evaluatorManager.Close() | ||
defer func(evaluatorManager pkl.EvaluatorManager) { | ||
err := evaluatorManager.Close() | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
}(evaluatorManager) | ||
f := &Function{Log: logging.NewNopLogger(), EvaluatorManager: evaluatorManager} | ||
rsp, err := f.RunFunction(tc.args.ctx, tc.args.req) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.