|
2 | 2 |
|
3 | 3 | Feature gates allow you to enable or disable experimental features in your Kubebuilder controllers. This is similar to how Kubernetes core uses feature gates to manage experimental functionality.
|
4 | 4 |
|
| 5 | +> **Note**: Feature gate infrastructure is **optional** and only generated when explicitly requested or detected. This provides a better user experience by avoiding unnecessary scaffolding. |
| 6 | +
|
5 | 7 | ## Quick Start
|
6 | 8 |
|
| 9 | +### Enabling Feature Gate Infrastructure |
| 10 | + |
| 11 | +Feature gate infrastructure can be enabled in two ways: |
| 12 | + |
| 13 | +1. **During project initialization** with the `--with-feature-gates` flag: |
| 14 | + ```bash |
| 15 | + kubebuilder init --domain my.domain --repo my.domain/project --with-feature-gates |
| 16 | + ``` |
| 17 | + |
| 18 | +2. **During API creation** when adding experimental fields: |
| 19 | + ```bash |
| 20 | + kubebuilder create api --group webapp --version v1 --kind Guestbook --with-feature-gates |
| 21 | + ``` |
| 22 | + |
| 23 | +3. **Auto-detection**: If you add `+feature-gate` markers to your API types and run `kubebuilder create api`, the infrastructure will be automatically generated. |
| 24 | + |
7 | 25 | ### Marking Fields
|
8 | 26 |
|
9 | 27 | ```go
|
@@ -39,6 +57,13 @@ Feature gates provide a mechanism to:
|
39 | 57 | - Maintain backward compatibility during API evolution
|
40 | 58 | - Test experimental functionality safely in production environments
|
41 | 59 |
|
| 60 | +**Infrastructure Generation**: Feature gate infrastructure is only generated when: |
| 61 | +- The `--with-feature-gates` flag is used with `kubebuilder init` or `kubebuilder create api` |
| 62 | +- Auto-detected when existing feature gate infrastructure is found in the project |
| 63 | +- Auto-detected when `+feature-gate` markers are found in API types during `kubebuilder create api` |
| 64 | + |
| 65 | +This optional approach ensures projects only include feature gate infrastructure when actually needed. |
| 66 | + |
42 | 67 | ## Usage
|
43 | 68 |
|
44 | 69 | ### Marking Fields with Feature Gates
|
@@ -75,9 +100,13 @@ Feature gates are validated for proper format:
|
75 | 100 |
|
76 | 101 | Kubebuilder automatically discovers feature gates from your API types during scaffolding:
|
77 | 102 |
|
78 |
| -1. **During `kubebuilder create api`**: Scans for existing `+feature-gate` markers |
79 |
| -2. **Generates `internal/featuregates/featuregates.go`**: Contains all discovered gates |
80 |
| -3. **Updates `cmd/main.go`**: Adds `--feature-gates` flag support |
| 103 | +1. **During `kubebuilder init --with-feature-gates`**: Generates infrastructure for future use |
| 104 | +2. **During `kubebuilder create api --with-feature-gates`**: Generates infrastructure and scans for markers |
| 105 | +3. **During `kubebuilder create api`**: Auto-detects existing infrastructure or discovers new `+feature-gate` markers |
| 106 | +4. **Generates `internal/featuregates/featuregates.go`**: Contains all discovered gates |
| 107 | +5. **Updates `cmd/main.go`**: Adds `--feature-gates` flag support |
| 108 | + |
| 109 | +**Important**: If no `--with-feature-gates` flag is provided and no feature gate infrastructure exists, it will only be generated if `+feature-gate` markers are found in your API types. |
81 | 110 |
|
82 | 111 | ```go
|
83 | 112 | // Generated in internal/featuregates/featuregates.go
|
@@ -233,20 +262,25 @@ spec:
|
233 | 262 |
|
234 | 263 | ### Common Issues
|
235 | 264 |
|
236 |
| -1. **Feature gate not discovered** |
| 265 | +1. **Feature gate infrastructure not generated** |
| 266 | + - Use `--with-feature-gates` flag explicitly: `kubebuilder init --with-feature-gates` or `kubebuilder create api --with-feature-gates` |
| 267 | + - Add `+feature-gate` markers to your API types and run `kubebuilder create api` (auto-detection) |
| 268 | + - Ensure you're in a project directory with existing feature gate infrastructure |
| 269 | + |
| 270 | +2. **Feature gate not discovered** |
237 | 271 | - Ensure the `+feature-gate` marker is on the line immediately before the field
|
238 |
| - - Re-run `kubebuilder create api` to regenerate feature gate files |
| 272 | + - Re-run `kubebuilder create api --with-feature-gates` to regenerate feature gate files |
239 | 273 | - Check that the marker follows the correct format: `// +feature-gate gate-name`
|
240 | 274 |
|
241 |
| -2. **Invalid feature gate name** |
| 275 | +3. **Invalid feature gate name** |
242 | 276 | - Use only lowercase letters, numbers, and hyphens
|
243 | 277 | - Examples: `experimental-bar`, `alpha-feature-v2`
|
244 | 278 |
|
245 |
| -3. **Validation errors** |
| 279 | +4. **Validation errors** |
246 | 280 | - Check that all specified gates are discovered in your API types
|
247 | 281 | - Verify syntax: `gate1=true,gate2=false` (no spaces around `=`)
|
248 | 282 |
|
249 |
| -4. **Controller not recognizing feature gates** |
| 283 | +5. **Controller not recognizing feature gates** |
250 | 284 | - Ensure `cmd/main.go` includes the generated feature gate initialization
|
251 | 285 | - Verify that `internal/featuregates/featuregates.go` is properly generated
|
252 | 286 |
|
|
0 commit comments