openstack-helm-infra/prometheus-alertmanager/templates/statefulset.yaml
Tin Lam 628fd3007d RBAC: Consolidate serviceaccounts and restrict rbac
Currently, services have two serviceaccounts: one specified in the
chart that cannot read anything, and one injected via helm-toolkit
that can read everything. This patch set refactors the logic to:

- cleanup the roles and their binding automatically when the helm
  chart is deleted;
- remove the need to separately mount a serviceaccount  with secret;
- better handling of namespaces resource restriction.

Co-Authored-By: portdirect <pete@port.direct>

Change-Id: I47d41e0cad9b5b002f59fc9652bad2cc025538dc
2017-12-19 20:22:57 -05:00

119 lines
4.8 KiB
YAML

{{/*
Copyright 2017 The Openstack-Helm 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.manifests.statefulset }}
{{- $envAll := . }}
{{- if .Values.images.local_registry.active -}}
{{- $_ := set .Values "pod_dependency" (merge .Values.dependencies.alertmanager .Values.conditional_dependencies.local_image_registry) -}}
{{- else -}}
{{- $_ := set .Values "pod_dependency" .Values.dependencies.alertmanager -}}
{{- end -}}
{{- $mounts_alertmanager := .Values.pod.mounts.alertmanager.alertmanager }}
{{- $mounts_alertmanager_init := .Values.pod.mounts.alertmanager.init_container }}
{{- $serviceAccountName := "alertmanager"}}
{{ tuple $envAll $envAll.Values.pod_dependency $serviceAccountName | include "helm-toolkit.snippets.kubernetes_pod_rbac_serviceaccount" }}
---
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
name: alertmanager
spec:
serviceName: {{ tuple "alerts" "discovery" . | include "helm-toolkit.endpoints.hostname_short_endpoint_lookup" }}
replicas: {{ .Values.pod.replicas.alertmanager }}
template:
metadata:
labels:
{{ tuple $envAll "alertmanager" "server" | include "helm-toolkit.snippets.kubernetes_metadata_labels" | indent 8 }}
annotations:
configmap-bin-hash: {{ tuple "configmap-bin.yaml" . | include "helm-toolkit.utils.hash" }}
configmap-etc-hash: {{ tuple "configmap-etc.yaml" . | include "helm-toolkit.utils.hash" }}
spec:
serviceAccount: alertmanager
affinity:
{{ tuple $envAll "alertmanager" "server" | include "helm-toolkit.snippets.kubernetes_pod_anti_affinity" | indent 8 }}
nodeSelector:
{{ .Values.labels.node_selector_key }}: {{ .Values.labels.node_selector_value }}
terminationGracePeriodSeconds: {{ .Values.pod.lifecycle.termination_grace_period.alertmanager.timeout | default "30" }}
initContainers:
{{ tuple $envAll .Values.pod_dependency list | include "helm-toolkit.snippets.kubernetes_entrypoint_init_container" | indent 8 }}
containers:
- name: alertmanager
{{ tuple $envAll "alertmanager" | include "helm-toolkit.snippets.image" | indent 10 }}
command:
- /tmp/alertmanager.sh
- start
lifecycle:
preStop:
exec:
command:
- /tmp/alertmanager.sh
- stop
{{ tuple $envAll $envAll.Values.pod.resources.alertmanager | include "helm-toolkit.snippets.kubernetes_resources" | indent 10 }}
env:
- name: DISCOVERY_SVC
value: {{ tuple "alerts" "discovery" . | include "helm-toolkit.endpoints.hostname_short_endpoint_lookup" }}
ports:
- name: alerts-api
containerPort: {{ .Values.network.alertmanager.port }}
- name: peer-mesh
containerPort: {{ .Values.network.alertmanager.mesh_port }}
readinessProbe:
httpGet:
path: /#/status
port: {{ .Values.network.alertmanager.port }}
initialDelaySeconds: 30
timeoutSeconds: 30
volumeMounts:
- name: etc-alertmanager
mountPath: /etc/config
- name: alertmanager-etc
mountPath: /etc/alertmanager/template/alert-templates.tmpl
subPath: alert-templates.tmpl
readOnly: true
- name: alertmanager-etc
mountPath: /etc/config/alertmanager.yml
subPath: alertmanager.yml
readOnly: true
- name: alertmanager-bin
mountPath: /tmp/alertmanager.sh
subPath: alertmanager.sh
readOnly: true
- name: storage
mountPath: /var/lib/alertmanager/data
{{ if $mounts_alertmanager.volumeMounts }}{{ toYaml $mounts_alertmanager.volumeMounts | indent 12 }}{{ end }}
volumes:
- name: etc-alertmanager
emptyDir: {}
- name: alertmanager-etc
configMap:
name: alertmanager-etc
- name: alertmanager-bin
configMap:
name: alertmanager-bin
defaultMode: 0555
{{- if .Values.storage.enabled }}
- name: storage
persistentVolumeClaim:
claimName: {{ .Values.storage.pvc.name }}
{{- else }}
- name: storage
emptyDir: {}
{{- end }}
{{ if $mounts_alertmanager.volumes }}{{ toYaml $mounts_alertmanager.volumes | indent 8 }}{{ end }}
{{- end }}