From 0107af60bfb78d4489018e957ba1e9ea5022ebed Mon Sep 17 00:00:00 2001 From: David Sullivan Date: Wed, 20 Feb 2019 11:40:26 -0500 Subject: [PATCH] Purge deleted items from heat database Long running operations (for example autoscale stacks) can lead to heat database growth over time. This will remove entries that have been soft deleted from the heat database. This adds a cron job that will call heat-manage purge_deleted every 24h. Change-Id: I3b7c174cc7ed147a8f5700135d3da2e63696008d Story: 2005020 Task: 29499 --- .../bin/_heat-purge-deleted-active.sh.tpl | 21 +++++ heat/templates/configmap-bin.yaml | 2 + heat/templates/cron-job-purge-deleted.yaml | 88 +++++++++++++++++++ heat/values.yaml | 35 ++++++++ 4 files changed, 146 insertions(+) create mode 100644 heat/templates/bin/_heat-purge-deleted-active.sh.tpl create mode 100644 heat/templates/cron-job-purge-deleted.yaml diff --git a/heat/templates/bin/_heat-purge-deleted-active.sh.tpl b/heat/templates/bin/_heat-purge-deleted-active.sh.tpl new file mode 100644 index 0000000000..9e3ec1f85e --- /dev/null +++ b/heat/templates/bin/_heat-purge-deleted-active.sh.tpl @@ -0,0 +1,21 @@ +#!/bin/bash + +{{/* +Copyright 2019 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. +*/}} + +set -ex + +heat-manage purge_deleted -g minutes $1 diff --git a/heat/templates/configmap-bin.yaml b/heat/templates/configmap-bin.yaml index b432097b97..1463be528e 100644 --- a/heat/templates/configmap-bin.yaml +++ b/heat/templates/configmap-bin.yaml @@ -59,6 +59,8 @@ data: {{ tuple "bin/_heat-engine.sh.tpl" . | include "helm-toolkit.utils.template" | indent 4 }} heat-engine-cleaner.sh: | {{ tuple "bin/_heat-engine-cleaner.sh.tpl" . | include "helm-toolkit.utils.template" | indent 4 }} + heat-purge-deleted-active.sh: | +{{ tuple "bin/_heat-purge-deleted-active.sh.tpl" . | include "helm-toolkit.utils.template" | indent 4 }} rabbit-init.sh: | {{- include "helm-toolkit.scripts.rabbit_init" . | indent 4 }} {{- end }} diff --git a/heat/templates/cron-job-purge-deleted.yaml b/heat/templates/cron-job-purge-deleted.yaml new file mode 100644 index 0000000000..7539f1e9b4 --- /dev/null +++ b/heat/templates/cron-job-purge-deleted.yaml @@ -0,0 +1,88 @@ +{{/* +Copyright 2019 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.cron_job_purge_deleted }} +{{- $envAll := . }} + +{{- $mounts_heat_purge_deleted := .Values.pod.mounts.heat_purge_deleted.heat_purge_deleted }} +{{- $mounts_heat_purge_deleted_init := .Values.pod.mounts.heat_purge_deleted.init_container }} + +{{- $serviceAccountName := "heat-purge-deleted" }} +{{ tuple $envAll "purge_deleted" $serviceAccountName | include "helm-toolkit.snippets.kubernetes_pod_rbac_serviceaccount" }} +--- +apiVersion: batch/v1beta1 +kind: CronJob +metadata: + name: heat-purge-deleted + annotations: + {{ tuple $envAll | include "helm-toolkit.snippets.release_uuid" }} +spec: + schedule: {{ .Values.jobs.purge_deleted.cron | quote }} + successfulJobsHistoryLimit: {{ .Values.jobs.purge_deleted.history.success }} + failedJobsHistoryLimit: {{ .Values.jobs.purge_deleted.history.failed }} + concurrencyPolicy: Forbid + jobTemplate: + metadata: + labels: +{{ tuple $envAll "heat" "purge-deleted" | include "helm-toolkit.snippets.kubernetes_metadata_labels" | indent 8 }} + spec: + template: + metadata: + labels: +{{ tuple $envAll "heat" "purge-deleted" | include "helm-toolkit.snippets.kubernetes_metadata_labels" | indent 12 }} + spec: + serviceAccountName: {{ $serviceAccountName }} + restartPolicy: OnFailure + nodeSelector: + {{ .Values.labels.job.node_selector_key }}: {{ .Values.labels.job.node_selector_value }} + initContainers: +{{ tuple $envAll "purge_deleted" $mounts_heat_purge_deleted_init | include "helm-toolkit.snippets.kubernetes_entrypoint_init_container" | indent 12 }} + containers: + - name: heat-purge-deleted +{{ tuple $envAll "heat_purge_deleted" | include "helm-toolkit.snippets.image" | indent 14 }} +{{ tuple $envAll $envAll.Values.pod.resources.jobs.purge_deleted | include "helm-toolkit.snippets.kubernetes_resources" | indent 14 }} + command: + - /tmp/heat-purge-deleted-active.sh + - {{ quote .Values.jobs.purge_deleted.purge_age }} + volumeMounts: + - name: heat-bin + mountPath: /tmp/heat-purge-deleted-active.sh + subPath: heat-purge-deleted-active.sh + readOnly: true + - name: etcheat + mountPath: /etc/heat + - name: heat-etc + mountPath: /etc/heat/heat.conf + subPath: heat.conf + readOnly: true + - name: heat-etc + mountPath: {{ .Values.conf.heat.DEFAULT.log_config_append }} + subPath: {{ base .Values.conf.heat.DEFAULT.log_config_append }} + readOnly: true +{{ if $mounts_heat_purge_deleted.volumeMounts }}{{ toYaml $mounts_heat_purge_deleted.volumeMounts | indent 14 }}{{ end }} + volumes: + - name: etcheat + emptyDir: {} + - name: heat-etc + secret: + secretName: heat-etc + defaultMode: 0444 + - name: heat-bin + configMap: + name: heat-bin + defaultMode: 0555 +{{ if $mounts_heat_purge_deleted.volumes }}{{ toYaml $mounts_heat_purge_deleted.volumes | indent 10 }}{{ end }} +{{- end }} diff --git a/heat/values.yaml b/heat/values.yaml index 021aa46651..f005f63d7d 100644 --- a/heat/values.yaml +++ b/heat/values.yaml @@ -55,6 +55,7 @@ images: heat_cloudwatch: docker.io/openstackhelm/heat:ocata heat_engine: docker.io/openstackhelm/heat:ocata heat_engine_cleaner: docker.io/openstackhelm/heat:ocata + heat_purge_deleted: docker.io/openstackhelm/heat:ocata dep_check: quay.io/stackanetes/kubernetes-entrypoint:v0.3.1 image_repo_sync: docker.io/docker:17.07.0 pull_policy: "IfNotPresent" @@ -72,6 +73,13 @@ jobs: success: 3 failed: 1 + purge_deleted: + cron: "20 */24 * * *" + purge_age: 60 + history: + success: 3 + failed: 1 + conf: rally_tests: run_tempest: false @@ -681,6 +689,20 @@ dependencies: service: oslo_messaging - endpoint: internal service: identity + purge_deleted: + jobs: + - heat-db-sync + - heat-ks-user + - heat-trustee-ks-user + - heat-domain-ks-user + - heat-ks-endpoints + services: + - endpoint: internal + service: oslo_db + - endpoint: internal + service: oslo_messaging + - endpoint: internal + service: identity ks_endpoints: jobs: - heat-ks-service @@ -1013,6 +1035,11 @@ pod: heat_engine_cleaner: volumeMounts: volumes: + heat_purge_deleted: + init_container: null + heat_purge_deleted: + volumeMounts: + volumes: heat_tests: init_container: null heat_tests: @@ -1155,6 +1182,13 @@ pod: limits: memory: "1024Mi" cpu: "2000m" + purge_deleted: + requests: + memory: "124Mi" + cpu: "100m" + limits: + memory: "1024Mi" + cpu: "2000m" image_repo_sync: requests: memory: "128Mi" @@ -1204,6 +1238,7 @@ manifests: configmap_bin: true configmap_etc: true cron_job_engine_cleaner: true + cron_job_purge_deleted: true deployment_api: true deployment_cfn: true deployment_cloudwatch: false