ignore template comments, fix bad test data

Signed-off-by: Matt Butcher <matt.butcher@microsoft.com>
pull/8043/head
Matt Butcher 5 years ago
parent b6a3b5fa93
commit 43e48c75c7
No known key found for this signature in database
GPG Key ID: DCD5F5E5EF32C345

@ -377,7 +377,7 @@ const defaultNotes = `1. Get the application URL by running these commands:
{{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "<CHARTNAME>.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "<CHARTNAME>.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "<CHARTNAME>.fullname" . }} --template "{{ "{{ range (index .status.loadBalancer.ingress 0) }}{{ . }}{{ end }}" }}")
echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "<CHARTNAME>.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")

@ -188,10 +188,16 @@ func validateNoReleaseTime(manifest []byte) error {
// TODO: I strongly suspect that there are better regexps than these two.
var (
badTplStart = regexp.MustCompile(`{{-?[^-\s]+`)
badTplEnd = regexp.MustCompile(`[^\s-]+-?}}`)
badTplStart = regexp.MustCompile(`{{-?[^-\s\/]+`)
badTplEnd = regexp.MustCompile(`[^\s-\/]+-?}}`)
)
// validateWhitespaceAroundTemplateDirectives checks for formatting errors on tpl directives
//
// The recommendation is that templates add at least one whitespace character between the
// directive marker ({{ or {{-) and the directive. This enforces that.
//
// See https://github.com/helm/helm/issues/5763
func validateWhitespaceAroundTemplateDirectives(template string) error {
badMatches := []string{}
if matches := badTplStart.FindAllString(template, 10); matches != nil {

@ -244,6 +244,7 @@ func TestValidateWhitespaceAroundTemplateDirectives(t *testing.T) {
`{{ legal }}{{illegal }}`: false,
`{{ legal }}{{- legal -}}`: true,
"{{\nlegal\n}}": true,
"{{/* comment */}}": true,
} {
if err := validateWhitespaceAroundTemplateDirectives(example); (err == nil) != success {
st := "failure"

@ -2,7 +2,7 @@
{{/*
Expand the name of the chart.
*/}}
{{define "name"}}{{default "nginx" .Values.nameOverride | trunc 63 | trimSuffix "-" }}{{end}}
{{ define "name" }}{{ default "nginx" .Values.nameOverride | trunc 63 | trimSuffix "-" }}{{ end }}
{{/*
Create a default fully qualified app name.
@ -10,7 +10,7 @@ Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this
(by the DNS naming spec).
*/}}
{{define "fullname"}}
{{ define "fullname" }}
{{- $name := default "nginx" .Values.nameOverride -}}
{{printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{end}}
{{ printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{ end }}

@ -7,13 +7,13 @@ metadata:
labels:
app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
app.kubernetes.io/instance: {{ .Release.Name | quote }}
helm.sh/chart: "{{.Chart.Name}}-{{.Chart.Version}}"
helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
kubeVersion: {{ .Capabilities.KubeVersion.Major }}
spec:
ports:
- port: {{default 80 .Values.httpPort | quote}}
- port: {{ default 80 .Values.httpPort | quote }}
targetPort: 80
protocol: TCP
name: http
selector:
app.kubernetes.io/name: {{template "fullname" .}}
app.kubernetes.io/name: {{ template "fullname" . }}

Loading…
Cancel
Save