|
| 1 | +# Operations Example |
| 2 | + |
| 3 | +This example demonstrates using function-python with Crossplane Operations to |
| 4 | +check SSL certificate expiry for websites referenced in Kubernetes Ingress |
| 5 | +resources. |
| 6 | + |
| 7 | +## Files |
| 8 | + |
| 9 | +- `operation.yaml` - The Operation that checks certificate expiry |
| 10 | +- `functions.yaml` - Function definition for local development |
| 11 | +- `ingress.yaml` - Sample Ingress resource to check |
| 12 | +- `rbac.yaml` - RBAC permissions for Operations to access Ingress resources |
| 13 | +- `README.md` - This file |
| 14 | + |
| 15 | +## Testing |
| 16 | + |
| 17 | +Since Operations are runtime-only (they can't be statically rendered), you can |
| 18 | +test this example locally using the new `crossplane alpha render op` command. |
| 19 | + |
| 20 | +### Prerequisites |
| 21 | + |
| 22 | +1. Run the function in development mode: |
| 23 | + ```bash |
| 24 | + hatch run development |
| 25 | + ``` |
| 26 | + |
| 27 | +2. In another terminal, render the operation: |
| 28 | + ```bash |
| 29 | + crossplane alpha render op operation.yaml functions.yaml --required-resources . -r |
| 30 | + ``` |
| 31 | + |
| 32 | +The `-r` flag includes function results in the output, and |
| 33 | +`--required-resources .` tells the command to use the ingress.yaml file in this |
| 34 | +directory as the required resource. |
| 35 | + |
| 36 | +## What it does |
| 37 | + |
| 38 | +The Operation: |
| 39 | + |
| 40 | +1. **Reads the Ingress** resource specified in `requirements.requiredResources` |
| 41 | +2. **Extracts the hostname** from the Ingress rules (`google.com` in this |
| 42 | + example) |
| 43 | +3. **Fetches the SSL certificate** for that hostname |
| 44 | +4. **Calculates expiry information** (days until expiration) |
| 45 | +5. **Annotates the Ingress** with certificate monitoring annotations |
| 46 | +6. **Returns status information** in the Operation's output field |
| 47 | + |
| 48 | +This pattern is useful for: |
| 49 | +- Certificate monitoring and alerting |
| 50 | +- Compliance checking |
| 51 | +- Automated certificate renewal workflows |
| 52 | +- Integration with monitoring tools that read annotations |
| 53 | + |
| 54 | +## Function Details |
| 55 | + |
| 56 | +The operation function (`operate()`) demonstrates key Operations patterns: |
| 57 | + |
| 58 | +- **Required Resources**: Accessing pre-populated resources via |
| 59 | + `request.get_required_resources(req, "ingress")` |
| 60 | +- **Resource Updates**: Using `rsp.desired.resources` to update existing |
| 61 | + resources |
| 62 | +- **Operation Output**: Using `rsp.output.update()` for monitoring data |
| 63 | +- **Server-side Apply**: Crossplane applies the changes with force ownership |
0 commit comments