Skip to content

Commit d795612

Browse files
feat(cli): add docs for beta lint cli command
Signed-off-by: undefinedhuman <[email protected]>
1 parent dc192ed commit d795612

File tree

1 file changed

+161
-0
lines changed

1 file changed

+161
-0
lines changed

content/master/cli/command-reference.md

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,4 +1093,165 @@ crossplane beta validate schema resources.yaml
10931093
Total 5 resources: 0 missing schemas, 4 success cases, 1 failure cases
10941094
```
10951095

1096+
### beta lint
10961097

1098+
The `crossplane beta lint` command checks [composite resource definitions]({{<ref "../concepts/composite-resource-definitions">}})
1099+
against a set of best practices. These rules help ensure that your XRDs are well-formed and follow Crossplane's API design guidelines.
1100+
1101+
{{< hint "note" >}}
1102+
The `crossplane beta lint` command performs all checks offline.
1103+
1104+
A Kubernetes cluster running Crossplane isn't required.
1105+
{{< /hint >}}
1106+
1107+
### Flags
1108+
1109+
{{< table "table table-sm table-striped" >}}
1110+
| Short flag | Long flag | Description |
1111+
| ------------ | ------------------ | ------------------------------------------------------------------------ |
1112+
| `-h` | `--help` | Show context sensitive help. |
1113+
| `-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):
1233+
1234+
```shell
1235+
crossplane beta lint my-xrd.yaml --output=json
1236+
{
1237+
"summary": {
1238+
"valid": false,
1239+
"total": 3,
1240+
"errors": 0,
1241+
"warnings": 3
1242+
},
1243+
"issues": [
1244+
{
1245+
"id": "XRD001",
1246+
"name": "xdatabases.custom-api.example.org",
1247+
"line": 20,
1248+
"error": false,
1249+
"reference": "https://github.com/kubernetes/community/blob/master/contributors/devel/sig-archi
1250+
tecture/api-conventions.md#primitive-types",
1251+
"message": "Boolean field detected at path spec.versions[0].schema.openAPIV3Schema.properties.
1252+
spec.properties.enabled — consider using an enum instead for extensibility."
1253+
},
1254+
...
1255+
]
1256+
}
1257+
```

0 commit comments

Comments
 (0)