i've came across 2 types of syntax for creating configmaps from files in kubernetes.
first one ;
apiVersion: v1
data:
file1.yaml: |+
parameter1=value1
kind: ConfigMap
metadata:
name: my-configmap
second one ;
apiVersion: v1
data:
file1.yaml: | -
parameter1=value1
kind: ConfigMap
metadata:
name: my-configmap
what is the difference between |+ and |- ?
These are block chomping indicators, they influence how the trailing newlines in a literal (|
) or folded (>
) block style scalar are handled.
By default, if there is no +
or -
after the |
(or >
), those trailing newlines are clipped, i.e. the scalar will be loaded as a string ending in a single newline, independent of whether there are multiple empty lines at the end of the scalar.
If +
is specified, each newline is kept, so the scalar will have one extra newline for every empty line before the outdent for the next node (in addition to the one ending the last non-empty line)
If -
is specified, the scalar is stripped and will not end in a newline, even if there are multiple empty lines at the end of the block style scalar.
Please note that your second example is invalid, the production rules indicate that the chomping indicator can only be separated from the |
by the indentation indicator (i.e. number, if specified) and that no space is allowed between |
and -
.
This is the block chomping indicator.
Directly quoting from the link:
The chomping indicator controls what should happen with newlines at the end of the string. The default, clip, puts a single newline at the end of the string. To remove all newlines, strip them by putting a minus sign (-) after the style indicator. Both clip and strip ignore how many newlines are actually at the end of the block; to keep them all put a plus sign (+) after the style indicator.
This means that for:
apiVersion: v1
data:
file1.yaml: |-
parameter1=value1
kind: ConfigMap
metadata:
name: my-configmap
file1.yaml will have the value:
parameter1=value1
For:
apiVersion: v1
data:
file1.yaml: |+
parameter1=value1
kind: ConfigMap
metadata:
name: my-configmap
file1.yaml will have the value:
parameter1=value1 # line break
# line break
# line break