Skip to content

Commit af1dffb

Browse files
pedjakclaude
andauthored
docs: add API conventions and deprecation guidance to AGENTS.md (#2763)
Add a section documenting OpenShift and Kubernetes API conventions that must be followed for API changes, including the deprecation pattern for CRD fields. Signed-off-by: Predrag Knezevic <pknezevi@redhat.com> Co-authored-by: Claude <noreply@anthropic.com>
1 parent 8807a64 commit af1dffb

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

AGENTS.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,40 @@ Two manifest variants exist:
207207
- **Standard:** Production-ready features
208208
- **Experimental:** Features under development/testing (includes `ClusterObjectSet` API)
209209

210+
### API Conventions
211+
212+
API changes in `api/v1/*_types.go` must follow the [OpenShift API conventions](https://github.com/openshift/enhancements/blob/master/dev-guide/api-conventions.md) in addition to upstream [Kubernetes API conventions](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md).
213+
214+
After modifying API types, run `make generate manifests crd-ref-docs` to regenerate DeepCopy/ApplyConfiguration code, CRDs, reference docs, and manifests. Run `make lint-api-diff` to validate changes against kube-api-linter.
215+
216+
**Deprecating fields:** Follow Go and OpenShift conventions (see [openshift/api](https://github.com/openshift/api) for examples):
217+
218+
```go
219+
type ExampleConfig struct {
220+
// value holds some value.
221+
Value string `json:"value"`
222+
}
223+
224+
// Deprecated: structField is no longer used and will be removed in a future release.
225+
// Explanation of why and what replaces it.
226+
//
227+
// +optional
228+
StructField ExampleConfig `json:"structField,omitzero"`
229+
230+
// Deprecated: scalarField is no longer used and will be removed in a future release.
231+
// Explanation of why and what replaces it.
232+
//
233+
// +optional
234+
ScalarField string `json:"scalarField,omitempty"`
235+
```
236+
237+
- Use `Deprecated:` with capital D and colon (Go convention, recognized by godoc and staticcheck)
238+
- Use the lowercase JSON field name (camelCase) in doc comments, not the Go PascalCase identifier — doc comments are surfaced to end users via `oc explain` and generated API docs
239+
- Deprecated fields must be `+optional`, never `+required`
240+
- Do not use pointers for optional struct fields (OpenShift convention); use value types with `omitzero`
241+
- Use `omitzero` in the JSON tag for struct types, `omitempty` for scalar types (string, int, bool)
242+
- For intentional reads of deprecated fields (e.g. deprecation warnings), add `//nolint:staticcheck` with a reason
243+
210244
---
211245

212246
## Git Workflows

0 commit comments

Comments
 (0)