Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[helm] fix PDB templating and add support for HPA, pod affinity etc #8581

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion charts/helm-chart/kubernetes-dashboard/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

apiVersion: v2
name: kubernetes-dashboard
version: 7.0.0-alpha1
version: 7.0.0-alpha2
appVersion: "v3.0.0-alpha0"
description: General-purpose web UI for Kubernetes clusters
keywords:
Expand Down
13 changes: 13 additions & 0 deletions charts/helm-chart/kubernetes-dashboard/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,16 @@ Common label selectors
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/part-of: {{ include "kubernetes-dashboard.name" . }}
{{- end -}}

{{/*
Define apiVersion of HorizontalPodAutoscaler
*/}}
{{- define "kubernetes-dashboard.hpa.apiVersion" -}}
{{- if .Capabilities.APIVersions.Has "autoscaling/v2" -}}
{{- print "autoscaling/v2" -}}
{{- else if .Capabilities.APIVersions.Has "autoscaling/v2beta2" -}}
{{- print "autoscaling/v2beta2" -}}
{{- else -}}
{{- print "autoscaling/v2beta1" -}}
{{- end -}}
{{- end -}}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ metadata:
app.kubernetes.io/component: {{ .Values.api.role }}
name: {{ template "kubernetes-dashboard.fullname" . }}-{{ .Values.api.role }}
spec:
replicas: {{ .Values.app.scaling.replicas }}
replicas: {{ .Values.api.replicas }}
revisionHistoryLimit: {{ .Values.app.scaling.revisionHistoryLimit }}
selector:
matchLabels:
Expand Down Expand Up @@ -91,13 +91,19 @@ spec:
nodeSelector:
{{ toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.app.scheduling.nodeSelector }}
{{ toYaml . | nindent 8 }}
{{- end }}

{{- with .Values.app.tolerations }}
{{- with .Values.api.tolerations }}
tolerations:
{{ toYaml . | nindent 8 }}
{{- end }}


{{- with .Values.api.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ template "kubernetes-dashboard.fullname" . }}

{{- with .Values.api.topologySpreadConstraints }}
topologySpreadConstraints:
{{ toYaml . | nindent 8 }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,20 @@ spec:
nodeSelector:
{{ toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.app.scheduling.nodeSelector }}
{{ toYaml . | nindent 8 }}
{{- end }}

{{- with .Values.app.tolerations }}
{{- with .Values.metricsScraper.tolerations }}
tolerations:
{{ toYaml . | nindent 8 }}
{{- end }}


{{- with .Values.metricsScraper.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ template "kubernetes-dashboard.fullname" . }}

{{- with .Values.metricsScraper.topologySpreadConstraints }}
topologySpreadConstraints:
{{ toYaml . | nindent 8 }}
{{- end }}
{{ end }}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ metadata:
app.kubernetes.io/component: {{ .Values.web.role }}
name: {{ template "kubernetes-dashboard.fullname" . }}-{{ .Values.web.role }}
spec:
replicas: {{ .Values.app.scaling.replicas }}
replicas: {{ .Values.web.replicas }}
revisionHistoryLimit: {{ .Values.app.scaling.revisionHistoryLimit }}
selector:
matchLabels:
Expand Down Expand Up @@ -89,13 +89,19 @@ spec:
nodeSelector:
{{ toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.app.scheduling.nodeSelector }}
{{ toYaml . | nindent 8 }}
{{- end }}

{{- with .Values.app.tolerations }}
{{- with .Values.web.tolerations }}
tolerations:
{{ toYaml . | nindent 8 }}
{{- end }}

{{- with .Values.web.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ template "kubernetes-dashboard.fullname" . }}

{{- with .Values.web.topologySpreadConstraints }}
topologySpreadConstraints:
{{ toYaml . | nindent 8 }}
{{- end }}
67 changes: 67 additions & 0 deletions charts/helm-chart/kubernetes-dashboard/templates/hpa/api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Copyright 2017 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

{{- if .Values.api.autoscaling.enabled }}
apiVersion: {{ include "kubernetes-dashboard.hpa.apiVersion" . }}
kind: HorizontalPodAutoscaler
metadata:
labels:
{{- include "kubernetes-dashboard.labels" . | nindent 4 }}
{{- with .Values.api.labels }}
{{ toYaml . | nindent 4 }}
{{- end }}
app.kubernetes.io/name: {{ template "kubernetes-dashboard.name" . }}-{{ .Values.api.role }}
app.kubernetes.io/version: {{ .Values.api.image.tag }}
app.kubernetes.io/component: {{ .Values.api.role }}
name: {{ template "kubernetes-dashboard.fullname" . }}-{{ .Values.api.role }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ template "kubernetes-dashboard.fullname" . }}-{{ .Values.api.role }}
minReplicas: {{ .Values.api.autoscaling.minReplicas }}
maxReplicas: {{ .Values.api.autoscaling.maxReplicas }}
metrics:
{{- if eq (include "kubernetes-dashboard.hpa.apiVersion" .) "autoscaling/v2" -}}
{{- if .Values.api.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: {{ .Values.api.autoscaling.targetCPUUtilizationPercentage }}
{{- end }}
{{- if .Values.api.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: {{ .Values.api.autoscaling.targetMemoryUtilizationPercentage }}
{{- end }}
{{- else -}}
{{- if .Values.api.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
targetAverageUtilization: {{ .Values.api.autoscaling.targetCPUUtilizationPercentage }}
{{- end }}
{{- if .Values.api.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
targetAverageUtilization: {{ .Values.api.autoscaling.targetMemoryUtilizationPercentage }}
{{- end -}}
{{- end }}
{{- end }}
67 changes: 67 additions & 0 deletions charts/helm-chart/kubernetes-dashboard/templates/hpa/web.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Copyright 2017 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

{{- if .Values.web.autoscaling.enabled }}
apiVersion: {{ include "kubernetes-dashboard.hpa.apiVersion" . }}
kind: HorizontalPodAutoscaler
metadata:
labels:
{{- include "kubernetes-dashboard.labels" . | nindent 4 }}
{{- with .Values.web.labels }}
{{ toYaml . | nindent 4 }}
{{- end }}
app.kubernetes.io/name: {{ template "kubernetes-dashboard.name" . }}-{{ .Values.web.role }}
app.kubernetes.io/version: {{ .Values.web.image.tag }}
app.kubernetes.io/component: {{ .Values.web.role }}
name: {{ template "kubernetes-dashboard.fullname" . }}-{{ .Values.web.role }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ template "kubernetes-dashboard.fullname" . }}-{{ .Values.web.role }}
minReplicas: {{ .Values.web.autoscaling.minReplicas }}
maxReplicas: {{ .Values.web.autoscaling.maxReplicas }}
metrics:
{{- if eq (include "kubernetes-dashboard.hpa.apiVersion" .) "autoscaling/v2" -}}
{{- if .Values.web.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: {{ .Values.web.autoscaling.targetCPUUtilizationPercentage }}
{{- end }}
{{- if .Values.web.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: {{ .Values.web.autoscaling.targetMemoryUtilizationPercentage }}
{{- end }}
{{- else -}}
{{- if .Values.web.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
targetAverageUtilization: {{ .Values.web.autoscaling.targetCPUUtilizationPercentage }}
{{- end }}
{{- if .Values.web.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
targetAverageUtilization: {{ .Values.web.autoscaling.targetMemoryUtilizationPercentage }}
{{- end -}}
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

{{- if .Values.app.security.podDisruptionBudget.enabled -}}
{{- if .Values.api.podDisruptionBudget }}
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
Expand All @@ -25,17 +25,16 @@ metadata:
{{- if .Values.app.annotations }}
{{- include "common.tplvalues.render" ( dict "value" .Values.app.annotations "context" $ ) | nindent 4 }}
{{- end }}
name: {{ template "kubernetes-dashboard.fullname" . }}
name: {{ template "kubernetes-dashboard.fullname" . }}-{{ .Values.api.role }}
spec:
selector:
matchLabels:
{{ include "kubernetes-dashboard.matchLabels" . | nindent 6 }}

{{- if .Values.app.security.podDisruptionBudget.minAvailable }}
minAvailable: {{ .Values.app.security.podDisruptionBudget.minAvailable }}
{{- end }}

{{- if .Values.app.security.podDisruptionBudget.maxUnavailable }}
maxUnavailable: {{ .Values.app.security.podDisruptionBudget.maxUnavailable }}
{{- end }}
{{ include "kubernetes-dashboard.matchLabels" . | nindent 6 }}
{{- with .Values.api.labels }}
{{ toYaml . | nindent 6 }}
{{- end }}
app.kubernetes.io/name: {{ template "kubernetes-dashboard.name" . }}-{{ .Values.api.role }}
app.kubernetes.io/version: {{ .Values.api.image.tag }}
app.kubernetes.io/component: {{ .Values.api.role }}
{{- toYaml .Values.api.podDisruptionBudget | nindent 2 }}
{{- end -}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright 2017 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

{{- if .Values.web.podDisruptionBudget }}
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
labels:
{{- include "kubernetes-dashboard.labels" . | nindent 4 }}
{{- if .Values.app.labels }}
{{- include "common.tplvalues.render" ( dict "value" .Values.app.labels "context" $ ) | nindent 4 }}
{{- end }}
annotations:
{{- if .Values.app.annotations }}
{{- include "common.tplvalues.render" ( dict "value" .Values.app.annotations "context" $ ) | nindent 4 }}
{{- end }}
name: {{ template "kubernetes-dashboard.fullname" . }}-{{ .Values.web.role }}
spec:
selector:
matchLabels:
{{ include "kubernetes-dashboard.matchLabels" . | nindent 6 }}
{{- with .Values.web.labels }}
{{ toYaml . | nindent 6 }}
{{- end }}
app.kubernetes.io/name: {{ template "kubernetes-dashboard.name" . }}-{{ .Values.web.role }}
app.kubernetes.io/version: {{ .Values.web.image.tag }}
app.kubernetes.io/component: {{ .Values.web.role }}
{{- toYaml .Values.web.podDisruptionBudget | nindent 2 }}
{{- end -}}
Loading