Merge pull request #32327 from fluxcd/fix-32326

Fix vanishing empty lines
pull/32370/head
George Jenkins 2 months ago committed by GitHub
commit 9c373bf4fc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -34,7 +34,7 @@ type SimpleHead struct {
} `json:"metadata,omitempty"` } `json:"metadata,omitempty"`
} }
var sep = regexp.MustCompile("(?:^|\\s*\n)---\\s*") var sep = regexp.MustCompile(`(?m)^---[ \t]*`)
// SplitManifests takes a manifest string and returns a map containing individual manifests. // SplitManifests takes a manifest string and returns a map containing individual manifests.
// //

@ -74,7 +74,7 @@ spec:
name: "whitespace-only doc after separator is skipped", name: "whitespace-only doc after separator is skipped",
input: "---\napiVersion: v1\nkind: ConfigMap\nmetadata:\n name: cm1\n---\n \n", input: "---\napiVersion: v1\nkind: ConfigMap\nmetadata:\n name: cm1\n---\n \n",
expected: map[string]string{ expected: map[string]string{
"manifest-0": "apiVersion: v1\nkind: ConfigMap\nmetadata:\n name: cm1", "manifest-0": "apiVersion: v1\nkind: ConfigMap\nmetadata:\n name: cm1\n",
}, },
}, },
{ {
@ -110,7 +110,8 @@ metadata:
"manifest-0": `apiVersion: v1 "manifest-0": `apiVersion: v1
kind: ConfigMap kind: ConfigMap
metadata: metadata:
name: cm1`, name: cm1
`,
"manifest-1": `apiVersion: v1 "manifest-1": `apiVersion: v1
kind: ConfigMap kind: ConfigMap
metadata: metadata:
@ -329,8 +330,8 @@ data:
}, },
}, },
// Multi-doc with block scalars: the regex consumes \s*\n before ---, // Multi-doc with block scalars: the separator regex preserves trailing
// so trailing newlines from non-last docs are stripped. // newlines from non-last documents.
{ {
name: "multi-doc block scalar clip (|) before separator", name: "multi-doc block scalar clip (|) before separator",
input: ` input: `
@ -354,7 +355,8 @@ metadata:
name: test name: test
data: data:
key: | key: |
hello`, hello
`,
"manifest-1": `apiVersion: v1 "manifest-1": `apiVersion: v1
kind: ConfigMap kind: ConfigMap
metadata: metadata:
@ -387,7 +389,10 @@ metadata:
name: test name: test
data: data:
key: |+ key: |+
hello`, hello
`,
"manifest-1": `apiVersion: v1 "manifest-1": `apiVersion: v1
kind: ConfigMap kind: ConfigMap
metadata: metadata:
@ -432,7 +437,8 @@ metadata:
"manifest-0": `apiVersion: v1 "manifest-0": `apiVersion: v1
kind: ConfigMap kind: ConfigMap
metadata: metadata:
name: cm1`, name: cm1
`,
"manifest-1": `apiVersion: v1 "manifest-1": `apiVersion: v1
kind: ConfigMap kind: ConfigMap
metadata: metadata:
@ -460,11 +466,13 @@ metadata:
"manifest-0": `apiVersion: v1 "manifest-0": `apiVersion: v1
kind: ConfigMap kind: ConfigMap
metadata: metadata:
name: cm1`, name: cm1
`,
"manifest-1": `apiVersion: v1 "manifest-1": `apiVersion: v1
kind: ConfigMap kind: ConfigMap
metadata: metadata:
name: cm2`, name: cm2
`,
"manifest-2": `apiVersion: v1 "manifest-2": `apiVersion: v1
kind: ConfigMap kind: ConfigMap
metadata: metadata:
@ -493,11 +501,13 @@ metadata:
"manifest-0": `apiVersion: v1 "manifest-0": `apiVersion: v1
kind: ConfigMap kind: ConfigMap
metadata: metadata:
name: cm1`, name: cm1
`,
"manifest-1": `apiVersion: v1 "manifest-1": `apiVersion: v1
kind: ConfigMap kind: ConfigMap
metadata: metadata:
name: cm2`, name: cm2
`,
"manifest-2": `apiVersion: v1 "manifest-2": `apiVersion: v1
kind: ConfigMap kind: ConfigMap
metadata: metadata:

@ -1198,9 +1198,9 @@ data:
`, `,
}, },
// Multi-doc tests: block scalar doc is NOT the last document. // Multi-doc block scalar tests where the block scalar document is NOT the last:
// SplitManifests' regex consumes \s*\n before ---, so trailing // the separator regex does not consume trailing newlines, so YAML chomping
// newlines from non-last docs are always stripped. // indicators (|, |+, |-) are respected.
// | (clip) in multi-doc (first doc) // | (clip) in multi-doc (first doc)
{ {
@ -1229,7 +1229,7 @@ metadata:
annotations: annotations:
postrenderer.helm.sh/postrender-filename: 'templates/cm.yaml' postrenderer.helm.sh/postrender-filename: 'templates/cm.yaml'
data: data:
key: |- key: |
hello hello
--- ---
apiVersion: v1 apiVersion: v1
@ -1269,7 +1269,7 @@ metadata:
annotations: annotations:
postrenderer.helm.sh/postrender-filename: 'templates/cm.yaml' postrenderer.helm.sh/postrender-filename: 'templates/cm.yaml'
data: data:
key: |- key: |
hello hello
--- ---
apiVersion: v1 apiVersion: v1
@ -1310,7 +1310,7 @@ metadata:
annotations: annotations:
postrenderer.helm.sh/postrender-filename: 'templates/cm.yaml' postrenderer.helm.sh/postrender-filename: 'templates/cm.yaml'
data: data:
key: |- key: |
hello hello
--- ---
apiVersion: v1 apiVersion: v1
@ -1473,7 +1473,7 @@ metadata:
annotations: annotations:
postrenderer.helm.sh/postrender-filename: 'templates/cm.yaml' postrenderer.helm.sh/postrender-filename: 'templates/cm.yaml'
data: data:
key: |- key: |
hello hello
--- ---
apiVersion: v1 apiVersion: v1
@ -1513,8 +1513,9 @@ metadata:
annotations: annotations:
postrenderer.helm.sh/postrender-filename: 'templates/cm.yaml' postrenderer.helm.sh/postrender-filename: 'templates/cm.yaml'
data: data:
key: |- key: |+
hello hello
--- ---
apiVersion: v1 apiVersion: v1
kind: ConfigMap kind: ConfigMap
@ -1554,8 +1555,10 @@ metadata:
annotations: annotations:
postrenderer.helm.sh/postrender-filename: 'templates/cm.yaml' postrenderer.helm.sh/postrender-filename: 'templates/cm.yaml'
data: data:
key: |- key: |+
hello hello
--- ---
apiVersion: v1 apiVersion: v1
kind: ConfigMap kind: ConfigMap

@ -8,6 +8,8 @@ rules:
- apiGroups: [""] - apiGroups: [""]
resources: ["pods", "pods/exec", "pods/log"] resources: ["pods", "pods/exec", "pods/log"]
verbs: ["*"] verbs: ["*"]
--- ---
# Source: hello/templates/rbac # Source: hello/templates/rbac
apiVersion: rbac.authorization.k8s.io/v1 apiVersion: rbac.authorization.k8s.io/v1

@ -10,6 +10,8 @@ spec:
policyTypes: policyTypes:
- Egress - Egress
- Ingress - Ingress
--- ---
# Source: object-order/templates/01-a.yml # Source: object-order/templates/01-a.yml
# 2 # 2
@ -22,6 +24,8 @@ spec:
policyTypes: policyTypes:
- Egress - Egress
- Ingress - Ingress
--- ---
# Source: object-order/templates/01-a.yml # Source: object-order/templates/01-a.yml
# 3 # 3
@ -34,6 +38,8 @@ spec:
policyTypes: policyTypes:
- Egress - Egress
- Ingress - Ingress
--- ---
# Source: object-order/templates/02-b.yml # Source: object-order/templates/02-b.yml
# 5 # 5
@ -46,6 +52,8 @@ spec:
policyTypes: policyTypes:
- Egress - Egress
- Ingress - Ingress
--- ---
# Source: object-order/templates/02-b.yml # Source: object-order/templates/02-b.yml
# 7 # 7
@ -58,6 +66,8 @@ spec:
policyTypes: policyTypes:
- Egress - Egress
- Ingress - Ingress
--- ---
# Source: object-order/templates/02-b.yml # Source: object-order/templates/02-b.yml
# 8 # 8
@ -70,6 +80,8 @@ spec:
policyTypes: policyTypes:
- Egress - Egress
- Ingress - Ingress
--- ---
# Source: object-order/templates/02-b.yml # Source: object-order/templates/02-b.yml
# 9 # 9
@ -82,6 +94,8 @@ spec:
policyTypes: policyTypes:
- Egress - Egress
- Ingress - Ingress
--- ---
# Source: object-order/templates/02-b.yml # Source: object-order/templates/02-b.yml
# 10 # 10
@ -94,6 +108,8 @@ spec:
policyTypes: policyTypes:
- Egress - Egress
- Ingress - Ingress
--- ---
# Source: object-order/templates/02-b.yml # Source: object-order/templates/02-b.yml
# 11 # 11
@ -106,6 +122,8 @@ spec:
policyTypes: policyTypes:
- Egress - Egress
- Ingress - Ingress
--- ---
# Source: object-order/templates/02-b.yml # Source: object-order/templates/02-b.yml
# 12 # 12
@ -118,6 +136,8 @@ spec:
policyTypes: policyTypes:
- Egress - Egress
- Ingress - Ingress
--- ---
# Source: object-order/templates/02-b.yml # Source: object-order/templates/02-b.yml
# 13 # 13
@ -130,6 +150,8 @@ spec:
policyTypes: policyTypes:
- Egress - Egress
- Ingress - Ingress
--- ---
# Source: object-order/templates/02-b.yml # Source: object-order/templates/02-b.yml
# 14 # 14
@ -142,6 +164,8 @@ spec:
policyTypes: policyTypes:
- Egress - Egress
- Ingress - Ingress
--- ---
# Source: object-order/templates/02-b.yml # Source: object-order/templates/02-b.yml
# 15 (11th object within 02-b.yml, in order to test `SplitManifests` which assigns `manifest-10` # 15 (11th object within 02-b.yml, in order to test `SplitManifests` which assigns `manifest-10`
@ -190,3 +214,5 @@ spec:
policyTypes: policyTypes:
- Egress - Egress
- Ingress - Ingress

@ -8,6 +8,8 @@ rules:
- apiGroups: [""] - apiGroups: [""]
resources: ["pods"] resources: ["pods"]
verbs: ["get","list","watch"] verbs: ["get","list","watch"]
--- ---
# Source: subchart/templates/subdir/rolebinding.yaml # Source: subchart/templates/subdir/rolebinding.yaml
apiVersion: rbac.authorization.k8s.io/v1 apiVersion: rbac.authorization.k8s.io/v1
@ -22,3 +24,5 @@ subjects:
- kind: ServiceAccount - kind: ServiceAccount
name: subchart-sa name: subchart-sa
namespace: default namespace: default

@ -19,6 +19,7 @@ spec:
name: nginx name: nginx
selector: selector:
app.kubernetes.io/name: subchart app.kubernetes.io/name: subchart
--- ---
# Source: subchart/charts/subcharta/templates/service.yaml # Source: subchart/charts/subcharta/templates/service.yaml
apiVersion: v1 apiVersion: v1
@ -36,3 +37,5 @@ spec:
name: apache name: apache
selector: selector:
app.kubernetes.io/name: subcharta app.kubernetes.io/name: subcharta

@ -19,3 +19,4 @@ spec:
name: nginx name: nginx
selector: selector:
app.kubernetes.io/name: subchart app.kubernetes.io/name: subchart

@ -34,7 +34,7 @@ type SimpleHead struct {
} `json:"metadata,omitempty"` } `json:"metadata,omitempty"`
} }
var sep = regexp.MustCompile("(?:^|\\s*\n)---\\s*") var sep = regexp.MustCompile(`(?m)^---[ \t]*`)
// SplitManifests takes a manifest string and returns a map containing individual manifests. // SplitManifests takes a manifest string and returns a map containing individual manifests.
// //

@ -74,7 +74,7 @@ spec:
name: "whitespace-only doc after separator is skipped", name: "whitespace-only doc after separator is skipped",
input: "---\napiVersion: v1\nkind: ConfigMap\nmetadata:\n name: cm1\n---\n \n", input: "---\napiVersion: v1\nkind: ConfigMap\nmetadata:\n name: cm1\n---\n \n",
expected: map[string]string{ expected: map[string]string{
"manifest-0": "apiVersion: v1\nkind: ConfigMap\nmetadata:\n name: cm1", "manifest-0": "apiVersion: v1\nkind: ConfigMap\nmetadata:\n name: cm1\n",
}, },
}, },
{ {
@ -110,7 +110,8 @@ metadata:
"manifest-0": `apiVersion: v1 "manifest-0": `apiVersion: v1
kind: ConfigMap kind: ConfigMap
metadata: metadata:
name: cm1`, name: cm1
`,
"manifest-1": `apiVersion: v1 "manifest-1": `apiVersion: v1
kind: ConfigMap kind: ConfigMap
metadata: metadata:
@ -329,8 +330,8 @@ data:
}, },
}, },
// Multi-doc with block scalars: the regex consumes \s*\n before ---, // Multi-doc with block scalars: the separator regex preserves trailing
// so trailing newlines from non-last docs are stripped. // newlines from non-last documents.
{ {
name: "multi-doc block scalar clip (|) before separator", name: "multi-doc block scalar clip (|) before separator",
input: ` input: `
@ -354,7 +355,8 @@ metadata:
name: test name: test
data: data:
key: | key: |
hello`, hello
`,
"manifest-1": `apiVersion: v1 "manifest-1": `apiVersion: v1
kind: ConfigMap kind: ConfigMap
metadata: metadata:
@ -387,7 +389,10 @@ metadata:
name: test name: test
data: data:
key: |+ key: |+
hello`, hello
`,
"manifest-1": `apiVersion: v1 "manifest-1": `apiVersion: v1
kind: ConfigMap kind: ConfigMap
metadata: metadata:
@ -432,7 +437,8 @@ metadata:
"manifest-0": `apiVersion: v1 "manifest-0": `apiVersion: v1
kind: ConfigMap kind: ConfigMap
metadata: metadata:
name: cm1`, name: cm1
`,
"manifest-1": `apiVersion: v1 "manifest-1": `apiVersion: v1
kind: ConfigMap kind: ConfigMap
metadata: metadata:
@ -460,11 +466,13 @@ metadata:
"manifest-0": `apiVersion: v1 "manifest-0": `apiVersion: v1
kind: ConfigMap kind: ConfigMap
metadata: metadata:
name: cm1`, name: cm1
`,
"manifest-1": `apiVersion: v1 "manifest-1": `apiVersion: v1
kind: ConfigMap kind: ConfigMap
metadata: metadata:
name: cm2`, name: cm2
`,
"manifest-2": `apiVersion: v1 "manifest-2": `apiVersion: v1
kind: ConfigMap kind: ConfigMap
metadata: metadata:
@ -493,11 +501,13 @@ metadata:
"manifest-0": `apiVersion: v1 "manifest-0": `apiVersion: v1
kind: ConfigMap kind: ConfigMap
metadata: metadata:
name: cm1`, name: cm1
`,
"manifest-1": `apiVersion: v1 "manifest-1": `apiVersion: v1
kind: ConfigMap kind: ConfigMap
metadata: metadata:
name: cm2`, name: cm2
`,
"manifest-2": `apiVersion: v1 "manifest-2": `apiVersion: v1
kind: ConfigMap kind: ConfigMap
metadata: metadata:

Loading…
Cancel
Save