Fix vanishing empty lines

Signed-off-by: Matheus Pimenta <matheuscscp@gmail.com>
release-4.2
Matheus Pimenta 2 months ago committed by George Jenkins
parent 43e8b7feec
commit 83a8b70ffc
No known key found for this signature in database
GPG Key ID: D79D67C9EC016739

@ -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.
// //

@ -73,7 +73,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",
}, },
}, },
{ {
@ -109,7 +109,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:
@ -328,8 +329,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: `
@ -353,7 +354,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:
@ -386,7 +388,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:
@ -431,7 +436,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:
@ -459,11 +465,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:
@ -492,11 +500,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:

@ -1230,7 +1230,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
@ -1270,7 +1270,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
@ -1311,7 +1311,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
@ -1474,7 +1474,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
@ -1514,8 +1514,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
@ -1555,8 +1556,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.
// //

@ -73,7 +73,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",
}, },
}, },
{ {
@ -109,7 +109,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:
@ -328,8 +329,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: `
@ -353,7 +354,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:
@ -386,7 +388,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:
@ -431,7 +436,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:
@ -459,11 +465,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:
@ -492,11 +500,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