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
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
+
959
1078
=== Inline code or commands
960
1079
Do NOT show full commands or command syntax inline within a sentence. The next section covers how to show commands and command syntax.
0 commit comments