Skip to content

Commit cc56232

Browse files
committed
docs: update documentation for optional feature gate infrastructure
Updated documentation to reflect the new optional feature gate infrastructure: - Updated feature-gates.md to explain optional nature and new CLI flags - Added note about --with-feature-gates flag in quick-start.md - Added examples to CLI help text for both init and create api commands - Clarified auto-detection behavior and when infrastructure is generated - Updated troubleshooting section with new flag usage The documentation now clearly explains: 1. Feature gates are opt-in rather than always generated 2. Three ways to enable: explicit flags, auto-detection, or marker discovery 3. Better UX through conditional scaffolding
1 parent 1105b60 commit cc56232

File tree

4 files changed

+65
-8
lines changed

4 files changed

+65
-8
lines changed

docs/book/src/quick-start.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,23 @@ Run the following command to create a new API (group/version) as `webapp/v1` and
7474
kubebuilder create api --group webapp --version v1 --kind Guestbook
7575
```
7676

77+
<aside class="note">
78+
<h1>Feature Gates (Optional)</h1>
79+
80+
If you plan to use experimental features with feature gates, you can include the infrastructure during project creation:
81+
82+
```bash
83+
# Initialize project with feature gate support
84+
kubebuilder init --domain my.domain --repo my.domain/guestbook --with-feature-gates
85+
86+
# Or add feature gate support when creating APIs
87+
kubebuilder create api --group webapp --version v1 --kind Guestbook --with-feature-gates
88+
```
89+
90+
Feature gate infrastructure is only generated when explicitly requested or when `+feature-gate` markers are detected in your API types. See the [Feature Gates reference](/reference/markers/feature-gates.md) for more details.
91+
92+
</aside>
93+
7794
<aside class="note">
7895
<h1>Press Options</h1>
7996

docs/book/src/reference/markers/feature-gates.md

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,26 @@
22

33
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.
44

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+
57
## Quick Start
68

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+
725
### Marking Fields
826

927
```go
@@ -39,6 +57,13 @@ Feature gates provide a mechanism to:
3957
- Maintain backward compatibility during API evolution
4058
- Test experimental functionality safely in production environments
4159

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+
4267
## Usage
4368

4469
### Marking Fields with Feature Gates
@@ -75,9 +100,13 @@ Feature gates are validated for proper format:
75100

76101
Kubebuilder automatically discovers feature gates from your API types during scaffolding:
77102

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.
81110

82111
```go
83112
// Generated in internal/featuregates/featuregates.go
@@ -233,20 +262,25 @@ spec:
233262
234263
### Common Issues
235264
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**
237271
- 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
239273
- Check that the marker follows the correct format: `// +feature-gate gate-name`
240274

241-
2. **Invalid feature gate name**
275+
3. **Invalid feature gate name**
242276
- Use only lowercase letters, numbers, and hyphens
243277
- Examples: `experimental-bar`, `alpha-feature-v2`
244278

245-
3. **Validation errors**
279+
4. **Validation errors**
246280
- Check that all specified gates are discovered in your API types
247281
- Verify syntax: `gate1=true,gate2=false` (no spaces around `=`)
248282

249-
4. **Controller not recognizing feature gates**
283+
5. **Controller not recognizing feature gates**
250284
- Ensure `cmd/main.go` includes the generated feature gate initialization
251285
- Verify that `internal/featuregates/featuregates.go` is properly generated
252286

pkg/plugins/golang/v4/api.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ make generate will be run.
7575
subcmdMeta.Examples = fmt.Sprintf(` # Create a frigates API with Group: ship, Version: v1beta1 and Kind: Frigate
7676
%[1]s create api --group ship --version v1beta1 --kind Frigate
7777
78+
# Create an API with feature gate infrastructure for experimental features
79+
%[1]s create api --group webapp --version v1 --kind Guestbook --with-feature-gates
80+
7881
# Edit the API Scheme
7982
8083
nano api/v1beta1/frigate_types.go

pkg/plugins/golang/v4/init.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ func (p *initSubcommand) UpdateMetadata(cliMeta plugin.CLIMetadata, subcmdMeta *
7575
7676
# Initialize a new project defining a specific project version
7777
%[1]s init --plugins go/v4 --project-version 3
78+
79+
# Initialize a new project with feature gate infrastructure for experimental features
80+
%[1]s init --plugins go/v4 --domain example.org --with-feature-gates
7881
`, cliMeta.CommandName)
7982
}
8083

0 commit comments

Comments
 (0)