Skip to content

Commit 6501dc2

Browse files
authored
Merge pull request #38812 from jboxman-rh/update-guidelines-for-yaml
Update guidelines with YAML formatting
2 parents 3fe4703 + 42ad272 commit 6501dc2

File tree

1 file changed

+125
-6
lines changed

1 file changed

+125
-6
lines changed

contributing_to_docs/doc_guidelines.adoc

Lines changed: 125 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -978,8 +978,7 @@ $ oc get endpoints --all-namespaces --template \
978978
# subscription-manager list
979979
----
980980

981-
* For snippets or sections of a larger file, use an ellipsis (`...`) to show that
982-
the file continues before and/or after the quoted block:
981+
* For snippets or sections of a file, use an ellipsis (`...`) to show that the file continues before and/or after the quoted block.
983982
+
984983
----
985984
apiVersion: v1
@@ -993,11 +992,10 @@ metadata:
993992
or
994993
+
995994
----
995+
Name: ci-ln-iyhx092-f76d1-nvdfm-worker-b-wln2l
996+
Roles: worker
996997
...
997-
spec:
998-
containers:
999-
- args:
1000-
image: k8s.gcr.io/liveness
998+
Taints: node-role.kubernetes.io/infra:NoSchedule
1001999
...
10021000
----
10031001
+
@@ -1017,6 +1015,127 @@ can be updated to use `jsonpath` instead:
10171015
$ oc get clusterversion -o jsonpath='{.items[0].spec}{"\n"}'
10181016
----
10191017

1018+
* For Bash "here" documents use `[source,terminal]`, such as the following example:
1019+
+
1020+
....
1021+
[source,terminal]
1022+
----
1023+
$ cat <<EOF| oc create -f -
1024+
apiVersion: v1
1025+
kind: Pod
1026+
metadata:
1027+
name: mlistener
1028+
labels:
1029+
app: multicast-verify
1030+
EOF
1031+
----
1032+
....
1033+
1034+
* For the output of commands use `[source,text]`, such as with the following example output from the `oc describe <pural> <object>` command:
1035+
+
1036+
....
1037+
[source,text]
1038+
----
1039+
Name: node1.example.com
1040+
Roles: worker
1041+
Labels: beta.kubernetes.io/arch=amd64
1042+
...
1043+
Annotations: cluster.k8s.io/machine: openshift-machine-api/ahardin-worker-us-east-2a-q5dzc
1044+
...
1045+
CreationTimestamp: Wed, 13 Feb 2019 11:05:57 -0500
1046+
----
1047+
....
1048+
1049+
=== YAML formatting for Kubernetes and OpenShift API objects
1050+
The following formatting guidelines apply to YAML manifests, but do not apply to the installation configuration YAML specified by `install-config.yaml`.
1051+
1052+
When possible, ensure that YAML is valid in a running cluster. You can validate YAML with `oc apply` with the following invocation:
1053+
1054+
----
1055+
$ oc apply -f test.yaml --dry-run=client
1056+
----
1057+
1058+
==== Required fields
1059+
1060+
- Include the `apiVersion` and `kind` so that a user always knows the context of the YAML.
1061+
- Include the full hierarchy to a deeply nested key.
1062+
- For objects that are in the global scope, such as for `config.openshift.io` API group, always include the `metadata.name` for the object, which is usually `cluster`.
1063+
1064+
.Example API object in the global scope
1065+
----
1066+
apiVersion: config.openshift.io/v1
1067+
kind: Scheduler
1068+
metadata:
1069+
name: cluster
1070+
...
1071+
spec:
1072+
defaultNodeSelector: node-role.kubernetes.io/app=
1073+
...
1074+
----
1075+
1076+
.Example deeply nested key with full context for `.ports` array
1077+
----
1078+
apiVersion: v1
1079+
kind: Pod
1080+
metadata:
1081+
name: pod1
1082+
namespace: default
1083+
spec:
1084+
containers:
1085+
- name: web
1086+
image: nginx
1087+
ports:
1088+
- name: web
1089+
containerPort: 80
1090+
protocol: TCP
1091+
----
1092+
1093+
==== Formatting
1094+
Use the following conventions govern the layout of YAML for API objects.
1095+
1096+
- Begin YAML at the beginning of the left margin.
1097+
- Use two-space indentation.
1098+
- Indent arrays at the same depth as the parent field.
1099+
- Include a space immediately after the colon for keys.
1100+
- Use block style for complex strings, such as embedded JSON or text blocks. You can enable block style by specifying `|` or `|-` after a field and indenting the field content by two spaces, such as in the following example:
1101+
+
1102+
----
1103+
fieldName: |-
1104+
This is a string.
1105+
And it can be on multiple lines.
1106+
----
1107+
- When truncating YAML, always precede an ellipsis with a pound so that the YAML is valid.
1108+
1109+
.Example with array indentation flush with parent field
1110+
----
1111+
apiVersion: v1
1112+
kind: Pod
1113+
metadata:
1114+
name: pod1
1115+
labels:
1116+
- key1: val1
1117+
- key2: val2
1118+
spec:
1119+
...
1120+
----
1121+
1122+
.Example with block string for annotation
1123+
----
1124+
apiVersion: v1
1125+
kind: Pod
1126+
metadata:
1127+
name: pod1
1128+
annotations:
1129+
k8s.v1.cni.cncf.io/networks: |-
1130+
[
1131+
{
1132+
"name": "net"
1133+
}
1134+
]
1135+
spec:
1136+
...
1137+
----
1138+
10201139
=== Inline code or commands
10211140
Do NOT show full commands or command syntax inline within a sentence. The next section covers how to show commands and command syntax.
10221141

0 commit comments

Comments
 (0)