From 4a70cab3a10cc788ab2eff908cf0028d2a01f891 Mon Sep 17 00:00:00 2001 From: Deirdre Storck Date: Tue, 17 Apr 2018 01:59:58 -0700 Subject: [PATCH] apiVersion shouldn't be hardcoded (#5060) * apiVersion shouldn't be hardcoded * updated chart version * fixed semver comparison --- incubator/elasticsearch-curator/Chart.yaml | 2 +- incubator/elasticsearch-curator/README.md | 3 +++ .../elasticsearch-curator/templates/_helpers.tpl | 11 +++++++++++ .../elasticsearch-curator/templates/cronjob.yaml | 4 ++-- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/incubator/elasticsearch-curator/Chart.yaml b/incubator/elasticsearch-curator/Chart.yaml index 09d2015639..372e90d1ae 100644 --- a/incubator/elasticsearch-curator/Chart.yaml +++ b/incubator/elasticsearch-curator/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v1 appVersion: "5.4.1" description: A Helm chart for Elasticseach Curator name: elasticsearch-curator -version: 0.1.0 +version: 0.1.1 home: https://github.com/elastic/curator keywords: - curator diff --git a/incubator/elasticsearch-curator/README.md b/incubator/elasticsearch-curator/README.md index b3c52b9ec9..c20f180b42 100644 --- a/incubator/elasticsearch-curator/README.md +++ b/incubator/elasticsearch-curator/README.md @@ -6,6 +6,9 @@ This directory contains a Kubernetes chart to deploy the [Elasticsearch Curator] * Elasticsearch +* The `elasticsearch-curator` cron job requires [K8s CronJob](https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/) support: + > You need a working Kubernetes cluster at version >= 1.8 (for CronJob). For previous versions of cluster (< 1.8) you need to explicitly enable `batch/v2alpha1` API by passing `--runtime-config=batch/v2alpha1=true` to the API server ([see Turn on or off an API version for your cluster for more](https://kubernetes.io/docs/admin/cluster-management/#turn-on-or-off-an-api-version-for-your-cluster)). + ## Chart Details This chart will do the following: diff --git a/incubator/elasticsearch-curator/templates/_helpers.tpl b/incubator/elasticsearch-curator/templates/_helpers.tpl index 6fa7ce0358..c786fb5fa8 100644 --- a/incubator/elasticsearch-curator/templates/_helpers.tpl +++ b/incubator/elasticsearch-curator/templates/_helpers.tpl @@ -1,5 +1,16 @@ {{/* vim: set filetype=mustache: */}} +{{/* +Return the appropriate apiVersion for cronjob APIs. +*/}} +{{- define "cronjob.apiVersion" -}} +{{- if semverCompare "< 1.8-0" .Capabilities.KubeVersion.GitVersion -}} +{{- print "batch/v2alpha1" }} +{{- else if semverCompare ">=1.8-0" .Capabilities.KubeVersion.GitVersion -}} +{{- print "batch/v1beta1" }} +{{- end -}} +{{- end -}} + {{/* Expand the name of the chart. */}} diff --git a/incubator/elasticsearch-curator/templates/cronjob.yaml b/incubator/elasticsearch-curator/templates/cronjob.yaml index 733a462f69..8e5ce6344a 100644 --- a/incubator/elasticsearch-curator/templates/cronjob.yaml +++ b/incubator/elasticsearch-curator/templates/cronjob.yaml @@ -1,4 +1,4 @@ -apiVersion: batch/v1beta1 +apiVersion: {{ template "cronjob.apiVersion" . }} kind: CronJob metadata: name: {{ template "elasticsearch-curator.fullname" . }} @@ -19,7 +19,7 @@ spec: spec: volumes: - name: config-volume - configMap: + configMap: name: curator-config restartPolicy: Never containers: