Add hpa and env to helm create

Signed-off-by: Naseem Ullah <naseemkullah@gmail.com>
pull/5110/head
Naseem Ullah 7 years ago
parent c82c0b6046
commit dfa227bfd9

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

@ -40,6 +40,8 @@ const (
IngressFileName = "ingress.yaml" 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"
// HorizontalPodAutoscalerName is the name of the example hpa file.
HorizontalPodAutoscalerName = "hpa.yaml"
// ServiceName is the name of the example service file. // ServiceName is the name of the example service file.
ServiceName = "service.yaml" ServiceName = "service.yaml"
// NotesName is the name of the example NOTES.txt file. // NotesName is the name of the example NOTES.txt file.
@ -56,32 +58,23 @@ const defaultValues = `# Default values for %s.
# This is a YAML-formatted file. # This is a YAML-formatted file.
# Declare variables to be passed into your templates. # Declare variables to be passed into your templates.
replicaCount: 1 nameOverride: ""
fullnameOverride: ""
deployment:
image: image:
repository: nginx repository: nginx
tag: stable tag: stable
pullPolicy: IfNotPresent pullPolicy: IfNotPresent
nameOverride: "" replicaCount: 1
fullnameOverride: ""
service:
type: ClusterIP
port: 80
ingress: hpa:
enabled: false enabled: false
annotations: {} minReplicas: 1
# kubernetes.io/ingress.class: nginx maxReplicas: 10
# kubernetes.io/tls-acme: "true" targetCPUUtilizationPercentage: 80
paths: [] targetMemoryUtilizationPercentage: 80
hosts:
- chart-example.local
tls: []
# - secretName: chart-example-tls
# hosts:
# - chart-example.local
resources: {} resources: {}
# We usually recommend not to specify default resources and to leave this as a conscious # We usually recommend not to specify default resources and to leave this as a conscious
@ -95,11 +88,34 @@ resources: {}
# cpu: 100m # cpu: 100m
# memory: 128Mi # memory: 128Mi
env: {}
# - name: FOO
# value: bar
# - name: BAZ
# value: qux
nodeSelector: {} nodeSelector: {}
tolerations: [] tolerations: []
affinity: {} affinity: {}
service:
type: ClusterIP
port: 80
ingress:
enabled: false
annotations: {}
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
paths: []
hosts:
- chart-example.local
tls: []
# - secretName: chart-example-tls
# hosts:
# - chart-example.local
` `
const defaultIgnore = `# Patterns to ignore when building packages. const defaultIgnore = `# Patterns to ignore when building packages.
@ -178,7 +194,7 @@ metadata:
app.kubernetes.io/instance: {{ .Release.Name }} app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }} app.kubernetes.io/managed-by: {{ .Release.Service }}
spec: spec:
replicas: {{ .Values.replicaCount }} replicas: {{ .Values.deployment.replicaCount }}
selector: selector:
matchLabels: matchLabels:
app.kubernetes.io/name: {{ include "<CHARTNAME>.name" . }} app.kubernetes.io/name: {{ include "<CHARTNAME>.name" . }}
@ -191,8 +207,8 @@ spec:
spec: spec:
containers: containers:
- name: {{ .Chart.Name }} - name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" image: "{{ .Values.deployment.image.repository }}:{{ .Values.deployment.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }} imagePullPolicy: {{ .Values.deployment.image.pullPolicy }}
ports: ports:
- name: http - name: http
containerPort: 80 containerPort: 80
@ -206,20 +222,54 @@ spec:
path: / path: /
port: http port: http
resources: resources:
{{- toYaml .Values.resources | nindent 12 }} {{- toYaml .Values.deployment.resources | nindent 12 }}
{{- with .Values.nodeSelector }} env:
{{- toYaml .Values.deployment.env | nindent 12 }}
{{- with .Values.deployment.nodeSelector }}
nodeSelector: nodeSelector:
{{- toYaml . | nindent 8 }} {{- toYaml . | nindent 8 }}
{{- end }} {{- end }}
{{- with .Values.affinity }} {{- with .Values.deployment.affinity }}
affinity: affinity:
{{- toYaml . | nindent 8 }} {{- toYaml . | nindent 8 }}
{{- end }} {{- end }}
{{- with .Values.tolerations }} {{- with .Values.deployment.tolerations }}
tolerations: tolerations:
{{- toYaml . | nindent 8 }} {{- toYaml . | nindent 8 }}
{{- end }} {{- end }}
` `
const defaultHorizontalPodAutoscaler = `{{- if .Values.deployment.hpa.enabled }}
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
labels:
app.kubernetes.io/name: {{ include "<CHARTNAME>.name" . }}
helm.sh/chart: {{ include "<CHARTNAME>.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
name: {{ template "<CHARTNAME>.fullname" . }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ template "<CHARTNAME>.fullname" . }}
minReplicas: {{ .Values.hpa.minReplicas }}
maxReplicas: {{ .Values.hpa.maxReplicas }}
metrics:
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
targetAverageUtilization: {{ .Values.hpa.targetCPUUtilizationPercentage }}
{{- end }}
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
targetAverageUtilization: {{ .Values.hpa.targetMemoryUtilizationPercentage }}
{{- end }}
{{- end }}
`
const defaultService = `apiVersion: v1 const defaultService = `apiVersion: v1
kind: Service kind: Service
@ -413,6 +463,11 @@ func Create(chartfile *chart.Metadata, dir string) (string, error) {
path: filepath.Join(cdir, TemplatesDir, DeploymentName), path: filepath.Join(cdir, TemplatesDir, DeploymentName),
content: Transform(defaultDeployment, "<CHARTNAME>", chartfile.Name), content: Transform(defaultDeployment, "<CHARTNAME>", chartfile.Name),
}, },
{
// hpa.yaml
path: filepath.Join(cdir, TemplatesDir, HorizontalPodAutoscalerName),
content: Transform(defaultHorizontalPodAutoscaler, "<CHARTNAME>", chartfile.Name),
},
{ {
// service.yaml // service.yaml
path: filepath.Join(cdir, TemplatesDir, ServiceName), path: filepath.Join(cdir, TemplatesDir, ServiceName),

Loading…
Cancel
Save