Skip to content

Commit 42ad272

Browse files
committed
Update guidelines with YAML formatting
1 parent 5e3c4cc commit 42ad272

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
@@ -917,8 +917,7 @@ $ oc get endpoints --all-namespaces --template \
917917
# subscription-manager list
918918
----
919919

920-
* For snippets or sections of a larger file, use an ellipsis (`...`) to show that
921-
the file continues before and/or after the quoted block:
920+
* For snippets or sections of a file, use an ellipsis (`...`) to show that the file continues before and/or after the quoted block.
922921
+
923922
----
924923
apiVersion: v1
@@ -932,11 +931,10 @@ metadata:
932931
or
933932
+
934933
----
934+
Name: ci-ln-iyhx092-f76d1-nvdfm-worker-b-wln2l
935+
Roles: worker
935936
...
936-
spec:
937-
containers:
938-
- args:
939-
image: k8s.gcr.io/liveness
937+
Taints: node-role.kubernetes.io/infra:NoSchedule
940938
...
941939
----
942940
+
@@ -956,6 +954,127 @@ can be updated to use `jsonpath` instead:
956954
$ oc get clusterversion -o jsonpath='{.items[0].spec}{"\n"}'
957955
----
958956

957+
* For Bash "here" documents use `[source,terminal]`, such as the following example:
958+
+
959+
....
960+
[source,terminal]
961+
----
962+
$ cat <<EOF| oc create -f -
963+
apiVersion: v1
964+
kind: Pod
965+
metadata:
966+
name: mlistener
967+
labels:
968+
app: multicast-verify
969+
EOF
970+
----
971+
....
972+
973+
* For the output of commands use `[source,text]`, such as with the following example output from the `oc describe <pural> <object>` command:
974+
+
975+
....
976+
[source,text]
977+
----
978+
Name: node1.example.com
979+
Roles: worker
980+
Labels: beta.kubernetes.io/arch=amd64
981+
...
982+
Annotations: cluster.k8s.io/machine: openshift-machine-api/ahardin-worker-us-east-2a-q5dzc
983+
...
984+
CreationTimestamp: Wed, 13 Feb 2019 11:05:57 -0500
985+
----
986+
....
987+
988+
=== YAML formatting for Kubernetes and OpenShift API objects
989+
The following formatting guidelines apply to YAML manifests, but do not apply to the installation configuration YAML specified by `install-config.yaml`.
990+
991+
When possible, ensure that YAML is valid in a running cluster. You can validate YAML with `oc apply` with the following invocation:
992+
993+
----
994+
$ oc apply -f test.yaml --dry-run=client
995+
----
996+
997+
==== Required fields
998+
999+
- Include the `apiVersion` and `kind` so that a user always knows the context of the YAML.
1000+
- Include the full hierarchy to a deeply nested key.
1001+
- 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`.
1002+
1003+
.Example API object in the global scope
1004+
----
1005+
apiVersion: config.openshift.io/v1
1006+
kind: Scheduler
1007+
metadata:
1008+
name: cluster
1009+
...
1010+
spec:
1011+
defaultNodeSelector: node-role.kubernetes.io/app=
1012+
...
1013+
----
1014+
1015+
.Example deeply nested key with full context for `.ports` array
1016+
----
1017+
apiVersion: v1
1018+
kind: Pod
1019+
metadata:
1020+
name: pod1
1021+
namespace: default
1022+
spec:
1023+
containers:
1024+
- name: web
1025+
image: nginx
1026+
ports:
1027+
- name: web
1028+
containerPort: 80
1029+
protocol: TCP
1030+
----
1031+
1032+
==== Formatting
1033+
Use the following conventions govern the layout of YAML for API objects.
1034+
1035+
- Begin YAML at the beginning of the left margin.
1036+
- Use two-space indentation.
1037+
- Indent arrays at the same depth as the parent field.
1038+
- Include a space immediately after the colon for keys.
1039+
- 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:
1040+
+
1041+
----
1042+
fieldName: |-
1043+
This is a string.
1044+
And it can be on multiple lines.
1045+
----
1046+
- When truncating YAML, always precede an ellipsis with a pound so that the YAML is valid.
1047+
1048+
.Example with array indentation flush with parent field
1049+
----
1050+
apiVersion: v1
1051+
kind: Pod
1052+
metadata:
1053+
name: pod1
1054+
labels:
1055+
- key1: val1
1056+
- key2: val2
1057+
spec:
1058+
...
1059+
----
1060+
1061+
.Example with block string for annotation
1062+
----
1063+
apiVersion: v1
1064+
kind: Pod
1065+
metadata:
1066+
name: pod1
1067+
annotations:
1068+
k8s.v1.cni.cncf.io/networks: |-
1069+
[
1070+
{
1071+
"name": "net"
1072+
}
1073+
]
1074+
spec:
1075+
...
1076+
----
1077+
9591078
=== Inline code or commands
9601079
Do NOT show full commands or command syntax inline within a sentence. The next section covers how to show commands and command syntax.
9611080

0 commit comments

Comments
 (0)