|
| 1 | +# ApprovalRequest Controller |
| 2 | + |
| 3 | +The ApprovalRequest Controller is a standalone controller that runs on the **hub cluster** to automate approval decisions for staged updates based on workload health metrics. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +This controller is designed to be a standalone component that can run independently from the main kubefleet repository. It: |
| 8 | +- Uses kubefleet v0.1.2 as an external dependency |
| 9 | +- Includes its own APIs for MetricCollectorReport and WorkloadTracker |
| 10 | +- Watches `ApprovalRequest` and `ClusterApprovalRequest` resources (from kubefleet) |
| 11 | +- Creates `MetricCollector` resources on member clusters via ClusterResourcePlacement |
| 12 | +- Monitors workload health via `MetricCollectorReport` objects |
| 13 | +- Automatically approves requests when all tracked workloads are healthy |
| 14 | +- Runs every 15 seconds to check health status |
| 15 | + |
| 16 | +## Architecture |
| 17 | + |
| 18 | +The controller is designed to run on the hub cluster and: |
| 19 | +1. Deploys MetricCollector instances to member clusters using CRP |
| 20 | +2. Collects health metrics from MetricCollectorReports |
| 21 | +3. Compares metrics against WorkloadTracker specifications |
| 22 | +4. Approves ApprovalRequests when all workloads are healthy |
| 23 | + |
| 24 | +## Installation |
| 25 | + |
| 26 | +### Prerequisites |
| 27 | + |
| 28 | +The following CRDs must be installed on the hub cluster (installed by kubefleet hub-agent): |
| 29 | +- `approvalrequests.placement.kubernetes-fleet.io` |
| 30 | +- `clusterapprovalrequests.placement.kubernetes-fleet.io` |
| 31 | +- `clusterresourceplacements.placement.kubernetes-fleet.io` |
| 32 | +- `clusterresourceoverrides.placement.kubernetes-fleet.io` |
| 33 | +- `clusterstagedupdateruns.placement.kubernetes-fleet.io` |
| 34 | +- `stagedupdateruns.placement.kubernetes-fleet.io` |
| 35 | + |
| 36 | +The following CRDs are installed by this chart: |
| 37 | +- `metriccollectors.metric.kubernetes-fleet.io` |
| 38 | +- `metriccollectorreports.metric.kubernetes-fleet.io` |
| 39 | +- `workloadtrackers.metric.kubernetes-fleet.io` |
| 40 | + |
| 41 | +### Install via Helm |
| 42 | + |
| 43 | +```bash |
| 44 | +# Build the image |
| 45 | +make docker-build IMAGE_NAME=approval-request-controller IMAGE_TAG=latest |
| 46 | + |
| 47 | +# Load into kind (if using kind) |
| 48 | +kind load docker-image approval-request-controller:latest --name hub |
| 49 | + |
| 50 | +# Install the chart |
| 51 | +helm install approval-request-controller ./charts/approval-request-controller \ |
| 52 | + --namespace fleet-system \ |
| 53 | + --create-namespace |
| 54 | +``` |
| 55 | + |
| 56 | +## Configuration |
| 57 | + |
| 58 | +The controller watches for: |
| 59 | +- `ApprovalRequest` (namespaced) |
| 60 | +- `ClusterApprovalRequest` (cluster-scoped) |
| 61 | + |
| 62 | +Both resources from kubefleet are monitored, and the controller creates `MetricCollector` resources on appropriate member clusters based on the staged update configuration. |
| 63 | + |
| 64 | +### Health Check Interval |
| 65 | + |
| 66 | +The controller checks workload health every **15 seconds**. This interval is configurable via the `reconcileInterval` parameter in the Helm chart. |
| 67 | + |
| 68 | +## API Reference |
| 69 | + |
| 70 | +### WorkloadTracker |
| 71 | + |
| 72 | +`WorkloadTracker` is a cluster-scoped custom resource that defines which workloads the approval controller should monitor for health metrics before auto-approving staged rollouts. |
| 73 | + |
| 74 | +#### Example: Single Workload |
| 75 | + |
| 76 | +```yaml |
| 77 | +apiVersion: metric.kubernetes-fleet.io/v1beta1 |
| 78 | +kind: WorkloadTracker |
| 79 | +metadata: |
| 80 | + name: sample-workload-tracker |
| 81 | +workloads: |
| 82 | + - name: sample-metric-app |
| 83 | + namespace: test-ns |
| 84 | +``` |
| 85 | +
|
| 86 | +#### Example: Multiple Workloads |
| 87 | +
|
| 88 | +```yaml |
| 89 | +apiVersion: metric.kubernetes-fleet.io/v1beta1 |
| 90 | +kind: WorkloadTracker |
| 91 | +metadata: |
| 92 | + name: multi-workload-tracker |
| 93 | +workloads: |
| 94 | + - name: frontend |
| 95 | + namespace: production |
| 96 | + - name: backend-api |
| 97 | + namespace: production |
| 98 | + - name: worker-service |
| 99 | + namespace: production |
| 100 | +``` |
| 101 | +
|
| 102 | +#### Usage Notes |
| 103 | +
|
| 104 | +- **Cluster-scoped:** WorkloadTracker is a cluster-scoped resource, not namespaced |
| 105 | +- **Optional:** If no WorkloadTracker exists, the controller will skip health checks and won't auto-approve |
| 106 | +- **Single instance:** The controller expects one WorkloadTracker per cluster and uses the first one found |
| 107 | +- **Health criteria:** All workloads listed must report healthy (metric value = 1.0) before approval |
| 108 | +- **Prometheus metrics:** Each workload should expose `workload_health` metrics that the MetricCollector can query |
| 109 | + |
| 110 | +For a complete example, see: [`./examples/workloadtracker/workloadtracker.yaml`](./examples/workloadtracker/workloadtracker.yaml) |
| 111 | + |
| 112 | +## Additional Resources |
| 113 | + |
| 114 | +- **Main Tutorial:** See [`../README.md`](../README.md) for a complete end-to-end tutorial on setting up automated staged rollouts with approval automation |
| 115 | +- **Metric Collector:** See [`../metric-collector/README.md`](../metric-collector/README.md) for details on the metric collection component that runs on member clusters |
| 116 | +- **KubeFleet Documentation:** [Azure/fleet](https://github.com/Azure/fleet) - Multi-cluster orchestration platform |
| 117 | +- **Example Configurations:** |
| 118 | + - [`./examples/workloadtracker/`](./examples/workloadtracker/) - WorkloadTracker resource examples |
| 119 | + - [`./examples/stagedupdaterun/`](./examples/stagedupdaterun/) - Staged update configuration examples |
| 120 | + - [`./examples/prometheus/`](./examples/prometheus/) - Prometheus deployment and configuration for metric collection |
| 121 | +``` |
0 commit comments