|
| 1 | +# RHAI (Red Hat AI) Extensions |
| 2 | + |
| 3 | +This directory contains RHAI-specific extensions for the Kubeflow Trainer operator. |
| 4 | + |
| 5 | +## Purpose |
| 6 | + |
| 7 | +The `rhai/` package provides midstream-specific features that are not part of upstream Kubeflow: |
| 8 | +- **Progression tracking**: Real-time training metrics polling and status updates |
| 9 | +- **Custom annotations**: RHAI-specific metadata for training jobs |
| 10 | +- **Extended RBAC**: Additional permissions |
| 11 | + |
| 12 | +## Structure |
| 13 | + |
| 14 | +``` |
| 15 | +pkg/rhai/ |
| 16 | +├── README.md # This file |
| 17 | +├── setup.go # RHAI feature registration |
| 18 | +├── controller/ |
| 19 | +│ └── progression_controller.go # Wraps base controller with progression tracking |
| 20 | +└── progression/ |
| 21 | + ├── progression.go # Core progression tracking logic |
| 22 | + └── progression_test.go # Tests for progression tracking |
| 23 | +``` |
| 24 | + |
| 25 | +## How It Works |
| 26 | + |
| 27 | +### 1. Controller Wrapping |
| 28 | + |
| 29 | +The `ProgressionReconciler` wraps the base `TrainJobReconciler` and adds: |
| 30 | +- Metrics polling from training pods |
| 31 | +- Progress annotation updates |
| 32 | +- Automatic requeuing for ongoing polling |
| 33 | + |
| 34 | +### 2. Progression Tracking |
| 35 | + |
| 36 | +When enabled via annotation `trainer.opendatahub.io/progression-tracking: "enabled"`: |
| 37 | +- Controller polls training pod's metrics endpoint (default port: 28080) |
| 38 | +- Updates TrainJob annotations with real-time progress |
| 39 | +- Captures final metrics on job completion/failure |
| 40 | + |
| 41 | +### 3. Manifest Integration |
| 42 | + |
| 43 | +RHAI-specific manifests in `manifests/rhoai/`: |
| 44 | +- `rbac_progression_patch.yaml`: Additional RBAC for pod access |
| 45 | +- `manager_config_patch.yaml`: ConfigMap mounting for feature flags |
| 46 | + |
| 47 | +## Enabling RHAI Features |
| 48 | + |
| 49 | +RHAI features are controlled via the `ENABLE_RHAI_FEATURES` environment variable. When enabled, the operator uses a wrapping controller that adds progression tracking to the base upstream functionality. |
| 50 | + |
| 51 | +### Deployment Configuration |
| 52 | + |
| 53 | +**For Kubernetes/OpenShift deployments**, set the environment variable in your deployment manifest: |
| 54 | + |
| 55 | +```yaml |
| 56 | +# manifests/rhoai/manager_config_patch.yaml |
| 57 | +apiVersion: apps/v1 |
| 58 | +kind: Deployment |
| 59 | +spec: |
| 60 | + template: |
| 61 | + spec: |
| 62 | + containers: |
| 63 | + - name: manager |
| 64 | + env: |
| 65 | + - name: ENABLE_RHAI_FEATURES |
| 66 | + value: "true" |
| 67 | +``` |
| 68 | +
|
| 69 | +**For local development**, export the variable before running: |
| 70 | +
|
| 71 | +```bash |
| 72 | +export ENABLE_RHAI_FEATURES=true |
| 73 | +go run ./cmd/trainer-controller-manager/main.go |
| 74 | +``` |
| 75 | + |
| 76 | +## Usage Example |
| 77 | + |
| 78 | +Create a TrainJob with progression tracking: |
| 79 | + |
| 80 | +```yaml |
| 81 | +apiVersion: trainer.kubeflow.org/v1alpha1 |
| 82 | +kind: TrainJob |
| 83 | +metadata: |
| 84 | + name: pytorch-example |
| 85 | + annotations: |
| 86 | + trainer.opendatahub.io/progression-tracking: "enabled" |
| 87 | + trainer.opendatahub.io/metrics-port: "28080" # optional, default: 28080 |
| 88 | + trainer.opendatahub.io/metrics-poll-interval: "30s" # optional, default: 30s |
| 89 | +spec: |
| 90 | + # ... your training job spec ... |
| 91 | +``` |
| 92 | + |
| 93 | +The controller will: |
| 94 | +1. Poll the primary pod's metrics endpoint every 30s(default) - configurable |
| 95 | +2. Update the `trainer.opendatahub.io/trainerStatus` annotation with: |
| 96 | + - Progress percentage |
| 97 | + - Current step/epoch |
| 98 | + - Loss and learning rate |
| 99 | + - Time elapsed/remaining |
| 100 | + - Custom metrics |
| 101 | +3. Capture final status when job completes |
| 102 | + |
| 103 | +## Development |
| 104 | + |
| 105 | +### Running Tests |
| 106 | + |
| 107 | +```bash |
| 108 | +go test ./pkg/rhai/... |
| 109 | +``` |
| 110 | + |
| 111 | +### Adding New RHAI Features |
| 112 | + |
| 113 | +1. Create new package under `pkg/rhai/yourfeature/` |
| 114 | +2. Add controller wrapper if needed in `pkg/rhai/controller/` |
| 115 | +3. Update `pkg/rhai/setup.go` to register the feature |
| 116 | +4. Add manifest patches in `manifests/rhoai/` |
| 117 | +5. Document in this README |
| 118 | + |
| 119 | +## Maintenance |
| 120 | + |
| 121 | +When rebasing from upstream: |
| 122 | +1. Pull upstream changes: `git pull upstream master` |
| 123 | +2. Rebase: `git rebase upstream/master` |
| 124 | +3. `pkg/rhai/` should auto-merge (no conflicts expected) |
| 125 | +4. Review controller integration in `main.go` if base controller changed |
| 126 | +5. Run tests: `make test` |
0 commit comments