-
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.
add package to convert xrd pkl files to Classes. Start adding a small guide to the Readme
- Loading branch information
Showing
25 changed files
with
906 additions
and
90 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,12 +35,84 @@ 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 new Composition Function from Scratch | ||
#### Create a XRD | ||
If you already have an XRD skip this and the next section. | ||
Create a new Pkl file | ||
```pkl | ||
amends "package://pkg.pkl-lang.org/github.com/crossplane-contrib/function-pkl/[email protected]#/CompositeResourceDefinition.pkl" | ||
``` | ||
the Pkl file can be rendered as Yaml using `pkl eval <nameOfYourPklFile>.pkl` | ||
|
||
#### Create a Module of your XRD | ||
To Convert the XRD.pkl to Pkl Module a small helper file `xrd2module.pkl` is needed: | ||
```pkl | ||
amends "package://pkg.pkl-lang.org/github.com/crossplane-contrib/function-pkl/[email protected]#/generate.pkl" | ||
crds { | ||
import("XR.pkl") | ||
} | ||
k8sImportPath = "@k8s" | ||
crossplaneImportPath = "@crossplane.contrib" | ||
``` | ||
running `pkl eval generate.pkl -m .` will generate a new Module that can be imported and referenced in the Composition. | ||
|
||
#### Create Managed Resources in Pkl | ||
Import Managed Resources and Preexisting CompositeResourceDefinitions to Pkl | ||
```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" | ||
``` | ||
|
||
#### Create the Composition Function Logic | ||
The Function must amend CompositionResponse.pkl. | ||
|
||
This is a very minimal example. A more extensive one can be found in `pkl/crossplane.contrib.example` | ||
```pkl | ||
amends "crossplane.contrib/CompositionResponse.pkl" | ||
import "crds/Object.pkl" | ||
import "@k8s/api/core/v1/ConfigMap.pkl" | ||
desired { | ||
resources { | ||
["example"] = new Resource { | ||
resource = new Object { | ||
metadata { | ||
name = "example" | ||
} | ||
spec { | ||
forProvider { | ||
manifest = new ConfigMap { | ||
metadata { | ||
name = "example" | ||
namespace = "crossplane-system" | ||
} | ||
data { | ||
["hello"] = "world" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
#### Create Composition | ||
TODO. | ||
|
||
|
||
|
||
## Building a Pkl Package | ||
A Pkl Package can be built in the following steps: | ||
1. Create Pkl files in a directory | ||
|
@@ -59,7 +131,7 @@ A Pkl Package can be built in the following steps: | |
|
||
## 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) | ||
see [here](example/inline/composition.yaml) and [here](pkl/crossplane.contrib.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. | ||
|
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
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,11 +18,11 @@ | |
amends "pkl:Project" | ||
|
||
package { | ||
name = "crossplane-example" | ||
name = "crossplane.contrib.example" | ||
authors { | ||
"Tim Geimer <[email protected]>" | ||
} | ||
version = "0.1.19" | ||
version = "1.0.0" | ||
baseUri = "package://pkg.pkl-lang.org/github.com/crossplane-contrib/function-pkl/\(name)" | ||
packageZipUrl = "https://github.com/crossplane-contrib/function-pkl/releases/download/\(name)@\(version)/\(name)@\(version).zip" | ||
sourceCode = "https://github.com/crossplane-contrib/function-pkl" | ||
|
@@ -35,7 +35,6 @@ dependencies { | |
["k8s"] { | ||
uri = "package://pkg.pkl-lang.org/pkl-k8s/[email protected]" | ||
} | ||
["crossplane"] { | ||
uri = "package://pkg.pkl-lang.org/github.com/crossplane-contrib/function-pkl/[email protected]" | ||
} | ||
["crossplane.contrib"] = import("../crossplane.contrib/PklProject") | ||
["crossplane.contrib.xrd"] = import("../crossplane.contrib.xrd/PklProject") | ||
} |
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
{ | ||
"schemaVersion": 1, | ||
"resolvedDependencies": { | ||
"package://pkg.pkl-lang.org/pkl-k8s/k8s@1": { | ||
"type": "remote", | ||
"uri": "projectpackage://pkg.pkl-lang.org/pkl-k8s/[email protected]", | ||
"checksums": { | ||
"sha256": "75c6d66d94c335417a3c502e107aaeadf7a60b4e1d34b2c979afe11193205a1a" | ||
} | ||
}, | ||
"package://pkg.pkl-lang.org/github.com/crossplane-contrib/function-pkl/crospslane.contrib.xrd@1": { | ||
"type": "local", | ||
"uri": "projectpackage://pkg.pkl-lang.org/github.com/crossplane-contrib/function-pkl/[email protected]", | ||
"path": "../crossplane.contrib.xrd" | ||
}, | ||
"package://pkg.pkl-lang.org/pkl-pantry/pkl.experimental.deepToTyped@1": { | ||
"type": "remote", | ||
"uri": "projectpackage://pkg.pkl-lang.org/pkl-pantry/[email protected]", | ||
"checksums": { | ||
"sha256": "0746fe618d59187b15ca3e589caf359a285c74efadd8c796da86aaa08202d542" | ||
} | ||
}, | ||
"package://pkg.pkl-lang.org/pkl-pantry/org.json_schema.contrib@1": { | ||
"type": "remote", | ||
"uri": "projectpackage://pkg.pkl-lang.org/pkl-pantry/[email protected]", | ||
"checksums": { | ||
"sha256": "b76f2ea3fd7252b7d6ec4ac7331dea197b4ce9846adc86c3853c13c48b358d13" | ||
} | ||
}, | ||
"package://pkg.pkl-lang.org/pkl-pantry/pkl.experimental.syntax@1": { | ||
"type": "remote", | ||
"uri": "projectpackage://pkg.pkl-lang.org/pkl-pantry/[email protected]", | ||
"checksums": { | ||
"sha256": "83ad123a9de2e1e559dbf72370ec8d0353b8d017f37823cdd4ab71f0ce04eb18" | ||
} | ||
}, | ||
"package://pkg.pkl-lang.org/pkl-pantry/pkl.experimental.uri@1": { | ||
"type": "remote", | ||
"uri": "projectpackage://pkg.pkl-lang.org/pkl-pantry/[email protected]", | ||
"checksums": { | ||
"sha256": "0b1db5755fa0c7651d5c62e0d5ef8a9ed4ed6411fe31769d06714600162e1589" | ||
} | ||
}, | ||
"package://pkg.pkl-lang.org/pkl-pantry/org.json_schema@1": { | ||
"type": "remote", | ||
"uri": "projectpackage://pkg.pkl-lang.org/pkl-pantry/[email protected]", | ||
"checksums": { | ||
"sha256": "7a11e61df5248c81b9256cae11ae333c13aa5a05101aff1d7b26d7a2e825df96" | ||
} | ||
}, | ||
"package://pkg.pkl-lang.org/pkl-pantry/org.openapis.v3@2": { | ||
"type": "remote", | ||
"uri": "projectpackage://pkg.pkl-lang.org/pkl-pantry/[email protected]", | ||
"checksums": { | ||
"sha256": "a3ce491d0e504c14d456d599f988bbb4a2b77915696450dfd65b8e4cef7c9522" | ||
} | ||
}, | ||
"package://pkg.pkl-lang.org/github.com/crossplane-contrib/function-pkl/crossplane.contrib@1": { | ||
"type": "local", | ||
"uri": "projectpackage://pkg.pkl-lang.org/github.com/crossplane-contrib/function-pkl/[email protected]", | ||
"path": "../crossplane.contrib" | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions
8
pkl/crossplane-example/full.pkl → pkl/crossplane.contrib.example/full.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
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
amends "@crossplane.contrib.xrd/C" |
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
//===----------------------------------------------------------------------===// | ||
// Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
//===----------------------------------------------------------------------===// | ||
|
||
/// Templates for configuring [Kubernetes](https://kubernetes.io). | ||
amends "pkl:Project" | ||
|
||
local repo = "github.com/crossplane-contrib/function-pkl" | ||
|
||
package { | ||
name = "crospslane.contrib.xrd" | ||
authors { | ||
"Tim Geimer <[email protected]>" | ||
} | ||
version = "1.0.0" | ||
baseUri = "package://pkg.pkl-lang.org/\(repo)/\(name)" | ||
packageZipUrl = "https://\(repo)/releases/download/\(name)@\(version)/\(name)@\(version).zip" | ||
sourceCode = "https://\(repo)" | ||
license = "Apache-2.0" | ||
description = """ | ||
Convert CompositeResourceDefitions to Modules that can be amended | ||
""" | ||
} | ||
dependencies { | ||
["crossplane.contrib"] = import("../crossplane.contrib/PklProject") | ||
|
||
["jsonschema"] { uri = "package://pkg.pkl-lang.org/pkl-pantry/[email protected]" } | ||
["jsonschema.contrib"] { uri = "package://pkg.pkl-lang.org/pkl-pantry/[email protected]" } | ||
["deepToTyped"] { uri = "package://pkg.pkl-lang.org/pkl-pantry/[email protected]" } | ||
["uri"] { uri = "package://pkg.pkl-lang.org/pkl-pantry/[email protected]" } | ||
["syntax"] { uri = "package://pkg.pkl-lang.org/pkl-pantry/[email protected]" } | ||
["openapiv3"] { uri = "package://pkg.pkl-lang.org/pkl-pantry/[email protected]" } | ||
|
||
["k8s"] { uri = "package://pkg.pkl-lang.org/pkl-k8s/[email protected]" } | ||
} |
Oops, something went wrong.