-
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 #18 from Avarei/pkl-compositions
Pkl compositions
- Loading branch information
Showing
25 changed files
with
1,422 additions
and
239 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,4 +24,7 @@ go.work | |
.idea/ | ||
|
||
# Temporary Debug Binaries | ||
__debug_bin* | ||
__debug_bin* | ||
|
||
# Pkl | ||
*PklProject.deps.json |
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 |
---|---|---|
|
@@ -30,12 +30,12 @@ spec: | |
functionRef: | ||
name: function-pkl | ||
input: | ||
apiVersion: template.fn.crossplane.io/v1beta1 | ||
apiVersion: pkl.fn.crossplane.io/v1beta1 | ||
kind: Pkl | ||
spec: | ||
type: uri | ||
# This pkl file is at `pkl/crossplane.contrib.example/full.pkl` in this repo | ||
uri: "package://pkg.pkl-lang.org/github.com/crossplane-contrib/function-pkl/crossplane.contrib.example@1.0.0#/full.pkl" | ||
uri: "package://pkg.pkl-lang.org/github.com/crossplane-contrib/function-pkl/[email protected].1#/full.pkl" | ||
``` | ||
### Example | ||
|
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 |
---|---|---|
|
@@ -12,9 +12,9 @@ spec: | |
functionRef: | ||
name: function-pkl | ||
input: | ||
apiVersion: template.fn.crossplane.io/v1beta1 | ||
apiVersion: pkl.fn.crossplane.io/v1beta1 | ||
kind: Pkl | ||
spec: | ||
type: uri | ||
# This pkl file is at `pkl/crossplane.contrib.example/full.pkl` in this repo | ||
uri: "package://pkg.pkl-lang.org/github.com/crossplane-contrib/function-pkl/crossplane.contrib.example@1.0.0#/full.pkl" | ||
uri: "package://pkg.pkl-lang.org/github.com/crossplane-contrib/function-pkl/[email protected].1#/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,27 @@ | ||
apiVersion: apiextensions.crossplane.io/v1 | ||
kind: Composition | ||
metadata: | ||
name: function-pkl | ||
name: inline-example | ||
spec: | ||
compositeTypeRef: | ||
apiVersion: example.crossplane.io/v1 | ||
kind: XR | ||
mode: Pipeline | ||
pipeline: | ||
- step: run-the-template | ||
functionRef: | ||
- functionRef: | ||
name: function-pkl | ||
input: | ||
apiVersion: template.fn.crossplane.io/v1beta1 | ||
apiVersion: pkl.fn.crossplane.io/v1beta1 | ||
kind: Pkl | ||
spec: | ||
type: inline | ||
# This pkl file is at `pkl/crossplane.contrib.example/full.pkl` in this repo | ||
inline: | | ||
amends "package://pkg.pkl-lang.org/github.com/crossplane-contrib/function-pkl/[email protected]#/CompositionResponse.pkl" | ||
import "package://pkg.pkl-lang.org/github.com/crossplane-contrib/function-pkl/[email protected]#/Resource.pkl" | ||
import "package://pkg.pkl-lang.org/github.com/crossplane-contrib/function-pkl/[email protected]#/Crossplane.pkl" | ||
import "package://pkg.pkl-lang.org/github.com/crossplane-contrib/function-pkl/[email protected]#/crds/XR.pkl" | ||
import "package://pkg.pkl-lang.org/github.com/crossplane-contrib/function-pkl/[email protected]#/crds/Object.pkl" | ||
import "package://pkg.pkl-lang.org/pkl-k8s/[email protected]#/api/core/v1/ConfigMap.pkl" | ||
local request = new Crossplane { | ||
customResourceTemplates = new { | ||
["XR"] { | ||
["example.crossplane.io/v1"] = XR | ||
} | ||
["Object"] { | ||
["kubernetes.crossplane.io/v1alpha2"] = Object | ||
} | ||
} | ||
}.Request | ||
local observedCompositeResource: XR = request.observed.composite.resource as XR | ||
local extraResource: Object? = request.getExtraResource("ineed", 0)?.resource as Object? | ||
requirements { | ||
extraResources { | ||
["ineed"] { | ||
apiVersion = Object.apiVersion | ||
kind = Object.kind | ||
match { | ||
matchName = "required" | ||
} | ||
} | ||
} | ||
} | ||
amends "package://pkg.pkl-lang.org/github.com/crossplane-contrib/function-pkl/[email protected]#/CompositionResponse.pkl" | ||
import "package://pkg.pkl-lang.org/github.com/crossplane-contrib/function-pkl/[email protected]#/crds/Object.pkl" | ||
import "package://pkg.pkl-lang.org/pkl-k8s/[email protected]#/api/core/v1/ConfigMap.pkl" | ||
desired { | ||
composite { | ||
resource = new XR { | ||
status { | ||
someStatus = "pretty status" | ||
} | ||
} | ||
} | ||
resources { | ||
["cm-one"] = new Resource { | ||
["cm-minimal"] = new { | ||
resource = new Object { | ||
metadata { | ||
name = "cm-one" | ||
|
@@ -71,35 +30,18 @@ spec: | |
forProvider { | ||
manifest = new ConfigMap { | ||
metadata { | ||
name = "cm-one" | ||
name = "cm-minimal" | ||
namespace = "crossplane-system" | ||
} | ||
data { | ||
["foo"] = observedCompositeResource?.metadata?.name ?? throw("Composite could not find observed composite name") | ||
["required"] = extraResource?.metadata?.name ?? "i could not find what I needed..." | ||
["foo"] = "bar" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
ready = Ready_READY_TRUE | ||
} | ||
} | ||
} | ||
results { | ||
new { | ||
severity = Severity_SEVERITY_NORMAL | ||
message = "welcome" | ||
} | ||
} | ||
context { | ||
["greetings"] = "with <3 from function-pkl" | ||
when (request.context.containsKey("apiextensions.crossplane.io/environment")) { | ||
["apiextensions.crossplane.io/environment"] = request.context.getOrNull("apiextensions.crossplane.io/environment") | ||
} | ||
} | ||
meta = if (request.meta != null) new ResponseMeta { | ||
ttl = 60.s | ||
} else null | ||
type: inline | ||
step: pkl-template |
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 |
---|---|---|
|
@@ -12,9 +12,9 @@ spec: | |
functionRef: | ||
name: function-pkl | ||
input: | ||
apiVersion: template.fn.crossplane.io/v1beta1 | ||
apiVersion: pkl.fn.crossplane.io/v1beta1 | ||
kind: Pkl | ||
spec: | ||
type: uri | ||
# This pkl file is at `pkl/crossplane-example/minimal.pkl` in this repo | ||
uri: "package://pkg.pkl-lang.org/github.com/crossplane-contrib/function-pkl/crossplane-example@1.0.0#/minimal.pkl" | ||
uri: "package://pkg.pkl-lang.org/github.com/crossplane-contrib/function-pkl/[email protected].1#/minimal.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
//===----------------------------------------------------------------------===// | ||
// 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 = read?("env:REPOSITORY") ?? "github.com/crossplane-contrib/function-pkl" | ||
local packageVersion: String = "0.0.0" | ||
|
||
package { | ||
name = "pklcrd" | ||
authors { | ||
"Tim Geimer <[email protected]>" | ||
} | ||
version = packageVersion | ||
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.xrd"] = import("../../pkl/crossplane.contrib.xrd/PklProject") | ||
|
||
["k8s.contrib.crd"] { | ||
uri = "package://pkg.pkl-lang.org/pkl-pantry/[email protected]" | ||
} | ||
["k8s"] { | ||
uri = "package://pkg.pkl-lang.org/pkl-k8s/[email protected]" | ||
} | ||
|
||
//workaround | ||
["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]" } | ||
} |
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,6 @@ | ||
# Generate the Pkl.pkl and Composition.pkl | ||
|
||
```shell | ||
pkl eval -m ../../pkl/crossplane-contrib crd2module.pkl | ||
pkl eval -m ../../pkl/crossplane-contrib crd2module-composition-fix.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
amends "generate.pkl" | ||
|
||
import "@k8s/K8sResource.pkl" | ||
|
||
source = "https://raw.githubusercontent.com/crossplane/crossplane/v1.16.0/cluster/crds/apiextensions.crossplane.io_compositions.yaml" | ||
|
||
// These Converters Provide Type Safety on the Object resource. Without them manifest would be of type "Dynamic" | ||
converters { | ||
["compositions.apiextensions.crossplane.io"] { | ||
[List("spec", "pipeline", "pipeline", "input")] = K8sResource | ||
} | ||
} | ||
|
||
// The Package references to be used within the new Module | ||
k8sImportPath = "@k8s" // package://pkg.pkl-lang.org/pkl-k8s/k8s@<version># |
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,6 @@ | ||
amends "@k8s.contrib.crd/generate.pkl" | ||
|
||
source = "package/input/pkl.fn.crossplane.io_pkls.yaml" | ||
|
||
// The Package references to be used within the new Module | ||
k8sImportPath = "@k8s" // package://pkg.pkl-lang.org/pkl-k8s/k8s@<version># |
Oops, something went wrong.