Merge pull request #2188 from scottrigby/chartutil-ingress-example

chartutil create ingress example
pull/2273/head
Taylor Thomas 8 years ago committed by GitHub
commit d03311b45a

@ -142,7 +142,7 @@ func TestCreateStarterCmd(t *testing.T) {
t.Errorf("Wrong API version: %q", c.Metadata.ApiVersion) t.Errorf("Wrong API version: %q", c.Metadata.ApiVersion)
} }
if l := len(c.Templates); l != 5 { if l := len(c.Templates); l != 6 {
t.Errorf("Expected 5 templates, got %d", l) t.Errorf("Expected 5 templates, got %d", l)
} }

@ -36,6 +36,8 @@ const (
ChartsDir = "charts" ChartsDir = "charts"
// IgnorefileName is the name of the Helm ignore file. // IgnorefileName is the name of the Helm ignore file.
IgnorefileName = ".helmignore" IgnorefileName = ".helmignore"
// IngressFileName is the name of the example ingress file.
IngressFileName = "ingress.yaml"
// DeploymentName is the name of the example deployment file. // DeploymentName is the name of the example deployment file.
DeploymentName = "deployment.yaml" DeploymentName = "deployment.yaml"
// ServiceName is the name of the example service file. // ServiceName is the name of the example service file.
@ -59,6 +61,19 @@ service:
type: ClusterIP type: ClusterIP
externalPort: 80 externalPort: 80
internalPort: 80 internalPort: 80
ingress:
enabled: false
# Used to create Ingress record (should used with service.type: ClusterIP).
hosts:
- chart-example.local
annotations:
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
tls:
# Secrets must be manually created in the namespace.
# - secretName: chart-example-tls
# hosts:
# - chart-example.local
resources: resources:
limits: limits:
cpu: 100m cpu: 100m
@ -92,6 +107,40 @@ const defaultIgnore = `# Patterns to ignore when building packages.
*.tmproj *.tmproj
` `
const defaultIngress = `{{- if .Values.ingress.enabled -}}
{{- $serviceName := include "fullname" . -}}
{{- $servicePort := .Values.service.externalPort -}}
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: {{ template "fullname" . }}
labels:
app: {{ template "fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
annotations:
{{- range $key, $value := .Values.ingress.annotations }}
{{ $key }}: {{ $value | quote }}
{{- end }}
spec:
rules:
{{- range $host := .Values.ingress.hosts }}
- host: {{ $host }}
http:
paths:
- path: /
backend:
serviceName: {{ $serviceName }}
servicePort: {{ $servicePort }}
{{- end -}}
{{- if .Values.ingress.tls }}
tls:
{{ toYaml .Values.ingress.tls | indent 4 }}
{{- end -}}
{{- end -}}
`
const defaultDeployment = `apiVersion: extensions/v1beta1 const defaultDeployment = `apiVersion: extensions/v1beta1
kind: Deployment kind: Deployment
metadata: metadata:
@ -141,7 +190,9 @@ spec:
` `
const defaultNotes = `1. Get the application URL by running these commands: const defaultNotes = `1. Get the application URL by running these commands:
{{- if contains "NodePort" .Values.service.type }} {{- if .Values.ingress.hostname }}
http://{{- .Values.ingress.hostname }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "fullname" . }}) export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT/login echo http://$NODE_IP:$NODE_PORT/login
@ -247,6 +298,11 @@ func Create(chartfile *chart.Metadata, dir string) (string, error) {
path: filepath.Join(cdir, IgnorefileName), path: filepath.Join(cdir, IgnorefileName),
content: []byte(defaultIgnore), content: []byte(defaultIgnore),
}, },
{
// ingress.yaml
path: filepath.Join(cdir, TemplatesDir, IngressFileName),
content: []byte(defaultIngress),
},
{ {
// deployment.yaml // deployment.yaml
path: filepath.Join(cdir, TemplatesDir, DeploymentName), path: filepath.Join(cdir, TemplatesDir, DeploymentName),

Loading…
Cancel
Save