You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|`-o`|`--output`| Output format. Valid values are stdout (default) or json. |
1114
+
||`--skip-reference`| Skip printing the reference docs to the rule that was violated. |
1115
+
{{< /table >}}
1116
+
1117
+
#### Rule XRD001 - No boolean fields
1118
+
1119
+
Boolean fields are inflexible and cannot be extended. Replace them with enum-based strings so you can introduce additional states later.
1120
+
See [Kubernetes API conventions](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#primitive-types)
1121
+
1122
+
```yaml {label="Incorrect:"}
1123
+
# Removed for brevity
1124
+
properties:
1125
+
spec:
1126
+
type: object
1127
+
properties:
1128
+
enabled:
1129
+
type: boolean # flagged by XRD001
1130
+
```
1131
+
1132
+
```yaml {label="Best practice:"}
1133
+
# Removed for brevity
1134
+
properties:
1135
+
enabled:
1136
+
type: string
1137
+
enum:
1138
+
- Enabled
1139
+
- Disabled
1140
+
```
1141
+
1142
+
#### Rule XRD002 - Check for required fields
1143
+
1144
+
Marking fields as required up front forces every user to provide them and makes future changes risky - this rule flags any `required:`
1145
+
list in your XRD so you can decide if each field truly needs to be mandatory.
1146
+
1147
+
```yaml
1148
+
# Removed for brevity
1149
+
properties:
1150
+
spec:
1151
+
type: object
1152
+
properties:
1153
+
version:
1154
+
type: string
1155
+
required: # flagged by XRD002
1156
+
- version
1157
+
```
1158
+
1159
+
#### Rule XRD003 - Check for missing descriptions
1160
+
1161
+
Every property in your schema should include a description: so that `kubectl explain` and documentation generators can produce helpful output.
1162
+
1163
+
```yaml {label="Incorrect:"}
1164
+
# Removed for brevity
1165
+
versions:
1166
+
- name: v1alpha1
1167
+
schema:
1168
+
openAPIV3Schema:
1169
+
type: object
1170
+
properties:
1171
+
spec:
1172
+
type: object
1173
+
properties:
1174
+
version: # flagged by XRD003
1175
+
type: string
1176
+
1177
+
```
1178
+
1179
+
```yaml {label="Best practice:"}
1180
+
# Removed for brevity
1181
+
properties:
1182
+
spec:
1183
+
type: object
1184
+
properties:
1185
+
version:
1186
+
type: string
1187
+
description: |
1188
+
The version of the database engine to deploy.
1189
+
```
1190
+
1191
+
#### Ignore rules
1192
+
1193
+
If you need to opt out of a specific check for example, a field that you know is safe even though it violates a rule
1194
+
you can append a `# nolint <RULE_ID>` comment directly above the violating node or line:
1195
+
1196
+
```yaml {label="Missing description"}
1197
+
# Removed for brevity
1198
+
properties:
1199
+
spec:
1200
+
type: object
1201
+
properties:
1202
+
# nolint XRD003
1203
+
version:
1204
+
type: string
1205
+
```
1206
+
1207
+
```yaml {label="Boolean field"}
1208
+
# Removed for brevity
1209
+
properties:
1210
+
spec:
1211
+
type: object
1212
+
properties:
1213
+
version:
1214
+
# nolint XRD001
1215
+
type: boolean
1216
+
```
1217
+
1218
+
#### Example usage
1219
+
1220
+
Running the command on an XRD file:
1221
+
1222
+
```shell
1223
+
crossplane beta lint my-xrd.yaml
1224
+
xdatabases.custom-api.example.org:20 [XRD001] Boolean field detected at path spec.versions[0].schema.openAPIV3Schema.properties.spec.properties.enabled — consider using an enum instead for extensibility. More information: (https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#primitive-types)
1225
+
xdatabases.custom-api.example.org:25 [XRD002] Required field 'enabled' at path spec.versions[0].schema.openAPIV3Schema.properties.spec.required — consider making it optional with a default.
1226
+
Found 2 issues: 0 errors, 2 warnings
1227
+
exit status 2
1228
+
```
1229
+
1230
+
This outputs any violations of the best practices, along with references to the relevant guidelines for fixing them.
1231
+
1232
+
To integrate in CI or tooling, output as JSON (--output=json):
0 commit comments