Skip to content

Commit

Permalink
feat(composition): update all examples, make input configurable (#20)
Browse files Browse the repository at this point in the history
* feat(composition): update all examples, make input configurable

Signed-off-by: Christopher Haar <[email protected]>

* feat(composition): update all examples, make input configurable

Signed-off-by: Christopher Haar <[email protected]>

---------

Signed-off-by: Christopher Haar <[email protected]>
  • Loading branch information
haarchri authored Mar 19, 2024
1 parent acbeace commit 230a9dd
Show file tree
Hide file tree
Showing 21 changed files with 109 additions and 508 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ go.work
.golangci.yml
*.xpkg
function-cidr
.vscode
27 changes: 7 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,13 @@ test: ## Run Code Tests
go test -v -cover .

render: ## Render Examples, Requires make debug first
crossplane beta render \
examples/xr-cidrhost.yaml \
examples/composition-cidrhost.yaml \
examples/functions.yaml
crossplane beta render \
examples/xr.yaml \
examples/composition-cidrnetmask.yaml \
examples/functions.yaml
crossplane beta render \
examples/xr-cidrsubnet.yaml \
examples/composition-cidrsubnet.yaml \
examples/functions.yaml
crossplane beta render \
examples/xr-cidrsubnets.yaml \
examples/composition-cidrsubnets.yaml \
examples/functions.yaml
crossplane beta render \
examples/xr-cidrsubnetloop.yaml \
examples/composition-cidrsubnetloop.yaml \
examples/functions.yaml
@for file in examples/xr-*.yaml; do \
echo "Rendering $$file..."; \
crossplane beta render \
"$$file" \
apis/composition.yaml \
examples/functions.yaml; \
done

debug: ## Run CIDR Function For Rendering Examples
go run . --insecure --debug
270 changes: 1 addition & 269 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ cat <<EOF|kubectl apply -f -
apiVersion: pkg.crossplane.io/v1beta1
kind: Function
metadata:
name: function-cidr
annotations:
render.crossplane.io/runtime: Docker
name: upbound-function-cidr
spec:
package: xpkg.upbound.io/upbound/function-cidr:v0.1.0
EOF
Expand Down Expand Up @@ -73,236 +71,25 @@ field path in the XR.
The `cidrhost cidrfunc` requires a `hostnum` or `hostnumfield` as
function input. `hostnum` is an integer.

#### Composition With Default Input / Output Fields
```
apiVersion: apiextensions.crossplane.io/v1
kind: Composition
metadata:
name: vpc
spec:
compositeTypeRef:
apiVersion: platform.upbound.io/v1alpha1
kind: XVPC
mode: Pipeline
pipeline:
- step: cidr
functionRef:
name: function-cidr
input:
apiVersion: cidr.fn.crossplane.io/v1beta1
kind: Parameters
cidrFunc: cidrhost
prefix: "10.0.0.0/20"
hostNum: 111
```

#### Composition With Custom Input / Output Fields
```
apiVersion: apiextensions.crossplane.io/v1
kind: Composition
metadata:
name: vpc
spec:
compositeTypeRef:
apiVersion: platform.upbound.io/v1alpha1
kind: XVPC
mode: Pipeline
pipeline:
- step: cidr
functionRef:
name: function-cidr
input:
apiVersion: cidr.fn.crossplane.io/v1beta1
kind: Parameters
cidrFunc: cidrhost
prefixField: spec.forFunction.cidr
hostNumField: spec.forFunction.hostNum
outputField: "status.atFunction.cidr.hostAddress"
```
#### XR For Composition With Custom Input / Output Fields
```
apiVersion: platform.upbound.io/v1alpha1
kind: XVPC
metadata:
name: cidr-example
spec:
forFunction:
cidr: 10.0.0.0/20
hostNum: 111
```
The function writes its output into the specified `outputfield`.
```
apiVersion: platform.upbound.io/v1alpha1
kind: XVPC
metadata:
name: cidr-example
status:
atFunction:
cidr:
hostAddress: 10.0.0.111
```

### cidrnetmask
The `cidrnetmask cidrfunc` does not require additional parameters
beyond the `prefix`. The `prefix` can be read from an XR field
when the `prefixField` path is specified in the function input
instead of a `prefix` value.

#### Composition With Default Input / Output Fields
```
apiVersion: apiextensions.crossplane.io/v1
kind: Composition
metadata:
name: cidr-example
spec:
compositeTypeRef:
apiVersion: platform.upbound.io/v1alpha1
kind: XVPC
mode: Pipeline
pipeline:
- step: cidr
functionRef:
name: function-cidr
input:
apiVersion: cidr.fn.crossplane.io/v1beta1
kind: Parameters
cidrFunc: cidrnetmask
prefix: 172.16.0.0/12
```
#### XR
The `cidrnetmask` function does not rely on any fields in the XR.
```
apiVersion: platform.upbound.io/v1alpha1
kind: XVPC
metadata:
name: cidr-example
spec:
```
The function writes its output to the default `status.cidr`
field unless the function input `outputfield` has been specified.
```
apiVersion: platform.upbound.io/v1alpha1
kind: XVPC
metadata:
name: cidr-example
status:
atFunction:
cidr:
netmask: 255.240.0.0
```

### cidrsubnet
The `cidrhost cidrsubnet` reauires a `netnum` or `netnumfield`,
and a `newbits` or `newbitsfield` as function input.

`netNum` is an integer.
`newBits` is one integer in an array of integers.

#### Composition With Custom Input / Output Fields
```
apiVersion: apiextensions.crossplane.io/v1
kind: Composition
metadata:
name: cidr-example
spec:
compositeTypeRef:
apiVersion: platform.upbound.io/v1alpha1
kind: XVPC
mode: Pipeline
pipeline:
- step: cidr
functionRef:
name: function-cidr
input:
apiVersion: cidr.fn.crossplane.io/v1beta1
kind: Parameters
cidrFunc: cidrsubnet
prefixField: spec.forFunction.cidr
newBitsField: spec.forFunction.newBits
netNumField: spec.forFunction.netNum
outputField: status.atFunction.cidr.subnet-1
```
#### XR For Composition With Custom Input / Output Fields
```
apiVersion: platform.upbound.io/v1alpha1
kind: XVPC
metadata:
name: cidr-example
spec:
forFunction:
cidr: 10.0.0.0/20
newBits:
- 8
netNum: 3
```
The function writes its output into the specified `outputfield`.
```
apiVersion: platform.upbound.io/v1alpha1
kind: XVPC
metadata:
name: cidr-example
status:
atFunction:
cidr:
subnet-1: 10.0.0.48/28
```

### cidrsubnets
The `cidrhost cidrsubnets` reauires a `newBits`
or `newBitsField` as function input.

`newBits` is an array of integers.

#### Composition With Hybrid Default and Custom Input / Output Fields
```
apiVersion: apiextensions.crossplane.io/v1
kind: Composition
metadata:
name: cidr-example
spec:
compositeTypeRef:
apiVersion: platform.upbound.io/v1alpha1
kind: XVPC
mode: Pipeline
pipeline:
- step: cidr
functionRef:
name: function-cidr
input:
apiVersion: cidr.fn.crossplane.io/v1beta1
kind: Parameters
cidrFunc: cidrsubnets
prefix: 10.0.0.0/20
newBitsField: spec.forFunction.newBits
```
#### XR For Hybrid Composition With Default and Custom Input / Output Fields
```
apiVersion: platform.upbound.io/v1alpha1
kind: XVPC
metadata:
name: cidr-example
spec:
forFunction:
newBits:
- 8
- 4
- 2
```
The function writes its output into the default `outputfield`.
```
apiVersion: platform.upbound.io/v1alpha1
kind: XVPC
metadata:
name: cidr-example
status:
atFunction:
cidr:
subnets:
- 10.0.0.0/28
- 10.0.1.0/24
- 10.0.4.0/22
```

### cidrsubnetloop
The `cidrhost cidrsubnetloop` reauires the following input fields.
- `newBits` (integer array) or `newBitsField`
Expand All @@ -318,61 +105,6 @@ iteration from `iteration`+`offset`. The iterations are either from
0 to `netNumCount` -1 or from 0 to number of items in `netNumItemsCount`
or their respective values from their XR field references.

#### Composition With Custom Input / Output Fields
```
apiVersion: apiextensions.crossplane.io/v1
kind: Composition
metadata:
name: cidr-example
spec:
compositeTypeRef:
apiVersion: platform.upbound.io/v1alpha1
kind: XVPC
mode: Pipeline
pipeline:
- step: cidr
functionRef:
name: function-cidr
input:
apiVersion: cidr.fn.crossplane.io/v1beta1
kind: Parameters
cidrFunc: cidrsubnetloop
prefixField: spec.forFunction.cidrBlock
newBitsField: spec.forFunction.newBits
netNumItemsField: spec.forFunction.azs
offsetField: spec.forFunction.offset
outputfield: spec.atFunction.cidr.subnets
```
#### XR For Composition With Custom Input / Output Fields
```
apiVersion: platform.upbound.io/v1alpha1
kind: XVPC
metadata:
name: cidr-example
spec:
forFunction:
cidr: 10.0.0.0/20
newBits:
- 8
netNum: 3
```
The function writes its output into the specified `outputField`.
```
apiVersion: platform.upbound.io/v1alpha1
kind: XVPC
metadata:
name: cidr-example
spec:
atFunction:
cidr:
subnets:
- 10.0.0.48/32
- 10.0.0.49/32
- 10.0.0.50/32
- 10.0.0.51/32
- 10.0.0.52/32
```

## Testing The Function
Clone the repo. Run `make debug` and in a second terminal run `make render`
and examine the output. Corresponding compositions and XR yaml can be
Expand Down
2 changes: 0 additions & 2 deletions api/README.md

This file was deleted.

Loading

0 comments on commit 230a9dd

Please sign in to comment.