Skip to content

Commit

Permalink
chore: add connection detail resource example
Browse files Browse the repository at this point in the history
Signed-off-by: peefy <xpf6677@163.com>
  • Loading branch information
Peefy committed Apr 3, 2024
1 parent fb18467 commit 386ebbe
Show file tree
Hide file tree
Showing 6 changed files with 201 additions and 1 deletion.
2 changes: 2 additions & 0 deletions examples/default/connection_details/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
run:
crossplane beta render xr.yaml composition.yaml functions.yaml -r
113 changes: 113 additions & 0 deletions examples/default/connection_details/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# Example Manifests

You can run your function locally and test it using `crossplane beta render`
with these example manifests.

```shell
# Run the function locally
$ go run . --insecure --debug
```

```shell
# Then, in another terminal, call it with these example manifests
$ crossplane beta render xr.yaml composition.yaml functions.yaml -r
---
apiVersion: example.crossplane.io/v1beta1
kind: XR
metadata:
name: example
status:
dummy: cool-status
---
apiVersion: iam.aws.upbound.io/v1beta1
kind: AccessKey
metadata:
annotations:
crossplane.io/composition-resource-name: sample-access-key-1
generateName: example-
labels:
crossplane.io/composite: example
name: sample-access-key-1
ownerReferences:
- apiVersion: example.crossplane.io/v1beta1
blockOwnerDeletion: true
controller: true
kind: XR
name: example
uid: ""
spec:
forProvider:
userSelector:
matchLabels:
testing.upbound.io/example-name: test-user-1
writeConnectionSecretToRef:
name: sample-access-key-secret-1
namespace: crossplane-system
---
apiVersion: iam.aws.upbound.io/v1beta1
kind: User
metadata:
annotations:
crossplane.io/composition-resource-name: test-user-0
generateName: example-
labels:
crossplane.io/composite: example
dummy: foo
testing.upbound.io/example-name: test-user-0
name: test-user-0
ownerReferences:
- apiVersion: example.crossplane.io/v1beta1
blockOwnerDeletion: true
controller: true
kind: XR
name: example
uid: ""
spec:
forProvider: {}
---
apiVersion: iam.aws.upbound.io/v1beta1
kind: AccessKey
metadata:
annotations:
crossplane.io/composition-resource-name: sample-access-key-0
generateName: example-
labels:
crossplane.io/composite: example
name: sample-access-key-0
ownerReferences:
- apiVersion: example.crossplane.io/v1beta1
blockOwnerDeletion: true
controller: true
kind: XR
name: example
uid: ""
spec:
forProvider:
userSelector:
matchLabels:
testing.upbound.io/example-name: test-user-0
writeConnectionSecretToRef:
name: sample-access-key-secret-0
namespace: crossplane-system
---
apiVersion: iam.aws.upbound.io/v1beta1
kind: User
metadata:
annotations:
crossplane.io/composition-resource-name: test-user-1
generateName: example-
labels:
crossplane.io/composite: example
dummy: foo
testing.upbound.io/example-name: test-user-1
name: test-user-1
ownerReferences:
- apiVersion: example.crossplane.io/v1beta1
blockOwnerDeletion: true
controller: true
kind: XR
name: example
uid: ""
spec:
forProvider: {}
```
71 changes: 71 additions & 0 deletions examples/default/connection_details/composition.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
apiVersion: apiextensions.crossplane.io/v1
kind: Composition
metadata:
name: function-template-go
spec:
compositeTypeRef:
apiVersion: example.crossplane.io/v1
kind: XR
mode: Pipeline
pipeline:
- step: normal
functionRef:
name: kcl-function
input:
apiVersion: krm.kcl.dev/v1alpha1
kind: KCLRun
metadata:
name: basic
spec:
source: |
import base64
oxr = option("params").oxr
count = oxr.spec.count or 1
ocds = option("params").ocds
dxr = {
**oxr
status.dummy = "cool-status"
}
details = {
apiVersion: "meta.krm.kcl.dev/v1alpha1"
kind: "CompositeConnectionDetails"
if "sample-access-key-0" in ocds:
data: {
username = ocds["sample-access-key-0"].ConnectionDetails.username
password = ocds["sample-access-key-0"].ConnectionDetails.password
url = base64.encode("http://www.example.com")
}
else:
data: {}
}
items = sum([[{
apiVersion: "iam.aws.upbound.io/v1beta1"
kind: "User"
metadata.name = "test-user-{}".format(i)
metadata.labels: {
"testing.upbound.io/example-name" = "test-user-{}".format(i)
if "test-user-{}".format(i) in ocds:
dummy = ocds["test-user-{}".format(i)].Resource.metadata.labels.dummy
else:
dummy = "foo"
}
spec.forProvider: {}
}, {
apiVersion: "iam.aws.upbound.io/v1beta1"
kind: "AccessKey"
metadata.name = "sample-access-key-{}".format(i)
metadata.annotations: {
"krm.kcl.dev/ready": "True"
}
spec.forProvider.userSelector.matchLabels: {
"testing.upbound.io/example-name" = "test-user-{}".format(i)
}
spec.writeConnectionSecretToRef: {
name: "sample-access-key-secret-{}".format(i)
namespace: "crossplane-system"
}
}] for i in range(count)], []) + [
details
dxr
]
9 changes: 9 additions & 0 deletions examples/default/connection_details/functions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: pkg.crossplane.io/v1beta1
kind: Function
metadata:
name: kcl-function
annotations:
# This tells crossplane beta render to connect to the function locally.
render.crossplane.io/runtime: Development
spec:
package: xpkg.upbound.io/crossplane-contrib/function-kcl:latest
6 changes: 6 additions & 0 deletions examples/default/connection_details/xr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: example.crossplane.io/v1beta1
kind: XR
metadata:
name: example
spec:
count: 1
1 change: 0 additions & 1 deletion pkg/resource/res.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ const (

const (
AnnotationKeyReady = "krm.kcl.dev/ready"

MetaApiVersion = "meta.krm.kcl.dev/v1alpha1"
)

Expand Down

0 comments on commit 386ebbe

Please sign in to comment.